-
Notifications
You must be signed in to change notification settings - Fork 49
Auto-detect SPIR-V extensions from device capabilities #410
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c73a89
Auto-detect SPIR-V extensions from device capabilities
SimonDanisch 24cbd43
add SPV_KHR_bit_instructions
SimonDanisch 38b583d
add bitreverse
SimonDanisch ecfd47d
erge branch 'master' into auto-spirv-extensions
SimonDanisch 33228a2
add tests
SimonDanisch 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 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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using KernelAbstractions | ||
| using Atomix: Atomix | ||
|
|
||
| @testset "spirv_extensions" begin | ||
|
|
||
| @testset "bitreverse KernelAbstractions kernel" begin | ||
| @kernel function bitreverse_ka!(out, inp) | ||
| i = @index(Global) | ||
| @inbounds out[i] = bitreverse(inp[i]) | ||
| end | ||
|
|
||
| @testset "$T" for T in [Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64] | ||
| N = 64 | ||
| inp = CLArray(rand(T, N)) | ||
| out = similar(inp) | ||
| bitreverse_ka!(OpenCLBackend())(out, inp; ndrange=N) | ||
| synchronize(OpenCLBackend()) | ||
|
|
||
| @test Array(out) == bitreverse.(Array(inp)) | ||
| end | ||
| end | ||
|
|
||
| @testset "atomic float accumulation without manual extensions" begin | ||
| # The auto-spirv-extensions feature detects cl_ext_float_atomics and enables | ||
| # SPV_EXT_shader_atomic_float_add automatically. Previously this required | ||
| # passing extensions=["SPV_EXT_shader_atomic_float_add"] to @opencl manually. | ||
| # | ||
| # We test with a concurrent accumulation pattern where multiple work-items | ||
| # write to the same output locations. Without atomics this would race; | ||
| # with Atomix.@atomic (which emits OpAtomicFAddEXT) the result must be exact. | ||
| if "cl_ext_float_atomics" in cl.device().extensions | ||
| @kernel function atomic_accum_kernel!(out, arr) | ||
| i, j = @index(Global, NTuple) | ||
| for k in 1:size(out, 1) | ||
| Atomix.@atomic out[k, i] += arr[i, j] | ||
| end | ||
| end | ||
|
|
||
| @testset "$T" for T in [Float32, Float64] | ||
| if T == Float64 && !("cl_khr_fp64" in cl.device().extensions) | ||
| continue | ||
| end | ||
|
|
||
| M, N = 32, 64 | ||
| img = zeros(T, M, N) | ||
| img[5:15, 5:15] .= one(T) | ||
| img[20:30, 20:30] .= T(2) | ||
|
|
||
| cl_img = CLArray(img) | ||
| out = KernelAbstractions.zeros(OpenCLBackend(), T, M, N) | ||
| atomic_accum_kernel!(OpenCLBackend())(out, cl_img; ndrange=(M, N)) | ||
| synchronize(OpenCLBackend()) | ||
|
|
||
| # Each out[k, i] = sum(img[i, :]) — accumulate row i across all columns | ||
| out_host = Array(out) | ||
| expected = zeros(T, M, N) | ||
| for i in 1:M | ||
| expected[:, i] .= sum(img[i, :]) | ||
| end | ||
| @test out_host ≈ expected | ||
| end | ||
| end | ||
| end | ||
|
|
||
| end |
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.
This seems useful but unrelated, do you want to open a separate PR?