Skip to content

Commit d105754

Browse files
authored
Adapt to LLVM.jl 5 and GPUCompiler.jl 0.19. (#1847)
1 parent 5297f31 commit d105754

File tree

13 files changed

+52
-47
lines changed

13 files changed

+52
-47
lines changed

Manifest.toml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ version = "0.1.9"
9999

100100
[[GPUArrays]]
101101
deps = ["Adapt", "GPUArraysCore", "LLVM", "LinearAlgebra", "Printf", "Random", "Reexport", "Serialization", "Statistics"]
102-
git-tree-sha1 = "7a2e790b1e2e6f648cfb25c4500c5de1f7b375ef"
102+
git-tree-sha1 = "9ade6983c3dbbd492cf5729f865fe030d1541463"
103103
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
104-
version = "8.6.5"
104+
version = "8.6.6"
105105

106106
[[GPUArraysCore]]
107107
deps = ["Adapt"]
@@ -110,10 +110,10 @@ uuid = "46192b85-c4d5-4398-a991-12ede77f4527"
110110
version = "0.1.4"
111111

112112
[[GPUCompiler]]
113-
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "TimerOutputs", "UUIDs"]
114-
git-tree-sha1 = "fd6431121f31fed05a5386ac88b9bb3f97fdfa69"
113+
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"]
114+
git-tree-sha1 = "590d394bad1055b798b2f9b308327ba871b7badf"
115115
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
116-
version = "0.18.0"
116+
version = "0.19.0"
117117

118118
[[InteractiveUtils]]
119119
deps = ["Markdown"]
@@ -144,15 +144,15 @@ version = "0.9.1"
144144

145145
[[LLVM]]
146146
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"]
147-
git-tree-sha1 = "f044a2796a9e18e0531b9b3072b0019a61f264bc"
147+
git-tree-sha1 = "a8960cae30b42b66dd41808beb76490519f6f9e2"
148148
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
149-
version = "4.17.1"
149+
version = "5.0.0"
150150

151151
[[LLVMExtra_jll]]
152152
deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"]
153-
git-tree-sha1 = "070e4b5b65827f82c16ae0916376cb47377aa1b5"
153+
git-tree-sha1 = "09b7505cc0b1cee87e5d4a26eea61d2e1b0dcd35"
154154
uuid = "dad2f222-ce93-54a1-a47d-0025e8a3acab"
155-
version = "0.0.18+0"
155+
version = "0.0.21+0"
156156

157157
[[LazyArtifacts]]
158158
deps = ["Artifacts", "Pkg"]
@@ -268,6 +268,12 @@ version = "1.3.0"
268268
[[SHA]]
269269
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
270270

271+
[[Scratch]]
272+
deps = ["Dates"]
273+
git-tree-sha1 = "30449ee12237627992a99d5e30ae63e4d78cd24a"
274+
uuid = "6c6a2e73-6563-6170-7368-637461726353"
275+
version = "1.2.0"
276+
271277
[[Serialization]]
272278
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
273279

@@ -337,9 +343,9 @@ version = "0.2.1"
337343

338344
[[UnsafeAtomicsLLVM]]
339345
deps = ["LLVM", "UnsafeAtomics"]
340-
git-tree-sha1 = "33af9d2031d0dc09e2be9a0d4beefec4466def8e"
346+
git-tree-sha1 = "ea37e6066bf194ab78f4e747f5245261f17a7175"
341347
uuid = "d80eeb9a-aca5-4d75-85e5-170c8b632249"
342-
version = "0.1.0"
348+
version = "0.1.2"
343349

344350
[[Zlib_jll]]
345351
deps = ["Libdl"]

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ CUDA_Runtime_Discovery = "0.2"
4141
CUDA_Runtime_jll = "0.5"
4242
ExprTools = "0.1"
4343
GPUArrays = "8.6"
44-
GPUCompiler = "0.18"
44+
GPUCompiler = "0.19"
4545
KernelAbstractions = "0.9"
46-
LLVM = "4.15"
46+
LLVM = "5"
4747
Preferences = "1"
4848
Random123 = "1.2"
4949
RandomNumbers = "1.5.3"

src/compiler/compilation.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ function compile(@nospecialize(job::CompilerJob))
102102
end
103103
function compile(@nospecialize(job::CompilerJob), ctx)
104104
# lower to PTX
105-
mi, mi_meta = GPUCompiler.emit_julia(job)
106-
ir, ir_meta = GPUCompiler.emit_llvm(job, mi; ctx)
107-
asm, asm_meta = GPUCompiler.emit_asm(job, ir; format=LLVM.API.LLVMAssemblyFile)
105+
asm, meta = GPUCompiler.compile(:asm, job; ctx)
108106

