-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL][CUDA] Add basic sub-group functionality #2587
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
75848a6
[SYCL] Wrap sub-group built-ins in functions
Pennycook 8e4f123
[SYCL][CUDA] Add basic sub-group functionality
Pennycook b118698
[SYCL][CUDA] Enable basic sub-group tests for CUDA
Pennycook 41d157d
[SYCL][CUDA] Remove else after return
Pennycook fcc055a
[SYCL][CUDA] Add sub-group headers to spirv.h
Pennycook 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
15 changes: 15 additions & 0 deletions
15
libclc/ptx-nvidiacl/libspirv/workitem/get_max_sub_group_size.cl
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,15 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <spirv/spirv.h> | ||
|
|
||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize() { | ||
| return 32; | ||
| // FIXME: warpsize is defined by NVVM IR but doesn't compile if used here | ||
| // return __nvvm_read_ptx_sreg_warpsize(); | ||
| } |
21 changes: 21 additions & 0 deletions
21
libclc/ptx-nvidiacl/libspirv/workitem/get_num_sub_groups.cl
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,21 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <spirv/spirv.h> | ||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize(); | ||
|
|
||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups() { | ||
| // sreg.nwarpid returns number of warp identifiers, not number of warps | ||
| // see https://docs.nvidia.com/cuda/parallel-thread-execution/index.html | ||
| size_t size_x = __spirv_WorkgroupSize_x(); | ||
| size_t size_y = __spirv_WorkgroupSize_y(); | ||
| size_t size_z = __spirv_WorkgroupSize_z(); | ||
| uint sg_size = __spirv_SubgroupMaxSize(); | ||
| uint linear_size = size_z * size_y * size_x; | ||
| return (linear_size + sg_size - 1) / sg_size; | ||
| } |
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,23 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <spirv/spirv.h> | ||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize(); | ||
|
|
||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupId() { | ||
| // sreg.warpid is volatile and doesn't represent virtual warp index | ||
| // see https://docs.nvidia.com/cuda/parallel-thread-execution/index.html | ||
| size_t id_x = __spirv_LocalInvocationId_x(); | ||
| size_t id_y = __spirv_LocalInvocationId_y(); | ||
| size_t id_z = __spirv_LocalInvocationId_z(); | ||
| size_t size_x = __spirv_WorkgroupSize_x(); | ||
| size_t size_y = __spirv_WorkgroupSize_y(); | ||
| size_t size_z = __spirv_WorkgroupSize_z(); | ||
| uint sg_size = __spirv_SubgroupMaxSize(); | ||
| return (id_z * size_y * size_x + id_y * size_x + id_x) / sg_size; | ||
| } |
13 changes: 13 additions & 0 deletions
13
libclc/ptx-nvidiacl/libspirv/workitem/get_sub_group_local_id.cl
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,13 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <spirv/spirv.h> | ||
|
|
||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupLocalInvocationId() { | ||
| return __nvvm_read_ptx_sreg_laneid(); | ||
| } |
26 changes: 26 additions & 0 deletions
26
libclc/ptx-nvidiacl/libspirv/workitem/get_sub_group_size.cl
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,26 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <spirv/spirv.h> | ||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupId(); | ||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_NumSubgroups(); | ||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupMaxSize(); | ||
|
|
||
| _CLC_DEF _CLC_OVERLOAD uint __spirv_SubgroupSize() { | ||
| if (__spirv_SubgroupId() != __spirv_NumSubgroups() - 1) { | ||
| return __spirv_SubgroupMaxSize(); | ||
| } else { | ||
bader marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| size_t size_x = __spirv_WorkgroupSize_x(); | ||
| size_t size_y = __spirv_WorkgroupSize_y(); | ||
| size_t size_z = __spirv_WorkgroupSize_z(); | ||
| uint linear_size = size_z * size_y * size_x; | ||
| uint uniform_groups = __spirv_NumSubgroups() - 1; | ||
| uint uniform_size = __spirv_SubgroupMaxSize() * uniform_groups; | ||
| return linear_size - uniform_size; | ||
| } | ||
| } | ||
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
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.