Support array_sizes that are not divisible by the thread block size for CUDA and HIP #185
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.
Currently, CUDA and HIP do not support array sizes that are not divisible by the thread block size, Since most other programming models support these, this PR removes this limitation to improve BabelStream's fairness.
This is done using a technique that is widely used in practice, commonly known as a "grid-strided loop" (see CUDA Pro Tip: Write Flexible Kernels with Grid-Stride Loops). The number of thread blocks in the launch configuration is rounded up to cover all array elements using
ceil_div
.This PR also updates the CUDAStream implementation to modern CUDA C++ practices by simplifying error handling, and using an explicit
cudaStream_t
. The impact of these two changes on performance is negligible; they are only cosmetic changes.