-
Notifications
You must be signed in to change notification settings - Fork 845
[libclc][amdgpu] Implement __spirv_GroupNonUniform*Shuffle* builtins #22665
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
zjin-lcf
wants to merge
1
commit into
intel:sycl
Choose a base branch
from
zjin-lcf:amdgpu-group-nonuniform-shuffle
base: sycl
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.
+71
−0
Open
Changes from all commits
Commits
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,70 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 <libspirv/spirv.h> | ||
|
|
||
| #pragma OPENCL EXTENSION cl_khr_fp16 : enable | ||
| #pragma OPENCL EXTENSION cl_khr_fp64 : enable | ||
|
|
||
| // The __spirv_GroupNonUniform*Shuffle* builtins are emitted directly by the | ||
| // SYCL headers (see sycl/detail/spirv.hpp) for sub-group shuffle, permute and | ||
| // scan operations, and are relied upon by oneDPL work-group algorithms. Unlike | ||
| // SPIR-V targets, the amdgcn target has no runtime translation for these | ||
| // instructions, so they must be provided by the device library. | ||
| // | ||
| // The SYCL headers scalarize every shuffle before reaching the intrinsic | ||
| // (vectors and marrays are handled element-wise, and bitcast/generic shuffles | ||
| // are lowered onto integer scalars), so only scalar overloads are required | ||
| // here - mirroring the scalar-only __spirv_GroupBroadcast definitions in | ||
| // group/collectives.cl. | ||
| // | ||
| // Each operation maps directly onto the corresponding, already validated, | ||
| // __spirv_SubgroupShuffle*INTEL primitive (see misc/sub_group_shuffle.cl), | ||
| // which lowers to the hardware ds_bpermute wavefront shuffle. The Shuffle Up | ||
| // and Down primitives take a pair of (previous/current) or (current/next) | ||
| // operands; for the single-operand SPIR-V form we pass the same value for both, | ||
| // which is correct within a single sub-group and preserves the SPIR-V contract | ||
| // that out-of-range indices produce an undefined result. | ||
| // The scope operand is unused: the delegated __spirv_SubgroupShuffle*INTEL | ||
| // primitives operate at sub-group (wavefront) granularity, matching the | ||
| // Subgroup path of __spirv_GroupBroadcast in group/collectives.cl. | ||
| #define __CLC_GROUP_NON_UNIFORM_SHUFFLE(TYPE) \ | ||
| _CLC_DEF _CLC_OVERLOAD _CLC_CONVERGENT TYPE __spirv_GroupNonUniformShuffle( \ | ||
| int scope, TYPE value, uint id) { \ | ||
| (void)scope; \ | ||
| return __spirv_SubgroupShuffleINTEL(value, id); \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. current implementation is also fine since the spec requires |
||
| } \ | ||
| _CLC_DEF _CLC_OVERLOAD _CLC_CONVERGENT TYPE \ | ||
| __spirv_GroupNonUniformShuffleXor(int scope, TYPE value, uint mask) { \ | ||
| (void)scope; \ | ||
| return __spirv_SubgroupShuffleXorINTEL(value, mask); \ | ||
| } \ | ||
| _CLC_DEF _CLC_OVERLOAD _CLC_CONVERGENT TYPE \ | ||
| __spirv_GroupNonUniformShuffleUp(int scope, TYPE value, uint delta) { \ | ||
| (void)scope; \ | ||
| return __spirv_SubgroupShuffleUpINTEL(value, value, delta); \ | ||
| } \ | ||
| _CLC_DEF _CLC_OVERLOAD _CLC_CONVERGENT TYPE \ | ||
| __spirv_GroupNonUniformShuffleDown(int scope, TYPE value, uint delta) { \ | ||
| (void)scope; \ | ||
| return __spirv_SubgroupShuffleDownINTEL(value, value, delta); \ | ||
| } | ||
|
|
||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(char) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(uchar) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(short) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(ushort) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(int) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(uint) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(long) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(ulong) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(half) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(float) | ||
| __CLC_GROUP_NON_UNIFORM_SHUFFLE(double) | ||
|
|
||
| #undef __CLC_GROUP_NON_UNIFORM_SHUFFLE | ||
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.