-
Notifications
You must be signed in to change notification settings - Fork 77
KernelIntrinsics API #635
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
Open
christiangnrd
wants to merge
8
commits into
JuliaGPU:main
Choose a base branch
from
christiangnrd:intrinsics
base: main
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.
+168
−24
Open
KernelIntrinsics API #635
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
feee338
define basic intrinsics
vchuravy ca815e2
Fix docstrings
christiangnrd df8cbba
localmemory
christiangnrd 11b6a8e
Move default barrier implementation to KernelIntrinsics
christiangnrd f1ad412
Implement remaining intrinsics for POCL
christiangnrd d60f6f2
Add basic tests
christiangnrd 3fda18f
Int32 -> Int
christiangnrd 84d0c68
Format
christiangnrd 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module KernelIntrinsics | ||
|
||
""" | ||
get_global_size()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Return the number of global work-items specified. | ||
""" | ||
function get_global_size end | ||
|
||
""" | ||
get_global_id()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Returns the unique global work-item ID. | ||
|
||
!!! note | ||
1-based. | ||
""" | ||
function get_global_id end | ||
|
||
""" | ||
get_local_size()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Return the number of local work-items specified. | ||
""" | ||
function get_local_size end | ||
|
||
""" | ||
get_local_id()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Returns the unique local work-item ID. | ||
|
||
!!! note | ||
1-based. | ||
""" | ||
function get_local_id end | ||
|
||
""" | ||
get_num_groups()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Returns the number of groups. | ||
""" | ||
function get_num_groups end | ||
|
||
""" | ||
get_group_id()::@NamedTuple{x::Int, y::Int, z::Int} | ||
|
||
Returns the unique group ID. | ||
|
||
!!! note | ||
1-based. | ||
""" | ||
function get_group_id end | ||
|
||
function localmemory end | ||
function barrier() | ||
error("Group barrier used outside kernel or not captured") | ||
end | ||
function print end | ||
|
||
end |
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,62 @@ | ||
|
||
@kernel cpu = false inbounds = true unsafe_indices = true function test_intrinsics_kernel(results) | ||
# Test all intrinsics return NamedTuples with x, y, z fields | ||
global_size = KernelIntrinsics.get_global_size() | ||
global_id = KernelIntrinsics.get_global_id() | ||
local_size = KernelIntrinsics.get_local_size() | ||
local_id = KernelIntrinsics.get_local_id() | ||
num_groups = KernelIntrinsics.get_num_groups() | ||
group_id = KernelIntrinsics.get_group_id() | ||
|
||
if UInt32(global_id.x) <= UInt32(global_size.x) | ||
results[1, global_id.x] = global_id.x | ||
results[2, global_id.x] = local_id.x | ||
results[3, global_id.x] = group_id.x | ||
results[4, global_id.x] = global_size.x | ||
results[5, global_id.x] = local_size.x | ||
results[6, global_id.x] = num_groups.x | ||
end | ||
end | ||
|
||
|
||
function intrinsics_testsuite(backend, AT) | ||
@testset "KernelIntrinsics Tests" begin | ||
@testset "Basic intrinsics functionality" begin | ||
|
||
# Test with small kernel | ||
N = 16 | ||
results = AT(zeros(Int, 6, N)) | ||
|
||
kernel = test_intrinsics_kernel(backend(), 4, (N,)) | ||
kernel(results, ndrange = N) | ||
KernelAbstractions.synchronize(backend()) | ||
|
||
host_results = Array(results) | ||
|
||
# Verify results make sense | ||
for i in 1:N | ||
global_id_x, local_id_x, group_id_x, global_size_x, local_size_x, num_groups_x = host_results[:, i] | ||
|
||
# Global IDs should be 1-based and sequential | ||
@test global_id_x == i | ||
|
||
# Global size should match our ndrange | ||
@test global_size_x == N | ||
|
||
# Local size should be 4 (our workgroupsize) | ||
@test local_size_x == 4 | ||
|
||
# Number of groups should be ceil(N/4) = 4 | ||
@test num_groups_x == 4 | ||
|
||
# Group ID should be 1-based | ||
expected_group = div(i - 1, 4) + 1 | ||
@test group_id_x == expected_group | ||
|
||
# Local ID should be 1-based within group | ||
expected_local = ((i - 1) % 4) + 1 | ||
@test local_id_x == expected_local | ||
end | ||
end | ||
end | ||
end |
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
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.
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.
Needs docs.