Repository navigation
[AMD] Swap floating-point values as integers in buffer atomic xchg - #11904
Merged
Merged
Conversation
tl.atomic_xchg on an fp64 tensor aborts compilation on gfx942, gfx950 and gfx1250 with "LLVM ERROR: Cannot select: ... AMDGPUISD::BUFFER_ATOMIC_SWAP": ConvertToBufferOps turns the atomic into a buffer atomic, and the AMDGPU backend has no f64 buffer swap. A swap only moves bits, so emit the swap intrinsic on the same-width integer type and bitcast around it. The new test_tensor_atomic_xchg also exposed that the interpreter rejects floating-point atomic_xchg; allow float and double there too.
LiRunGuo
requested review from
antiagainst,
ptillet and
zhanglx13
as code owners
September 22, 2026 02:53
The XCHG path converted each float element to an integer but kept the
vector, so a vector<2xf16>/vector<2xbf16> exchange became a <2 x i16>
buffer swap, which the AMDGPU backend cannot select either ("Cannot
select: v2i16 ... BUFFER_ATOMIC_SWAP"). The backend only has i32, i64
and f32 buffer swap patterns, so exchange a scalar integer of the whole
value width instead.
Small integer values cannot tell a bit-preserving swap from a value-converting one, so exchange random bit patterns plus -0.0, infinities, NaN payloads and a denormal, and compare bits. On targets with buffer atomics, also check that the kernel uses buffer_atomic_swap, so the test keeps covering the f64 buffer swap fix.
antiagainst
approved these changes
Oct 13, 2026
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.
Background
tl.atomic_xchgon an fp64 tensor aborts the process on gfx942, gfx950 and gfx1250:ConvertToBufferOpsturns the atomic intoamdg.buffer_atomic_rmw exch, which lowers tollvm.amdgcn.raw.ptr.buffer.atomic.swapon the value type, and the AMDGPU backend has no f64 buffer swap. fp32 swaps, i64 swaps and fp64 add/max compile fine (#11019 fixed theswapintrinsic name, not the type).Summary
A swap only moves bits, so
BufferEmitter::emitAtomicRMWnow emits the XCHG intrinsic on the same-width integer type and bitcasts around it (fp32 swaps become i32 swaps, which is equivalent).The new Python test also showed that the interpreter rejects floating-point
atomic_xchg(ValueError: Unsupported data type) even though the GPU path accepts it;floatanddoubleare added to the interpreter's XCHG types.Tests
test/Conversion/amd/buffer_load_store.mlir: f64 and f32exchlower to an integerbuffer.atomic.swap(the f64 case fails before, passes after). All AMD lit tests pass (test/Conversion/amd,test/TritonGPU/amd: 124).test_core.py::test_tensor_atomic_xchg: int32/int64/fp32/fp64 tensor exchange, with and without using the returned values. Passes on H200 and in the interpreter (the float cases failed in the interpreter before).atomic_xchg/atomic_add/atomic_maxx fp64/fp32/i64/i32 x acq_rel/relaxed on gfx942/gfx950/gfx1250: 6 fp64 xchg aborts before, all 72 compile after.New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these
rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD.Select one of the following.
/testforlittests/unittestfor C++ tests/python/testfor end-to-end testsFILL THIS IN.Select one of the following.
littests.littests I have added follow these best practices,including the "tests should be minimal" section. (Usually running Python code
and using the instructions it generates is not minimal.)