Repository navigation
Check the alignment of arrays passed to kernels - #733
Merged
Merged
Conversation
maleadt
force-pushed
the
tb/kernel-alignment-check
branch
2 times, most recently
from
October 25, 2026 06:17
ac690be to
09bb61e
Compare
`reinterpret` on a oneDeviceArray called `_reinterpret_exception`, which oneAPI.jl doesn't define, so any kernel using it failed to compile with an InvalidIRError. Call the GPUArrays function, as CUDA.jl and Metal.jl do.
maleadt
force-pushed
the
tb/kernel-alignment-check
branch
from
October 25, 2026 18:03
09bb61e to
51a7914
Compare
Since oneArray offsets are stored in bytes (#570), `reinterpret` of a view can yield an array that isn't aligned for its element type, e.g. `reinterpret(UInt64, view(a::oneVector{UInt8}, 2:17))`. Copies handle that fine, but kernels access elements assuming the element type's alignment, and Intel GPUs then silently access the wrong memory: on an Arc A770, loads of such an array read from the address rounded down to 8 bytes, and stores were lost. Check the pointer when converting a oneArray to a device array and throw an ArgumentError instead. Device-side `reinterpret` to a type with a stronger alignment requirement checks the pointer too. x-ref JuliaGPU/CUDA.jl#3451
maleadt
force-pushed
the
tb/kernel-alignment-check
branch
from
October 25, 2026 19:35
51a7914 to
de005dc
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #733 +/- ##
==========================================
- Coverage 86.93% 86.64% -0.30%
==========================================
Files 56 55 -1
Lines 5120 4993 -127
==========================================
- Hits 4451 4326 -125
+ Misses 669 667 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Since #570 stores oneArray offsets in bytes,
reinterpretof a view can produce an array that isn't aligned for its element type. Copying such an array works, but kernels assume the element type's alignment, and on Intel GPUs they then access the wrong memory without any error. On an Arc A770:This PR checks the pointer when a oneArray is converted to a device array, both when launching a kernel and in
unsafe_convert, and throws anArgumentErrorthat suggestscopy. Empty arrays are exempt. The check uses the alignment that device-side element accesses already assume, so nothing that currently works correctly is rejected. A device-sidereinterpretto a type with a stronger alignment requirement (e.g.Int32toInt64) checks the pointer as well. That required fixing device-sidereinterpretfirst: it called an undefined_reinterpret_exception, so every kernel using it failed to compile (separate commit).CUDA.jl makes the same change. On NVIDIA GPUs these kernels fault with
ERROR_MISALIGNED_ADDRESSand leave the context unusable (x-ref JuliaGPU/CUDA.jl#3451). Raising the assumed alignment to the element size so thatComplexF32orNTuple{4,Float32}get vector loads, as CUDA.jl also does, isn't worth it here: IGC already emitsd32x2/d32x4loads for those types on the A770, and the generated code and timings were identical with the higher alignment.Tested on an Arc A770 by running
arrayandexecution. With the new tests but without the fix, the broadcast andunsafe_converttests don't throw, and the device-sidereinterpretreads0x0000000200000000instead of not storing.