-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HW3 #420
Open
TuanTrain
wants to merge
5
commits into
harvard-cs205:HW3
Choose a base branch
from
TuanTrain:HW3
base: HW3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HW3 #420
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Using VM on Windows set up for CS205: | ||
|
||
best: | ||
configuration ('blocked', 16, 4): 0.004673046 seconds | ||
|
||
|
||
The platforms detected are: | ||
--------------------------- | ||
AMD Accelerated Parallel Processing Advanced Micro Devices, Inc. version: OpenCL 2.0 AMD-APP (1800.8) | ||
The devices detected on platform AMD Accelerated Parallel Processing are: | ||
--------------------------- | ||
Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz [Type: CPU ] | ||
Maximum clock Frequency: 2195 MHz | ||
Maximum allocable memory size: 1049 MB | ||
Maximum work group size 1024 | ||
--------------------------- | ||
This context is associated with 1 devices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Part 1: | ||
|
||
Maze 1: | ||
Finished after 879 iterations, 261.9836 ms total, 0.298047326507 ms per iteration | ||
Found 2 regions | ||
|
||
Maze 2: | ||
Finished after 514 iterations, 152.45928 ms total, 0.296613385214 ms per iteration | ||
Found 35 regions | ||
|
||
|
||
Part 2: | ||
|
||
Maze 1: | ||
Finished after 529 iterations, 157.65824 ms total, 0.298030699433 ms per iteration | ||
Found 2 regions | ||
|
||
Maze 2: | ||
Finished after 273 iterations, 81.33136 ms total, 0.297917069597 ms per iteration | ||
Found 35 regions | ||
|
||
|
||
Part 3: | ||
|
||
Maze 1: | ||
Finished after 10 iterations, 3.07216 ms total, 0.307216 ms per iteration | ||
Found 2 regions | ||
|
||
Maze 2: | ||
Finished after 10 iterations, 3.03024 ms total, 0.303024 ms per iteration | ||
Found 35 regions | ||
|
||
Part 4: | ||
|
||
Maze 1: | ||
Finished after 11 iterations, 8.83696 ms total, 0.80336 ms per iteration | ||
Found 2 regions | ||
|
||
Maze 2: | ||
Finished after 10 iterations, 8.00088 ms total, 0.800088 ms per iteration | ||
Found 35 regions | ||
|
||
For part 4, the optimization of reducing global memory reads by using a single thread to do that action only once per group actually slowed down the speed of the program. This is because that action was serialized over the whole group so the read and update could only be done one at a time rather than with the faster GPU memory access. The global memory access is not the limiting factor. This implementation would work if the memory access was much slower, perhaps if it was using the GPU of an old command line computer. | ||
|
||
|
||
Part 5: | ||
If we replace atomic_min() with min(), the memory updates are no longer serial but we lose the guarantee that the update occurs on a given iteration. So there are the two factors of increased speed yet lost accuracy, and it is hard to tell which one would win out. The increased speed due to parallelization is great when the threads are working on updating different labels. On the other hand, it is more difficult to understand the behavior when the min updates are no longer atomic. What may happen is that one update could be decreasing a label to 5, but another is decreasing it to 2. Depending on when the write occurs, either one can occur, so if the label should be 2, it can still be stalling at 5 until the write of 2 occurs. So I do not think an increase in label can ever occur from one iteration to another, but a decrease could be postponed or not done in time. Eventually, however, we should be able to see that the min values converge to the state they were meant to go to, it is just that the time to get there would not be consistent from one run to the next. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,20 +80,75 @@ propagate_labels(__global __read_write int *labels, | |
old_label = buffer[buf_y * buf_w + buf_x]; | ||
|
||
// CODE FOR PARTS 2 and 4 HERE (part 4 will replace part 2) | ||
// Part 2: | ||
//if (old_label < w * h) | ||
//{ | ||
// buffer[buf_y * buf_w + buf_x] = labels[old_label]; | ||
//} | ||
|
||
// Part 4: | ||
// once per local group | ||
if (lx == 0 && ly == 0) | ||
{ | ||
int cur_label; | ||
int prev_label = -25; | ||
int prev_grand_label; | ||
int pixels = buf_w * buf_h; | ||
int i; | ||
// iterate over pixels | ||
for(i = 0; i < pixels; i++) | ||
{ | ||
cur_label = buffer[i]; | ||
|
||
// within pic | ||
if (cur_label < w * h) | ||
{ | ||
// if labels on same value, use the already found grand label | ||
if (cur_label == prev_label) | ||
{ | ||
buffer[i] = prev_grand_label; | ||
} | ||
// otherwise update the grand label then use | ||
else | ||
{ | ||
prev_label = cur_label; | ||
prev_grand_label = labels[prev_label]; | ||
buffer[i] = prev_grand_label; | ||
} | ||
} | ||
} | ||
|
||
} | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
// stay in bounds | ||
new_label = old_label; | ||
if ((x < w) && (y < h)) { | ||
// CODE FOR PART 1 HERE | ||
// We set new_label to the value of old_label, but you will need | ||
// to adjust this for correctness. | ||
new_label = old_label; | ||
if (new_label < w * h) | ||
{ | ||
// min of adjacents | ||
new_label = min(new_label, | ||
min(buffer[(buf_y - 1) * buf_w + buf_x], | ||
min(buffer[(buf_y) * buf_w + buf_x - 1], | ||
min(buffer[(buf_y) * buf_w + buf_x + 1], | ||
buffer[(buf_y + 1) * buf_w + buf_x])))); | ||
} | ||
|
||
if (new_label != old_label) { | ||
// CODE FOR PART 3 HERE | ||
// indicate there was a change this iteration. | ||
// multiple threads might write this. | ||
// atomic update | ||
atomic_min(&labels[old_label], new_label); | ||
atomic_min(&labels[y * w + x], new_label); | ||
|
||
*(changed_flag) += 1; | ||
labels[y * w + x] = new_label; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line needs to be removed (you are doing the atomic_min update in 147). |
||
|
||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After parts 2 and 4, you should use buffer[buf_w * buf_y + buf_x] instead of old_label.