Skip to content

Commit a7d3f8b

Browse files
eschnettmaleadt
andauthored
Fixes for Julia 1.13. (#3020)
Co-authored by: Erik Schnetter <schnetter@gmail.com> Co-authored by: Karlo Sepetanc <karlo.sepetanc@live.com> Co-authored-by: Tim Besard <tim.besard@gmail.com>
1 parent 9c24e73 commit a7d3f8b

8 files changed

Lines changed: 459 additions & 447 deletions

File tree

.buildkite/pipeline.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ steps:
3333
- "1.10"
3434
- "1.11"
3535
- "1.12"
36+
- "1.13"
3637
- "nightly"
3738
adjustments:
3839
- with:

lib/nvml/NVML.jl

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ import Libdl
1212

1313
export has_nvml
1414

15-
function libnvml()
16-
@memoize begin
17-
if Sys.iswindows()
18-
# the NVSMI dir isn't added to PATH by the installer
19-
nvsmi = joinpath(ENV["ProgramFiles"], "NVIDIA Corporation", "NVSMI")
20-
if isdir(nvsmi)
21-
joinpath(nvsmi, "nvml.dll")
22-
else
23-
# let's just hope for the best
24-
"nvml"
25-
end
26-
else
27-
"libnvidia-ml.so.1"
28-
end
29-
end::String
15+
const libnvml::String = if Sys.iswindows()
16+
# the NVSMI dir isn't added to PATH by the installer
17+
nvsmi = joinpath(ENV["ProgramFiles"], "NVIDIA Corporation", "NVSMI")
18+
if isdir(nvsmi)
19+
joinpath(nvsmi, "nvml.dll")
20+
else
21+
# let's just hope for the best
22+
"nvml"
23+
end
24+
else
25+
"libnvidia-ml.so.1"
3026
end
3127

3228
function has_nvml()
@@ -37,7 +33,7 @@ function has_nvml()
3733
return false
3834
end
3935

40-
if Libdl.dlopen(libnvml(); throw_error=false) === nothing
36+
if Libdl.dlopen(libnvml; throw_error=false) === nothing
4137
return false
4238
end
4339

lib/nvml/libnvml.jl

Lines changed: 398 additions & 398 deletions
Large diffs are not rendered by default.

res/wrap/nvml.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[general]
2-
library_name = "libnvml()"
2+
library_name = "libnvml"
33
output_file_path = "../../lib/nvml/libnvml.jl"
44
prologue_file_path = "./libnvml_prologue.jl"
55

src/device/intrinsics/indexing.jl

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,54 +63,54 @@ end
6363

6464
@device_functions begin
6565

66-
"""
67-
gridDim()::NamedTuple
66+
@doc """
67+
threadIdx()::NamedTuple
6868
69-
Returns the dimensions of the grid.
70-
"""
71-
@inline gridDim() = (x=gridDim_x(), y=gridDim_y(), z=gridDim_z())
69+
Returns the thread index within the block.
70+
""" threadIdx
71+
@inline threadIdx() = (x=threadIdx_x(), y=threadIdx_y(), z=threadIdx_z())
7272

73-
"""
74-
blockIdx()::NamedTuple
73+
@doc """
74+
blockDim()::NamedTuple
7575
76-
Returns the block index within the grid.
77-
"""
78-
@inline blockIdx() = (x=blockIdx_x(), y=blockIdx_y(), z=blockIdx_z())
76+
Returns the dimensions (in threads) of the block.
77+
""" blockDim
78+
@inline blockDim() = (x=blockDim_x(), y=blockDim_y(), z=blockDim_z())
7979

80-
"""
81-
blockDim()::NamedTuple
80+
@doc """
81+
blockIdx()::NamedTuple
8282
83-
Returns the dimensions of the block.
84-
"""
85-
@inline blockDim() = (x=blockDim_x(), y=blockDim_y(), z=blockDim_z())
83+
Returns the block index within the grid.
84+
""" blockIdx
85+
@inline blockIdx() = (x=blockIdx_x(), y=blockIdx_y(), z=blockIdx_z())
8686

87-
"""
88-
threadIdx()::NamedTuple
87+
@doc """
88+
gridDim()::NamedTuple
8989
90-
Returns the thread index within the block.
91-
"""
92-
@inline threadIdx() = (x=threadIdx_x(), y=threadIdx_y(), z=threadIdx_z())
90+
Returns the dimensions (in blocks) of the grid.
91+
""" gridDim
92+
@inline gridDim() = (x=gridDim_x(), y=gridDim_y(), z=gridDim_z())
9393

94-
"""
94+
@doc """
9595
warpsize()::Int32
9696
9797
Returns the warp size (in threads).
98-
"""
98+
""" warpsize
9999
@inline warpsize() = ccall("llvm.nvvm.read.ptx.sreg.warpsize", llvmcall, Int32, ())
100100

101-
"""
101+
@doc """
102102
laneid()::Int32
103103
104104
Returns the thread's lane within the warp.
105-
"""
105+
""" laneid
106106
@inline laneid() = ccall("llvm.nvvm.read.ptx.sreg.laneid", llvmcall, Int32, ()) + 1i32
107107

108-
"""
108+
@doc """
109109
lanemask(pred)::UInt32
110110
111111
Returns a 32-bit mask indicating which threads in a warp satisfy the given predicate.
112112
Supported predicates are `==`, `<`, `<=`, `>=`, and `>`.
113-
"""
113+
""" lanemask
114114
@inline function lanemask(pred::F) where F
115115
if pred === Base.:(==)
116116
ccall("llvm.nvvm.read.ptx.sreg.lanemask.eq", llvmcall, UInt32, ())
@@ -127,12 +127,12 @@ Supported predicates are `==`, `<`, `<=`, `>=`, and `>`.
127127
end
128128
end
129129

130-
"""
130+
@doc """
131131
active_mask()
132132
133133
Returns a 32-bit mask indicating which threads in a warp are active with the current
134134
executing thread.
135-
"""
135+
""" active_mask
136136
@inline active_mask() = @asmcall("activemask.b32 \$0;", "=r", false, UInt32, Tuple{})
137137

138138
end

src/device/utils.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ macro device_functions(ex)
5252
# descend in blocks
5353
push!(out.args, rewrite(arg))
5454
elseif Meta.isexpr(arg, [:function, :(=)])
55-
# rewrite function definitions
56-
push!(out.args, :(@device_function $arg))
55+
# capture temp variable for Julia 1.13 and rewrite function definitions
56+
if Meta.isexpr(arg, :(=)) && isa(arg.args[1], Symbol) && Meta.isexpr(arg.args[2], [:function, :(=)])
57+
push!(out.args, Expr(:(=), arg.args[1], :(@device_function $(arg.args[2]))))
58+
else
59+
push!(out.args, :(@device_function $arg))
60+
end
5761
else
5862
# preserve all the rest
5963
push!(out.args, arg)

test/base/texture.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Broken on LLVM 20, see JuliaGPU/CUDA.jl#3037
2+
if !(v"20-" <= Base.libllvm_version < v"21-")
3+
14
using Interpolations
25

36
@inline function calcpoint(blockIdx, blockDim, threadIdx, size)
@@ -241,3 +244,5 @@ end
241244
end
242245
end
243246
end
247+
248+
end

test/core/device/ldg.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
@testset "ldg" begin
2-
ir = sprint(io->CUDA.code_llvm(io, CUDA.pointerref_ldg, Tuple{Core.LLVMPtr{Int,AS.Global},Int,Val{1}}))
3-
@test occursin("@llvm.nvvm.ldg", ir)
2+
ir = sprint(io->CUDA.code_llvm(io, CUDA.pointerref_ldg, Tuple{Core.LLVMPtr{Int,AS.Global},Int,Val{1}}; raw=true))
3+
if Base.libllvm_version >= v"20"
4+
# `@llvm.nvvm.ldg` was removed in LLVM 20; the auto-upgrade
5+
# replaces it with a load bearing `!invariant.load` metadata
6+
@test occursin("!invariant.load", ir)
7+
else
8+
@test occursin("@llvm.nvvm.ldg", ir)
9+
end
410
end
511

612

0 commit comments

Comments
 (0)