Repository navigation
fix omp scan bug #6560
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
Merged
Merged
fix omp scan bug #6560
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
430a2e8
fix omp scan bug
charan-003 e400373
Add more scan tests
bernhardmgruber 656f024
add scan tests and few changes
charan-003 addf851
Merge branch 'main' into fix_omp_scan_bug
charan-003 ae2c2c7
Merge branch 'main' into fix_omp_scan_bug
charan-003 f549d50
use value type for init accum_t
charan-003 68f500c
use thrust::inclusive/exclusive
charan-003 b0d8c74
Merge branch 'main' into fix_omp_scan_bug
charan-003 9ea6902
fix
charan-003 47060f2
minor changes
charan-003 b07f663
Merge branch 'main' into fix_omp_scan_bug
charan-003 660b6f2
fix
charan-003 8a56f7d
include tabulate
charan-003 9f904ea
Merge branch 'main' into fix_omp_scan_bug
charan-003 a8df5c0
minor fix
charan-003 9a7675d
use thrust::placeholders
charan-003 0b1e611
remove unnecessary check
charan-003 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -106,7 +106,25 @@ OutputIterator scan_impl( | |
|
|
||
| if (start < n) | ||
| { | ||
| block_sums[tid] = ::cuda::std::reduce(first + start, first + end, accum_t{}, wrapped_binary_op); | ||
| if constexpr (has_init) | ||
| { | ||
| if (tid == 0) | ||
| { | ||
| block_sums[tid] = ::cuda::std::reduce(first + start, first + end, init, wrapped_binary_op); | ||
| } | ||
| else | ||
| { | ||
| block_sums[tid] = ::cuda::std::reduce(first + start, first + end, accum_t{}, wrapped_binary_op); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // No init value: reduce uses first element as init | ||
| if (end > start) | ||
| { | ||
| block_sums[tid] = ::cuda::std::reduce(first + start + 1, first + end, *(first + start), wrapped_binary_op); | ||
| } | ||
| } | ||
|
charan-003 marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -117,7 +135,18 @@ OutputIterator scan_impl( | |
| } | ||
| else | ||
| { | ||
| ::cuda::std::exclusive_scan(block_sums.begin(), block_sums.end(), block_sums.begin(), accum_t{}, wrapped_binary_op); | ||
| // For no init inclusive scan, use inclusive_scan on block_sums, then shift | ||
| if (num_threads > 1) | ||
|
charan-003 marked this conversation as resolved.
Resolved
Contributor
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. You added the assertion as suggested, but forgot to remove this now unnecessary check for
Contributor
Author
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. Right, thanks for bringing this up. |
||
| { | ||
| temporary_array<accum_t, DerivedPolicy> block_sums_copy(exec, num_threads); | ||
| for (int i = 0; i < num_threads; ++i) | ||
| { | ||
| block_sums_copy[i] = block_sums[i]; | ||
| } | ||
| ::cuda::std::inclusive_scan( | ||
| block_sums_copy.begin(), block_sums_copy.begin() + num_threads - 1, block_sums.begin() + 1, wrapped_binary_op); | ||
| // block_sums[0] stays as-is (no prefix for first block) | ||
| } | ||
|
charan-003 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // Step 3: Scan each block with offset (N reads/writes) | ||
|
|
@@ -130,13 +159,30 @@ OutputIterator scan_impl( | |
|
|
||
| if (start < n) | ||
| { | ||
| const accum_t prefix = block_sums[tid]; | ||
| if constexpr (IsInclusive) | ||
| { | ||
| ::cuda::std::inclusive_scan(first + start, first + end, result + start, wrapped_binary_op, prefix); | ||
| if constexpr (has_init) | ||
| { | ||
| const accum_t prefix = block_sums[tid]; | ||
| ::cuda::std::inclusive_scan(first + start, first + end, result + start, wrapped_binary_op, prefix); | ||
| } | ||
| else | ||
| { | ||
| // For no init: thread 0 has no prefix, others use block_sums | ||
| if (tid == 0) | ||
| { | ||
| ::cuda::std::inclusive_scan(first + start, first + end, result + start, wrapped_binary_op); | ||
| } | ||
| else | ||
| { | ||
| const accum_t prefix = block_sums[tid]; | ||
| ::cuda::std::inclusive_scan(first + start, first + end, result + start, wrapped_binary_op, prefix); | ||
| } | ||
| } | ||
|
charan-003 marked this conversation as resolved.
Resolved
|
||
| } | ||
| else | ||
| { | ||
| const accum_t prefix = block_sums[tid]; | ||
| ::cuda::std::exclusive_scan(first + start, first + end, result + start, prefix, wrapped_binary_op); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.