Skip to content

GCN: generate machine code via external AMDGPU_LLVM_Backend_jll#857

Open
vchuravy wants to merge 2 commits into
mainfrom
vc/amdgpu_backend
Open

GCN: generate machine code via external AMDGPU_LLVM_Backend_jll#857
vchuravy wants to merge 2 commits into
mainfrom
vc/amdgpu_backend

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Mirror the NVPTX_LLVM_Backend_jll approach (see src/ptx.jl) for AMDGPU: generate GCN machine code through the external, up-to-date llc from AMDGPU_LLVM_Backend_jll rather than the in-process LLVM back-end.

Changes

  • src/gcn.jl: add an AMDGPU_LLVM_Backend_jll LazyModule and an @unlocked mcgen(::CompilerJob{GCNCompilerTarget}, …) override that writes the module to a .bc, runs the external llc (-mtriple/-mcpu=dev_isa/-mattr=features/--relocation-model=pic/-filetype), surfaces stderr diagnostics, and reads back the asm/object.
  • Project.toml: AMDGPU_LLVM_Backend_jll weakdep + compat = "22".
  • test/Project.toml: add as a test dep.
  • test/runtests.jl: load it and skip the gcn testsuite when !AMDGPU_LLVM_Backend_jll.is_available().

Notes

  • Unlike PTX, this keeps GCN's llvm_machine/llvm_datalayout as-is, so the middle end still requires the in-process AMDGPU back-end (:AMDGPU in LLVM.backends(), already guarded by test/gcn.jl); only final machine-code emission goes through the external llc. Full decoupling would require a hardcoded datalayout, which is awkward because AMDGPU's datalayout already carries non-integral spaces (…-ni:7:8:9) that GPUCompiler then extends with -ni:10:11:12:13.
  • Depends on the registration of AMDGPU_LLVM_Backend_jll (New package: AMDGPU_LLVM_Backend_jll v22.1.7+0 JuliaRegistries/General#158674); until that merges the project will not resolve.

🤖 Generated with Claude Code

@vchuravy vchuravy closed this Jun 22, 2026
@vchuravy vchuravy reopened this Jun 22, 2026
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.72727% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.27%. Comparing base (68883fe) to head (73956a4).

Files with missing lines Patch % Lines
src/gcn.jl 72.72% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
- Coverage   80.32%   80.27%   -0.06%     
==========================================
  Files          25       25              
  Lines        4777     4810      +33     
==========================================
+ Hits         3837     3861      +24     
- Misses        940      949       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vchuravy vchuravy marked this pull request as ready for review June 22, 2026 13:07
@vchuravy vchuravy requested a review from maleadt June 22, 2026 13:07
@vchuravy

Copy link
Copy Markdown
Member Author

@maleadt did you do anything special to stop older version of CUDA to use GPUCompiler without NVPTX_LLVM_Backend_jll being loaded?

@maleadt

maleadt commented Jun 22, 2026

Copy link
Copy Markdown
Member

did you do anything special to stop older version of CUDA to use GPUCompiler without NVPTX_LLVM_Backend_jll being loaded?

Add a compat bound to the registry. Looking back at the problems that caused, I think it would be better to temporarily support both the in-process and external LLVM path, deprecating the former until we cut a breaking release.

vchuravy and others added 2 commits June 23, 2026 08:53
Mirror the NVPTX_LLVM_Backend_jll approach for AMDGPU: override `mcgen`
for `GCNCompilerTarget` to emit machine code through the external, up-to-date
`llc` from AMDGPU_LLVM_Backend_jll instead of the in-process LLVM back-end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Instead of erroring when AMDGPU_LLVM_Backend_jll is not loaded, fall back
to the (deprecated) in-process LLVM back-end. This keeps existing
consumers working until the external back-end can be required in the next
breaking release. A deprecation warning nudges users to load the jll.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vchuravy vchuravy force-pushed the vc/amdgpu_backend branch from 51874b1 to 73956a4 Compare June 23, 2026 06:53
Comment thread test/gcn.jl
Comment on lines +454 to +461
# simulate AMDGPU_LLVM_Backend_jll not being loaded
pkg = Base.PkgId(Base.UUID("cc5c0156-bd05-5a77-8a68-bb0aafb29019"),
"AMDGPU_LLVM_Backend_jll")
saved = get(Base.loaded_modules, pkg, nothing)
try
delete!(Base.loaded_modules, pkg)
@test !GPUCompiler.isavailable(GPUCompiler.AMDGPU_LLVM_Backend_jll)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@maleadt this is a fairly horrifying way of testing this. Any better ideas?

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.

2 participants