Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ function GPUCompiler.finish_module!(
end
end

# LLVM 20+ requires !amdgpu.no.fine.grained.memory on FP atomicrmw to emit
# native hardware atomics (e.g. global_atomic_add_f32) instead of a CAS loop.
# Mirrors Clang's setTargetAtomicMetadata; unsafe_fp_atomics is the opt-in.
if job.config.params.unsafe_fp_atomics
fp_binops = (LLVM.API.LLVMAtomicRMWBinOpFAdd, LLVM.API.LLVMAtomicRMWBinOpFSub,
LLVM.API.LLVMAtomicRMWBinOpFMax, LLVM.API.LLVMAtomicRMWBinOpFMin)
empty_md = MDNode(Metadata[])
for fn in LLVM.functions(mod), bb in LLVM.blocks(fn), inst in LLVM.instructions(bb)
inst isa LLVM.AtomicRMWInst || continue
op = LLVM.binop(inst)
op ∈ fp_binops || continue
md = LLVM.metadata(inst)
md["amdgpu.no.fine.grained.memory"] = empty_md
if op == LLVM.API.LLVMAtomicRMWBinOpFAdd && LLVM.value_type(inst) == LLVM.FloatType()
md["amdgpu.ignore.denormal.mode"] = empty_md
end
end
end

return entry
end

Expand Down Expand Up @@ -200,7 +219,7 @@ function hipcompile(@nospecialize(job::CompilerJob))
GPUCompiler.compile(:obj, job)
end

global_hostcalls = pop!(_global_hostcalls, hash(job))
global_hostcalls = pop!(_global_hostcalls, hash(job), Symbol[])
# Late global hostcalls detection.
append!(global_hostcalls, find_global_hostcalls(meta.ir))

Expand Down
Loading