Synchronize before indexing host-accessible arrays from the CPU - #649
Merged
Merged
Conversation
Scalar getindex and setindex! on shared and host buffers accessed the memory directly, without waiting for queued work. Reading the result of a reduction therefore returned stale data, e.g. sum() and maximum() of such arrays returned 0. Synchronize the current task's stream first.
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/test/array.jl b/test/array.jl
index eb21d26..e386d9e 100644
--- a/test/array.jl
+++ b/test/array.jl
@@ -104,11 +104,11 @@ end
end
@testset "reductions of host-accessible arrays" begin
- for B in (oneL0.SharedBuffer, oneL0.HostBuffer)
- a = oneArray{Float32, 1, B}(fill(1.0f0, 1024))
- @test sum(a) == 1024
- @test maximum(a) == 1
- end
+ for B in (oneL0.SharedBuffer, oneL0.HostBuffer)
+ a = oneArray{Float32, 1, B}(fill(1.0f0, 1024))
+ @test sum(a) == 1024
+ @test maximum(a) == 1
+ end
end
# https://github.com/JuliaGPU/CUDA.jl/issues/2191 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #649 +/- ##
==========================================
- Coverage 80.87% 78.96% -1.91%
==========================================
Files 56 56
Lines 4088 4089 +1
==========================================
- Hits 3306 3229 -77
- Misses 782 860 +78 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Arrays backed by shared or host memory can be indexed directly from the CPU, but doing so didn't wait for work still queued on the GPU. The most visible consequence is that reductions of such arrays returned garbage, because the result was read before the kernel computing it had finished:
Scalar indexing of these arrays now synchronizes first, so this returns the right results. As with other implicit synchronization, this only waits for the current task's queue: work submitted from other tasks, or to a queue you created yourself, still needs to be synchronized explicitly.
Found while working on host-memory wrapping for oneAPI.jl, but independent of it. Tested on an Iris Xe: the new test fails on
main(sumandmaximumreturn 0 for both shared and host buffers) and passes with this change.