109107
# remove extraneous debug info on lower debug levels
110108
if Base.JLOptions().debug_level < 2
@@ -121,15 +119,15 @@ function compile(@nospecialize(job::CompilerJob), ctx)
121119
end
122120

123121
# check if we'll need the device runtime
124-
undefined_fs = filter(collect(functions(ir))) do f
122+
undefined_fs = filter(collect(functions(meta.ir))) do f
125123
isdeclaration(f) && !LLVM.isintrinsic(f)
126124
end
127125
intrinsic_fns = ["vprintf", "malloc", "free", "__assertfail",
128126
"__nvvm_reflect" #= TODO: should have been optimized away =#]
129127
needs_cudadevrt = !isempty(setdiff(LLVM.name.(undefined_fs), intrinsic_fns))
130128

131129
# find externally-initialized global variables; we'll access those using CUDA APIs.
132-
external_gvars = filter(isextinit, collect(globals(ir))) .|> LLVM.name
130+
external_gvars = filter(isextinit, collect(globals(meta.ir))) .|> LLVM.name
133131

134132
# prepare invocations of CUDA compiler tools
135133
ptxas_opts = String[]
@@ -224,7 +222,7 @@ function compile(@nospecialize(job::CompilerJob), ctx)
224222
rm(ptxas_output)
225223
end
226224

227-
return (image, entry=LLVM.name(ir_meta.entry), external_gvars)
225+
return (image, entry=LLVM.name(meta.entry), external_gvars)
228226
end
229227

230228
# link into an executable kernel

src/compiler/reflection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ See also: [`@device_code_sass`](@ref)
4343
"""
4444
function code_sass(io::IO, @nospecialize(func), @nospecialize(types); kwargs...)
4545
compiler_kwargs, kwargs = split_kwargs_runtime(kwargs, COMPILER_KWARGS)
46-
source = FunctionSpec(typeof(func), Base.to_tuple_type(types))
46+
source = methodinstance(typeof(func), Base.to_tuple_type(types))
4747
config = compiler_config(device(); compiler_kwargs...)
4848
job = CompilerJob(source, config)
4949
code_sass(io, job; kwargs...)
@@ -138,7 +138,7 @@ for method in (:code_typed, :code_warntype, :code_llvm, :code_native)
138138
function $method(io::IO, @nospecialize(func), @nospecialize(types);
139139
kernel=false, kwargs...)
140140
compiler_kwargs, kwargs = split_kwargs_runtime(kwargs, COMPILER_KWARGS)
141-
source = FunctionSpec(typeof(func), Base.to_tuple_type(types))
141+
source = methodinstance(typeof(func), Base.to_tuple_type(types))
142142
config = compiler_config(device(); kernel, compiler_kwargs...)
143143
job = CompilerJob(source, config)
144144
GPUCompiler.$method($(args...); kwargs...)
@@ -156,7 +156,7 @@ const code_ptx = code_native
156156
Return a type `r` such that `f(args...)::r` where `args::tt`.
157157
"""
158158
function return_type(@nospecialize(func), @nospecialize(tt))
159-
source = FunctionSpec(typeof(func), tt)
159+
source = methodinstance(typeof(func), tt)
160160
config = compiler_config(device())
161161
job = CompilerJob(source, config)
162162
interp = GPUCompiler.get_interpreter(job)

src/device/intrinsics/assertion.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ assert_counter = 0
4949
mod = LLVM.parent(llvm_f)
5050

5151
# generate IR
52-
@dispose builder=Builder(ctx) begin
52+
@dispose builder=IRBuilder(ctx) begin
5353
entry = BasicBlock(llvm_f, "entry"; ctx)
5454
position!(builder, entry)
5555

@@ -66,9 +66,9 @@ assert_counter = 0
6666
# NOTE: we don't mark noreturn since that control flow might confuse ptxas
6767
assertfail_typ =
6868
LLVM.FunctionType(T_void,
69-
[T_pint8, T_pint8, T_int32, T_pint8, llvmtype(charSize)])
69+
[T_pint8, T_pint8, T_int32, T_pint8, value_type(charSize)])
7070
assertfail = LLVM.Function(mod, "__assertfail", assertfail_typ)
71-
call!(builder, assertfail, [message, file, line, func, charSize])
71+
call!(builder, assertfail_typ, assertfail, [message, file, line, func, charSize])
7272

7373
ret!(builder)
7474
end

src/device/intrinsics/atomics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const atomic_acquire_release = LLVM.API.LLVMAtomicOrderingAcquireRelease
3434

3535
llvm_f, _ = create_function(T_val, [T_ptr, T_val])
3636

37-
@dispose builder=Builder(ctx) begin
37+
@dispose builder=IRBuilder(ctx) begin
3838
entry = BasicBlock(llvm_f, "entry"; ctx)
3939
position!(builder, entry)
4040

