Skip to content

[ROCm] For SPIRV: replace preprocessor checks for gfx9xx with builtin_amdgcn_processor_is() - #172476

Closed
lakhinderwalia wants to merge 13 commits into
pytorch:mainfrom
lakhinderwalia:lw/replace_gfx_flags
Closed

lakhinderwalia wants to merge 13 commits into
pytorch:mainfrom
lakhinderwalia:lw/replace_gfx_flags

Conversation

@lakhinderwalia

@lakhinderwalia lakhinderwalia commented Jan 14, 2026 •

Copy link
Copy Markdown
Contributor

@lakhinderwalia
lakhinderwalia requested a review from eqy as a code owner January 14, 2026 19:37
Copilot AI review requested due to automatic review settings January 14, 2026 19:37
@pytorch-bot

pytorch-bot Bot commented Jan 14, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/172476

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures

As of commit f48e7ca with merge base 018bf86 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

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 replaces compile-time preprocessor checks for AMD GPU architectures (gfx90a, gfx942, gfx950) with runtime checks using __builtin_amdgcn_processor_is() to support SPIRV compilation. The changes enable device-specific code paths to be selected at runtime rather than compile-time, which is necessary for SPIRV's architecture-agnostic compilation model.

Changes:

  • Replaced #if defined(__gfx90a__), #if defined(__gfx942__), and #if defined(__gfx950__) preprocessor directives with runtime __builtin_amdgcn_processor_is() checks
  • Removed the CDNA2_OR_LATER macro in favor of runtime architecture detection
  • Updated atomic operations and kernel implementations to use conditional runtime branching

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
aten/src/ATen/native/cuda/layer_norm_kernel.cu Replaced compile-time gfx90a checks with runtime checks for reciprocal operations, introducing lambda functions for cleaner code organization
aten/src/ATen/native/cuda/int4mm.cu Removed CDNA2_OR_LATER macro and moved architecture checks to runtime within the kernel function
aten/src/ATen/native/cuda/ScatterGatherKernel.cu Converted preprocessor-based atomic operation selection to runtime branching
aten/src/ATen/native/cuda/MemoryAccess.cuh Added runtime check for gfx942-specific non-temporal load optimizations
aten/src/ATen/native/cuda/KernelUtils.cuh Replaced preprocessor checks with runtime conditionals in atomic add implementations, utilizing __builtin_amdgcn_is_invocable
aten/src/ATen/native/cuda/Indexing.cu Converted preprocessor-based atomic operation selection to runtime branching
aten/src/ATen/native/cuda/CUDALoops.cuh Replaced preprocessor checks for gfx942 with runtime branching for thread work size selection
aten/src/ATen/cuda/Atomic.cuh Converted gfx908-specific atomic operations to runtime checks
Comments suppressed due to low confidence (1)

aten/src/ATen/native/cuda/KernelUtils.cuh:82

  • Extra space in namespace declaration. Should be 'at::native' not 'at:: native'.
namespace at:: native {

Comment thread aten/src/ATen/native/cuda/Indexing.cu Resolved
Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
Comment thread aten/src/ATen/cuda/Atomic.cuh Resolved
@jithunnair-amd jithunnair-amd changed the title For SPIRV: replace preprocessor checks for gfx9xx with builtin_amdgcn_processor_is() [ROCm] For SPIRV: replace preprocessor checks for gfx9xx with builtin_amdgcn_processor_is() Jan 14, 2026
@pytorch-bot pytorch-bot Bot added ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 module: rocm AMD GPU support for Pytorch and removed ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 labels Jan 14, 2026
@mikaylagawarecki mikaylagawarecki added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jan 16, 2026
Comment thread aten/src/ATen/native/cuda/int4mm.cu Resolved

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
Comment thread aten/src/ATen/native/cuda/int4mm.cu Resolved
Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
jeffdaily
jeffdaily previously approved these changes Feb 6, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase -b main

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased lw/replace_gfx_flags onto refs/remotes/origin/main, please pull locally before adding more changes (for example, via git checkout lw/replace_gfx_flags && git pull --rebase)

Comment thread aten/src/ATen/native/cuda/CUDALoops.cuh Resolved
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase -b main

Rebasing after the other amdgcnspirv PR landed.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot revert -c nosignal -m "broke nightly builds https://github.com/pytorch/pytorch/actions/runs/24179438750/job/70568465816"

2026-04-09T11:25:18.5621137Z [7500/8169] Building HIPCC object caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/torch_hip_generated_int4mm.hip.o�[K
2026-04-09T11:25:18.5625401Z �[31mFAILED: [code=1] �[0mcaffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/torch_hip_generated_int4mm.hip.o /pytorch/build/caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/torch_hip_generated_int4mm.hip.o 
2026-04-09T11:25:18.5633947Z cd /pytorch/build/caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip && /opt/_internal/cpython-3.10.20/lib/python3.10/site-packages/cmake/data/bin/cmake -E make_directory /pytorch/build/caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/. && /opt/_internal/cpython-3.10.20/lib/python3.10/site-packages/cmake/data/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=RELEASE -D generated_file:STRING=/pytorch/build/caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/./torch_hip_generated_int4mm.hip.o -P /pytorch/build/caffe2/CMakeFiles/torch_hip.dir/__/aten/src/ATen/native/hip/torch_hip_generated_int4mm.hip.o.cmake
2026-04-09T11:25:18.5641210Z fatal error: error in backend: Cannot select: intrinsic %llvm.amdgcn.mfma.f32.16x16x16bf16.1k
2026-04-09T11:25:18.5643167Z clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@lakhinderwalia your PR has been successfully reverted.

@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels Apr 9, 2026
@pytorch-bot
pytorch-bot Bot dismissed jeffdaily’s stale review April 9, 2026 22:16

This PR was reopened (likely due to being reverted), so your approval was removed. Please request another review.

__builtin_amdgcn_is_invocable incorrectly reports the
mfma_f32_16x16x16bf16_1k intrinsic as available on gfx908 (CDNA1),
but the LLVM backend cannot select it, causing a "Cannot select"
error during multi-target compilation. Add preprocessor guards to
exclude gfx908 at compile time while preserving __builtin_amdgcn_is_invocable
for forward-compatible feature detection on all other architectures.

Co-Authored-By: Claude Opus 4.6 (1M context)
@pytorch-bot pytorch-bot Bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Apr 10, 2026
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 27, 2026
@pytorch-bot

pytorch-bot Bot commented Apr 27, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/trunk

Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: pull / linux-jammy-py3.14-clang18 / test (dynamo_wrapped, 1, 3, lf.linux.2xlarge), pull / linux-docs / build-docs-python-false

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

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

Labels

ci-no-td Do not run TD on this PR ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel Reverted triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ROCm] For SPIRV: replace certain preprocessor checks for AMD GPU IDs __gfxxxx__ with their builtin_amdgcn_processor_is() counterpart.

8 participants