Skip to content

[libclc][amdgpu] Implement __spirv_GroupNonUniform*Shuffle* builtins - #22665

Open
zjin-lcf wants to merge 5 commits into
intel:syclfrom
zjin-lcf:amdgpu-group-nonuniform-shuffle
Open

zjin-lcf wants to merge 5 commits into
intel:syclfrom
zjin-lcf:amdgpu-group-nonuniform-shuffle

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

The amdgcn libspirv device library declares the SPIR-V group non-uniform shuffle builtins (__spirv_GroupNonUniformShuffle{,Up,Down,Xor}) via libspirv/group/group_shuffle*.h but never defines them for the amdgpu target. The SYCL headers (sycl/detail/spirv.hpp) emit these directly for sub-group shuffle/permute/scan, and oneDPL work-group algorithms (inclusive_scan, sort, ...) rely on them. Device linking for amdgcn-amd-amdhsa therefore fails with e.g.

undefined symbol: __spirv_GroupNonUniformShuffleUp

Unlike SPIR-V targets there is no runtime translation of these instructions, so the device library must provide them.

Add group/group_shuffle.cl for the amdgpu target, mapping the four non-uniform shuffle operations onto the existing, validated __spirv_SubgroupShuffle*INTEL primitives (misc/sub_group_shuffle.cl), which lower to the hardware ds_bpermute wavefront shuffle. These primitives derive the wavefront size from __spirv_BuiltInSubgroupMaxSize() rather than hardcoding it and use only ds_bpermute, so they are correct across all wave64 CDNA generations (CDNA1 gfx908, CDNA2 gfx90a, CDNA3 gfx942, CDNA4 gfx950) with no arch-specific code. Only scalar overloads are defined: the SYCL headers scalarize all vector/marray shuffles and lower bitcast/generic shuffles onto integer scalars before reaching the intrinsic, matching the scalar-only __spirv_GroupBroadcast definitions in group/collectives.cl.

@zjin-lcf
zjin-lcf requested review from a team, Maetveis and wenju-he as code owners July 18, 2026 11:38
@zjin-lcf
zjin-lcf requested a review from kweronsx July 18, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes device-link failures on amdgcn-amd-amdhsa by providing missing definitions for the SPIR-V group non-uniform shuffle builtins in the AMDGPU libspirv device library, mapping them onto the existing __spirv_SubgroupShuffle*INTEL implementations (which lower to ds_bpermute).

Changes:

  • Add libclc/libspirv/lib/amdgpu/group/group_shuffle.cl implementing __spirv_GroupNonUniformShuffle{,Up,Down,Xor} for scalar types.
  • Register the new source file in the AMDGPU libspirv CMake sources list.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
libclc/libspirv/lib/amdgpu/group/group_shuffle.cl Implements missing GroupNonUniform shuffle builtins via existing AMDGPU subgroup shuffle primitives.
libclc/libspirv/lib/amdgpu/CMakeLists.txt Adds the new shuffle implementation file to the AMDGPU libspirv build.

@bratpiorka

Copy link
Copy Markdown
Contributor

@zjin-lcf please fix the code formatting

lilohuang pushed a commit to lilohuang/llvm that referenced this pull request Jul 30, 2026
Apply the final patch from intel#22665 to provide the missing __spirv_GroupNonUniformShuffle{,Up,Down,Xor} definitions for AMDGPU.

Upstream-PR: intel#22665

Upstream-Commit: af14d1d

Upstream-Commit: d11a322
lilohuang pushed a commit to lilohuang/llvm that referenced this pull request Jul 31, 2026
Apply the final patch from intel#22665 to provide the missing __spirv_GroupNonUniformShuffle{,Up,Down,Xor} definitions for AMDGPU.

Upstream-PR: intel#22665

Upstream-Commit: af14d1d

Upstream-Commit: d11a322
@bratpiorka

Copy link
Copy Markdown
Contributor

