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
17 changes: 12 additions & 5 deletions src/ptx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ function finish_module!(@nospecialize(job::CompilerJob{PTXCompilerTarget}),
# entry instead of re-reading the metadata.
annotations = Metadata[entry]

## kernel metadata
append!(annotations, [MDString("kernel"),
ConstantInt(Int32(1))])
# kernel metadata
#
# on LLVM >= 20 the `ptx_kernel` calling convention already marks the
# entry; the redundant "kernel" nvvm.annotation causes miscompilations.
if LLVM.version() < v"20"
append!(annotations, [MDString("kernel"),
ConstantInt(Int32(1))])
end

## expected CTA sizes
# expected CTA sizes
if job.config.target.minthreads !== nothing
bounds = ntuple(i -> i <= length(job.config.target.minthreads) ?
job.config.target.minthreads[i] : 1, 3)
Expand Down Expand Up @@ -234,7 +239,9 @@ function finish_module!(@nospecialize(job::CompilerJob{PTXCompilerTarget}),
end
end

push!(metadata(mod)["nvvm.annotations"], MDNode(annotations))
if length(annotations) > 1
push!(metadata(mod)["nvvm.annotations"], MDNode(annotations))
end
end

# we emit properties (of the device and ptx isa) as private global constants,
Expand Down
35 changes: 0 additions & 35 deletions test/ptx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,6 @@ end
end
end

@testset "property_annotations" begin
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true) do
@check_not "nvvm.annotations"
return
end
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true, kernel=true) do
@check_not "maxntid"
@check_not "reqntid"
@check_not "minctasm"
@check_not "maxnreg"
@check "nvvm.annotations"
return
end
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true, kernel=true, maxthreads=42) do
@check "maxntidx\", i32 42"
@check "maxntidy\", i32 1"
@check "maxntidz\", i32 1"
return
end
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true, kernel=true, minthreads=42) do
@check "reqntidx\", i32 42"
@check "reqntidy\", i32 1"
@check "reqntidz\", i32 1"
return
end
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true, kernel=true, blocks_per_sm=42) do
@check "minctasm\", i32 42"
return
end
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true, kernel=true, maxregs=42) do
@check "maxnreg\", i32 42"
return
end
end

LLVM.version() >= v"8" && @testset "calling convention" begin
@test @filecheck PTX.code_llvm(Tuple{}; dump_module=true) do
@check_not "ptx_kernel"
Expand Down
Loading