@@ -116,7 +116,7 @@ end
116116

117117
llvm_f, _ = create_function(T_val, [T_ptr, T_val, T_val])
118118

119-
@dispose builder=Builder(ctx) begin
119+
@dispose builder=IRBuilder(ctx) begin
120120
entry = BasicBlock(llvm_f, "entry"; ctx)
121121
position!(builder, entry)
122122

src/device/intrinsics/indexing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ export
1212
mod = LLVM.parent(llvm_f)
1313

1414
# generate IR
15-
@dispose builder=Builder(ctx) begin
15+
@dispose builder=IRBuilder(ctx) begin
1616
entry = BasicBlock(llvm_f, "entry"; ctx)
1717
position!(builder, entry)
1818

1919
# call the indexing intrinsic
2020
intr_typ = LLVM.FunctionType(T_int32)
2121
intr = LLVM.Function(mod, "llvm.nvvm.read.ptx.sreg.$name", intr_typ)
22-
idx = call!(builder, intr)
22+
idx = call!(builder, intr_typ, intr)
2323

2424
# attach range metadata
2525
range_metadata = MDNode([ConstantInt(Int32(range.start); ctx),

src/device/intrinsics/memory_dynamic.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export malloc
1414

1515
# get the intrinsic
1616
# NOTE: LLVM doesn't have void*, Clang uses i8* for malloc too
17-
intr = LLVM.Function(mod, "malloc", LLVM.FunctionType(T_pint8, [T_size]))
17+
intr_typ = LLVM.FunctionType(T_pint8, [T_size])
18+
intr = LLVM.Function(mod, "malloc", intr_typ)
1819
# should we attach some metadata here? julia.gc_alloc_obj has the following:
1920
#let attrs = function_attributes(intr)
2021
# AllocSizeNumElemsNotPresent = reinterpret(Cuint, Cint(-1))
@@ -27,11 +28,11 @@ export malloc
2728
#end
2829

2930
# generate IR
30-
@dispose builder=Builder(ctx) begin
31+
@dispose builder=IRBuilder(ctx) begin
3132
entry = BasicBlock(llvm_f, "entry"; ctx)
3233
position!(builder, entry)
3334

34-
ptr = call!(builder, intr, [parameters(llvm_f)[1]])
35+
ptr = call!(builder, intr_typ, intr, [parameters(llvm_f)[1]])
3536

3637
jlptr = ptrtoint!(builder, ptr, T_ptr)
3738

src/device/intrinsics/memory_shared.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ dynamic_smem_size() =
121121
alignment!(gv, align)
122122

123123
# generate IR
124-
@dispose builder=Builder(ctx) begin
124+
@dispose builder=IRBuilder(ctx) begin
125125
entry = BasicBlock(llvm_f, "entry"; ctx)
126126
position!(builder, entry)
127127

128-
ptr = gep!(builder, gv, [ConstantInt(0; ctx), ConstantInt(0; ctx)])
128+
ptr = gep!(builder, gv_typ, gv, [ConstantInt(0; ctx), ConstantInt(0; ctx)])
129129

130130
untyped_ptr = bitcast!(builder, ptr, T_ptr)
131131

src/device/intrinsics/output.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ end
4646

4747
# create functions
4848
param_types = LLVMType[convert(LLVMType, typ; ctx) for typ in arg_types]
49-
llvm_f, _ = create_function(T_int32, param_types)
49+
llvm_f, llvm_ft = create_function(T_int32, param_types)
5050
mod = LLVM.parent(llvm_f)
5151

5252
# generate IR
53-
@dispose builder=Builder(ctx) begin
53+
@dispose builder=IRBuilder(ctx) begin
5454
entry = BasicBlock(llvm_f, "entry"; ctx)
5555
position!(builder, entry)
5656

@@ -65,7 +65,7 @@ end
6565

6666
args = alloca!(builder, argtypes)
6767
for (i, param) in enumerate(parameters(llvm_f))
68-
p = struct_gep!(builder, args, i-1)
68+
p = struct_gep!(builder, argtypes, args, i-1)
6969
store!(builder, param, p)
7070
end
7171

@@ -75,7 +75,7 @@ end
7575
# invoke vprintf and return
7676
vprintf_typ = LLVM.FunctionType(T_int32, [T_pint8, T_pint8])
7777
vprintf = LLVM.Function(mod, "vprintf", vprintf_typ)
78-
chars = call!(builder, vprintf, [str, buffer])
78+
chars = call!(builder, vprintf_typ, vprintf, [str, buffer])
7979

8080
ret!(builder, chars)
8181
end

0 commit comments

Comments
 (0)