Skip to content

GCN: spell out the host's i128 alignment in the datalayout - #983

Merged
maleadt merged 1 commit into
JuliaGPU:mainfrom
luraess:lr/gcn-i128-datalayout
Oct 7, 2026
Merged

maleadt merged 1 commit into
JuliaGPU:mainfrom
luraess:lr/gcn-i128-datalayout

Conversation

@luraess

@luraess luraess commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Since AMDGPU_LLVM_Backend_jll 23.1.1+3, the external back-end aligns i128 to 16 bytes. Julia before 1.12 aligns Int128 to 8 bytes on the host. Any kernel argument at or after an Int128 therefore ends up at a different offset on the device than on the host, which makes kernels fault or read garbage (JuliaGPU/AMDGPU.jl#1002). libamdgpu replaces the module's datalayout with its own. Since 23.1.1+4 (JuliaPackaging/Yggdrasil#15010), it keeps a 64-bit i128 alignment if the module asks for one.

For the external back-end, this PR therefore appends the host's i128 alignment to the GCN datalayout. On Julia 1.12+, that is i128:128. The kernel argument layout doesn't change there, but the middle end's datalayout now matches the back-end's instead of inheriting the 64-bit default of Julia's LLVM. The in-process back-end is unchanged, because its datalayout comes from Julia's LLVM.

The new test compares the kernel argument offsets and sizes in the amdhsa.kernels metadata with the host layout of the argument types. On Julia 1.11 it fails without the source change, and with JLL 23.1.1+3. It passes with this change and 23.1.1+4:

Julia 1.11, kernel(::Int32, ::Int128, ::Tuple{Int32,Int128}, ::Int64) Int128 offset tuple size
host 8 24
main, either JLL build 16 32
this PR, 23.1.1+3 16 32
this PR, 23.1.1+4 8 24

On 1.12 and 1.13 the layout matches the host with or without this PR (16 and 32).

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.43%. Comparing base (c8f5617) to head (948ac96).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #983   +/-   ##
=======================================
  Coverage   88.42%   88.43%           
=======================================
  Files          30       30           
  Lines        6395     6400    +5     
=======================================
+ Hits         5655     5660    +5     
  Misses        740      740           

☔ 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.

@luraess

luraess commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

CI was all green, I just now trimmed the inline comments. if it looks good, happy to have it merged 🙏

@simeonschaub simeonschaub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look good, I wonder whether we can add an @filecheck regression test to check the backend actually does the right thing, i.e. something that fails with the current AMDGPU_LLVM_Backend_jll, but won't after JuliaPackaging/Yggdrasil#15010

@luraess

luraess commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

I wonder whether we can add an @filecheck regression test

Good point. I'll see to add that

@maleadt

maleadt commented Oct 6, 2026

Copy link
Copy Markdown
Member

I just now trimmed the inline comments

Better use [ci skip] then to avoid wasting CI resources.

@luraess

luraess commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

Ah yeah right

@maleadt maleadt self-assigned this Oct 6, 2026
Since AMDGPU_LLVM_Backend_jll 23.1.1+3, the external back-end aligns i128
to 16 bytes, while Julia before 1.12 aligns Int128 to 8 bytes on the host,
so kernel arguments after an Int128 were read at the wrong offset
(JuliaGPU/AMDGPU.jl#1002). The back-end replaces the module's datalayout
with its own, but since 23.1.1+4 keeps a 64-bit i128 alignment when the
module asks for one. Append the host's alignment for the external back-end;
on 1.12+ this also makes the middle end agree with the back-end's i128:128.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Tim Besard <tim.besard@gmail.com>
@maleadt
maleadt force-pushed the lr/gcn-i128-datalayout branch from 53d79e0 to 948ac96 Compare October 6, 2026 11:32
@maleadt

maleadt commented Oct 6, 2026

Copy link
Copy Markdown
Member

Added a test.

@luraess

luraess commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

Can this be merged and a released so we can finalise JuliaGPU/AMDGPU.jl#1139 🙏

@maleadt
maleadt merged commit dc597a2 into JuliaGPU:main Oct 7, 2026
35 checks passed
@luraess

luraess commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Thanks! Would it be possible to tag and release a patch?

@luraess
luraess deleted the lr/gcn-i128-datalayout branch October 7, 2026 07:03
maleadt added a commit that referenced this pull request Oct 8, 2026
Since #983, the GCN target's llvm_datalayout returns a String with the
external back-end, which the atomic validation test passed to @dispose.
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.

3 participants