Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/gcn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ function llvm_machine(target::GCNCompilerTarget)
return tm
end

# the external back-end replaces the module's datalayout with its own, which aligns i128 to
# 16 bytes. it does keep a 64-bit alignment if the module asks for one (since
# AMDGPU_LLVM_Backend_jll 23.1.1+4), which Julia needs before 1.12 to lay out kernel
# arguments like the host does.
function llvm_datalayout(target::GCNCompilerTarget)
dl = @invoke llvm_datalayout(target::AbstractCompilerTarget)
(dl === nothing || target.backend !== :external) && return dl
@dispose dl=dl begin
string(dl) * "-i128:$(8 * Base.datatype_alignment(Int128))"
end
end


# AMDGPU calls the device scope `agent`, and the subgroup one `wavefront`
llvm_syncscope(::GCNCompilerTarget, name::String) =
Expand Down
29 changes: 29 additions & 0 deletions test/gcn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,35 @@ end
end
end

@testset "Int128 kernel arguments" begin
# the back-end must lay out kernel arguments like the host does, which before Julia 1.12
# aligns Int128 to 8 bytes (JuliaGPU/AMDGPU.jl#1002)
mod = @eval module $(gensym())
kernel(a::Int32, b::Int128, c::Tuple{Int32,Int128}, d::Int64) = return
end
types = Tuple{Int32, Int128, Tuple{Int32,Int128}, Int64}
arg_offset(i) = fieldoffset(types, i)
arg_size(i) = sizeof(fieldtype(types, i))

@test @filecheck begin
@check "amdhsa.kernels:"
@check_next "- .args:"
@check ".offset: $(arg_offset(1)){{\$}}"
@check_next ".size: $(arg_size(1)){{\$}}"
@check_next ".value_kind: by_value"
@check ".offset: $(arg_offset(2)){{\$}}"
@check_next ".size: $(arg_size(2)){{\$}}"
@check_next ".value_kind: by_value"
@check ".offset: $(arg_offset(3)){{\$}}"
@check_next ".size: $(arg_size(3)){{\$}}"
@check_next ".value_kind: by_value"
@check ".offset: $(arg_offset(4)){{\$}}"
@check_next ".size: $(arg_size(4)){{\$}}"
@check_next ".value_kind: by_value"
GCN.code_native(mod.kernel, types; dump_module=true, kernel=true)
end
end

@testset "skip scalar trap" begin
mod = @eval module $(gensym())
workitem_idx_x() = ccall("llvm.amdgcn.workitem.id.x", llvmcall, Int32, ())
Expand Down
Loading