Hi @zjin-lcf , do you plan to continue working on your PRs?

@zjin-lcf

zjin-lcf commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up. Yes, I plan to continue working on this PR. The formatting issue has been fixed and the formatter check now passes. The remaining ARL CI failure is an unrelated XPASS in two bindless-image tests. I do not have permission to rerun the workflow; could a maintainer please rerun the failed job? @Maetveis @kweronsx, could you please review when convenient?

@wenju-he wenju-he left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @zjin-lcf

@zjin-lcf
zjin-lcf force-pushed the amdgpu-group-nonuniform-shuffle branch from 100a29a to 865ec36 Compare August 25, 2026 13:46

@wenju-he wenju-he left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

lilohuang pushed a commit to lilohuang/llvm that referenced this pull request Aug 26, 2026
Apply the final patch from intel#22665 to provide the missing __spirv_GroupNonUniformShuffle{,Up,Down,Xor} definitions for AMDGPU.

Upstream-PR: intel#22665

Upstream-Commit: af14d1d

Upstream-Commit: d11a322
@zjin-lcf

Copy link
Copy Markdown
Contributor Author

@wenju-he Thank you very much for your comments and suggestions.

@bratpiorka

Copy link
Copy Markdown
Contributor

Hi @zjin-lcf, I see there are a few of your older PRs that require some attention. Could you please rebase them?

zjin-lcf and others added 5 commits October 8, 2026 12:31
The amdgcn libspirv device library declares the SPIR-V group non-uniform
shuffle builtins (__spirv_GroupNonUniformShuffle{,Up,Down,Xor}) via
libspirv/group/group_shuffle*.h but never defines them for the amdgpu
target. The SYCL headers (sycl/detail/spirv.hpp) emit these directly for
sub-group shuffle/permute/scan, and oneDPL work-group algorithms
(inclusive_scan, sort, ...) rely on them. Device linking for
amdgcn-amd-amdhsa therefore fails with e.g.

  undefined symbol: __spirv_GroupNonUniformShuffleUp

Unlike SPIR-V targets there is no runtime translation of these
instructions, so the device library must provide them.

Add group/group_shuffle.cl for the amdgpu target, mapping the four
non-uniform shuffle operations onto the existing, validated
__spirv_SubgroupShuffle*INTEL primitives (misc/sub_group_shuffle.cl),
which lower to the hardware ds_bpermute wavefront shuffle. These
primitives derive the wavefront size from __spirv_BuiltInSubgroupMaxSize()
rather than hardcoding it and use only ds_bpermute, so they are correct
across all wave64 CDNA generations (CDNA1 gfx908, CDNA2 gfx90a,
CDNA3 gfx942, CDNA4 gfx950) with no arch-specific code. Only scalar
overloads are defined: the SYCL headers scalarize all vector/marray
shuffles and lower bitcast/generic shuffles onto integer scalars before
reaching the intrinsic, matching the scalar-only __spirv_GroupBroadcast
definitions in group/collectives.cl.

Co-authored-by: Cursor <[email protected]>
Use the operation's full SPIR-V name to distinguish group non-uniform shuffles from other shuffle implementations.

Co-authored-by: Cursor <[email protected]>
…oads

Clang declares these builtins for every vector width, so calls with a vector
Value operand must resolve for amdgcn too, even though the SYCL headers only
ever emit the scalar forms. Add a lit test that fails on any overload libspirv
declares but the target does not define.

Co-authored-by: Cursor <[email protected]>
Follow the standard libclc gentype pattern so scalar and vector shuffle overloads share one implementation while preserving element-wise vector lowering.

Co-authored-by: Cursor <[email protected]>
@zjin-lcf
zjin-lcf force-pushed the amdgpu-group-nonuniform-shuffle branch from 865ec36 to b2e5fba Compare October 8, 2026 19:37
@zjin-lcf

zjin-lcf commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current sycl (51add4ae931a). The five commits apply cleanly; the diff is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants