Skip to content

Commit 0034adc

Browse files
authored
Upgrade to GPUCompiler v0.19 (#113)
1 parent 84e1b90 commit 0034adc

12 files changed

Lines changed: 76 additions & 59 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
- x64
2828
group:
2929
- Core
30+
include:
31+
- arch: x86
32+
version: '1'
33+
os: ubuntu-latest
3034
steps:
3135
- uses: actions/checkout@v2
3236
- uses: julia-actions/setup-julia@latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
/test/test.*
88
Manifest.toml
99

10+
*.wasm
11+
*.dll
12+
*.o
13+
*.so
1014
test.o
1115
test.so
1216
test.bc

Project.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
88
CodeInfoTools = "bc773b8a-8374-437a-b9f2-0e9785855863"
99
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
1010
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
11+
LLD_jll = "d55e3150-da41-5e91-b323-ecfd1eec6109"
1112
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
1213
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1314
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
@@ -16,10 +17,10 @@ StaticTools = "86c06d3c-3f03-46de-9781-57580aa96d0a"
1617

1718
[compat]
1819
CodeInfoTools = "0.3"
19-
GPUCompiler = "0.17"
20-
LLVM = "4.8, 5"
21-
StaticTools = "0.8"
20+
GPUCompiler = "0.19"
21+
LLVM = "5"
2222
MacroTools = "0.5"
23+
StaticTools = "0.8"
2324
julia = "1.8, 1.9"
2425

2526
[extras]

src/StaticCompiler.jl

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include("code_loading.jl")
2323
include("optimize.jl")
2424
include("quirks.jl")
2525

26+
fix_name(s) = string("julia_", GPUCompiler.safe_name(s))
2627

2728
"""
2829
compile(f, types, path::String = tempname()) --> (compiled_f, path)
@@ -91,12 +92,13 @@ single method (the method determined by `types`).
9192
"""
9293
function compile(f, _tt, path::String = tempname();
9394
mixtape = NoContext(),
94-
name = GPUCompiler.safe_name(repr(f)),
95+
name = fix_name(repr(f)),
9596
filename = "obj",
9697
strip_llvm = false,
9798
strip_asm = true,
9899
opt_level=3,
99100
kwargs...)
101+
100102
tt = Base.to_tuple_type(_tt)
101103
isconcretetype(tt) || error("input type signature $_tt is not concrete")
102104

@@ -114,7 +116,7 @@ end
114116

115117
"""
116118
```julia
117-
generate_obj(f, tt, path::String = tempname(), name = GPUCompiler.safe_name(repr(f)), filenamebase::String="obj";
119+
generate_obj(f, tt, path::String = tempname(), name = fix_name(repr(f)), filenamebase::String="obj";
118120
\tmixtape = NoContext(),
119121
\tstrip_llvm = false,
120122
\tstrip_asm = true,
@@ -148,7 +150,7 @@ shell> tree \$path
148150
0 directories, 1 file
149151
```
150152
"""
151-
function generate_obj(f, tt, external = true, path::String = tempname(), name = GPUCompiler.safe_name(repr(f)), filenamebase::String="obj";
153+
function generate_obj(f, tt, external = true, path::String = tempname(), name = fix_name(repr(f)), filenamebase::String="obj";
152154
mixtape = NoContext(),
153155
strip_llvm = false,
154156
strip_asm = true,
@@ -158,12 +160,9 @@ function generate_obj(f, tt, external = true, path::String = tempname(), name =
158160
mkpath(path)
159161
obj_path = joinpath(path, "$filenamebase.o")
160162
#Get LLVM to generated a module of code for us. We don't want GPUCompiler's optimization passes.
161-
job = CompilerJob(NativeCompilerTarget(target...),
162-
FunctionSpec(f, tt, false, name),
163-
StaticCompilerParams(;
164-
opt = true,
165-
mixtape = mixtape,
166-
optlevel = Base.JLOptions().opt_level))
163+
params = StaticCompilerParams(opt = true, mixtape = mixtape, optlevel = Base.JLOptions().opt_level)
164+
config = GPUCompiler.CompilerConfig(NativeCompilerTarget(target...), params, name = name, kernel = false)
165+
job = GPUCompiler.CompilerJob(GPUCompiler.methodinstance(typeof(f), tt), config)
167166

168167
mod, meta = GPUCompiler.JuliaContext() do context
169168
GPUCompiler.codegen(:llvm, job; strip=strip_llvm, only_entry=false, validate=false, optimize=false, ctx=context)
@@ -259,7 +258,7 @@ shell> ./hello
259258
Hello, world!
260259
```
261260
"""
262-
function compile_executable(f::Function, types=(), path::String="./", name=GPUCompiler.safe_name(repr(f));
261+
function compile_executable(f::Function, types=(), path::String="./", name=fix_name(repr(f));
263262
filename=name,
264263
cflags=``,
265264
kwargs...
@@ -315,7 +314,7 @@ julia> ccall(("julia_test", "test.dylib"), Float64, (Int64,), 100_000)
315314
5.2564961094956075
316315
```
317316
"""
318-
function compile_shlib(f::Function, types=(), path::String="./", name=GPUCompiler.safe_name(repr(f));
317+
function compile_shlib(f::Function, types=(), path::String="./", name=fix_name(repr(f));
319318
filename=name,
320319
cflags=``,
321320
kwargs...
@@ -396,19 +395,19 @@ julia> test(100_000)
396395
function generate_shlib_fptr(path::String, name, filename::String=name)
397396
lib_path = joinpath(abspath(path), "$filename.$(Libdl.dlext)")
398397
ptr = Libdl.dlopen(lib_path, Libdl.RTLD_LOCAL)
399-
fptr = Libdl.dlsym(ptr, "julia_$name")
398+
fptr = Libdl.dlsym(ptr, name)
400399
@assert fptr != C_NULL
401400
fptr
402401
end
403402
# As above, but also compile (maybe remove this method in the future?)
404-
function generate_shlib_fptr(f, tt, path::String=tempname(), name = GPUCompiler.safe_name(repr(f)), filename::String=name;
403+
function generate_shlib_fptr(f, tt, path::String=tempname(), name = fix_name(repr(f)), filename::String=name;
405404
temp::Bool=true,
406405
kwargs...)
407406

408407
generate_shlib(f, tt, false, path, name; kwargs...)
409408
lib_path = joinpath(abspath(path), "$filename.$(Libdl.dlext)")
410409
ptr = Libdl.dlopen(lib_path, Libdl.RTLD_LOCAL)
411-
fptr = Libdl.dlsym(ptr, "julia_$name")
410+
fptr = Libdl.dlsym(ptr, name)
412411
@assert fptr != C_NULL
413412
if temp
414413
atexit(()->rm(path; recursive=true))
@@ -436,7 +435,7 @@ shell> ./hello
436435
Hello, world!
437436
```
438437
"""
439-
function generate_executable(f, tt, path=tempname(), name=GPUCompiler.safe_name(repr(f)), filename=string(name);
438+
function generate_executable(f, tt, path=tempname(), name=fix_name(repr(f)), filename=string(name);
440439
cflags=``,
441440
kwargs...
442441
)
@@ -456,18 +455,18 @@ function generate_executable(f, tt, path=tempname(), name=GPUCompiler.safe_name(
456455
# Compile!
457456
if Sys.isapple()
458457
# Apple no longer uses _start, so we can just specify a custom entry
459-
entry = "_julia_$name"
458+
entry = "_$name"
460459
run(`$cc -e $entry $cflags $obj_path -o $exec_path`)
461460
else
462461
# Write a minimal wrapper to avoid having to specify a custom entry
463462
wrapper_path = joinpath(path, "wrapper.c")
464463
f = open(wrapper_path, "w")
465-
print(f, """int julia_$name(int argc, char** argv);
464+
print(f, """int $name(int argc, char** argv);
466465
void* __stack_chk_guard = (void*) $(rand(UInt) >> 1);
467466
468467
int main(int argc, char** argv)
469468
{
470-
julia_$name(argc, argv);
469+
$name(argc, argv);
471470
return 0;
472471
}""")
473472
close(f)
@@ -517,7 +516,7 @@ julia> ccall(("julia_test", "example/test.dylib"), Float64, (Int64,), 100_000)
517516
5.2564961094956075
518517
```
519518
"""
520-
function generate_shlib(f::Function, tt, external::Bool=true, path::String=tempname(), name=GPUCompiler.safe_name(repr(f)), filename=name;
519+
function generate_shlib(f::Function, tt, external::Bool=true, path::String=tempname(), name=fix_name(repr(f)), filename=name;
521520
cflags=``,
522521
kwargs...
523522
)
@@ -568,15 +567,15 @@ function native_code_typed(@nospecialize(func), @nospecialize(types); kwargs...)
568567
end
569568

570569
# Return an LLVM module
571-
function native_llvm_module(f, tt, name = GPUCompiler.safe_name(repr(f)); kwargs...)
570+
function native_llvm_module(f, tt, name = fix_name(repr(f)); kwargs...)
572571
job, kwargs = native_job(f, tt, true; name, kwargs...)
573572
m, _ = GPUCompiler.JuliaContext() do context
574573
GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, ctx=context)
575574
end
576575
return m
577576
end
578577

579-
function native_code_native(@nospecialize(f), @nospecialize(tt), name = GPUCompiler.safe_name(repr(f)); kwargs...)
578+
function native_code_native(@nospecialize(f), @nospecialize(tt), name = fix_name(repr(f)); kwargs...)
580579
job, kwargs = native_job(f, tt, true; name, kwargs...)
581580
GPUCompiler.code_native(stdout, job; kwargs...)
582581
end
@@ -587,7 +586,7 @@ function native_llvm_module(funcs::Array; demangle = false, kwargs...)
587586
mod = native_llvm_module(f,tt, kwargs...)
588587
if length(funcs) > 1
589588
for func in funcs[2:end]
590-
@show f,tt = func
589+
f,tt = func
591590
tmod = native_llvm_module(f,tt, kwargs...)
592591
link!(mod,tmod)
593592
end
@@ -613,10 +612,10 @@ function generate_obj(funcs::Array, external, path::String = tempname(), filenam
613612
strip_asm = true,
614613
opt_level=3,
615614
kwargs...)
616-
f,tt = funcs[1]
615+
f, tt = funcs[1]
617616
mkpath(path)
618617
obj_path = joinpath(path, "$filenamebase.o")
619-
fakejob, kwargs = native_job(f,tt, external, kwargs...)
618+
fakejob, kwargs = native_job(f, tt, external, kwargs...)
620619
mod = native_llvm_module(funcs; demangle = demangle, kwargs...)
621620
obj, _ = GPUCompiler.emit_asm(fakejob, mod; strip=strip_asm, validate=false, format=LLVM.API.LLVMObjectFile)
622621
open(obj_path, "w") do io

src/code_loading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function instantiate(p::LazyStaticCompiledFunction{rt, tt}) where {rt, tt}
5050
dg = LLVM.CreateDynamicLibrarySearchGeneratorForProcess(prefix)
5151
LLVM.add!(jd, dg)
5252
LLVM.add!(lljit, jd, ofile)
53-
fptr = pointer(LLVM.lookup(lljit, "julia_" * p.name))
53+
fptr = pointer(LLVM.lookup(lljit, p.name))
5454

5555
StaticCompiledFunction{rt, tt}(p.f, fptr, lljit, p.reloc)
5656
end

src/interpreter.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Core.Compiler:
44
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, MethodInstance, OptimizationParams, WorldView
55
using GPUCompiler:
6-
@safe_debug, AbstractCompilerParams, CodeCache, CompilerJob, FunctionSpec
6+
@safe_debug, AbstractCompilerParams, CodeCache, CompilerJob, methodinstance
77
using CodeInfoTools
88
using CodeInfoTools: resolve
99

src/pointer_patching.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function get_pointers!(d, mod, inst)
137137
_, gv = d[val]
138138
LLVM.API.LLVMSetOperand(inst, i-1, gv)
139139
else
140-
gv_name = GPUCompiler.safe_name(String(gensym(repr(Core.Typeof(val)))))
140+
gv_name = fix_name(String(gensym(repr(Core.Typeof(val)))))
141141
gv = LLVM.GlobalVariable(mod, llvmeltype(arg), gv_name, LLVM.addrspace(llvmtype(arg)))
142142

143143
LLVM.extinit!(gv, true)
@@ -157,7 +157,7 @@ llvmeltype(x::LLVM.Value) = eltype(LLVM.llvmtype(x))
157157

158158
function pointer_patching_diff(f, tt, path1=tempname(), path2=tempname(); show_reloc_table=false)
159159
tm = GPUCompiler.llvm_machine(NativeCompilerTarget())
160-
job, kwargs = native_job(f, tt, false; name=GPUCompiler.safe_name(repr(f)))
160+
job, kwargs = native_job(f, tt, false; name=fix_name(repr(f)))
161161
#Get LLVM to generated a module of code for us. We don't want GPUCompiler's optimization passes.
162162
mod, meta = GPUCompiler.JuliaContext() do context
163163
GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, optimize=false, ctx=context)

src/target.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ for target in (:NativeCompilerTarget, :ExternalNativeCompilerTarget)
7272
return tm
7373
end
7474

75-
GPUCompiler.runtime_slug(job::GPUCompiler.CompilerJob{$target}) = "native_$(job.target.cpu)-$(hash(job.target.features))"
75+
GPUCompiler.runtime_slug(job::GPUCompiler.CompilerJob{$target}) = "native_$(job.config.target.cpu)-$(hash(job.config.target.features))"
7676

7777
GPUCompiler.runtime_module(::GPUCompiler.CompilerJob{$target}) = StaticRuntime
7878
GPUCompiler.runtime_module(::GPUCompiler.CompilerJob{$target, StaticCompilerParams}) = StaticRuntime
@@ -82,10 +82,10 @@ for target in (:NativeCompilerTarget, :ExternalNativeCompilerTarget)
8282
GPUCompiler.can_throw(job::GPUCompiler.CompilerJob{$target}) = true
8383

8484
GPUCompiler.get_interpreter(job::GPUCompiler.CompilerJob{$target, StaticCompilerParams}) =
85-
StaticInterpreter(job.params.cache, GPUCompiler.method_table(job), job.source.world,
85+
StaticInterpreter(job.config.params.cache, GPUCompiler.method_table(job), job.world,
8686
GPUCompiler.inference_params(job), GPUCompiler.optimization_params(job),
87-
job.params.mixtape)
88-
GPUCompiler.ci_cache(job::GPUCompiler.CompilerJob{$target, StaticCompilerParams}) = job.params.cache
87+
job.config.params.mixtape)
88+
GPUCompiler.ci_cache(job::GPUCompiler.CompilerJob{$target, StaticCompilerParams}) = job.config.params.cache
8989
end
9090
end
9191

@@ -94,20 +94,22 @@ GPUCompiler.method_table(@nospecialize(job::GPUCompiler.CompilerJob{ExternalNati
9494

9595
function native_job(@nospecialize(func::Function), @nospecialize(types::Type), external::Bool;
9696
mixtape = NoContext(),
97-
name = GPUCompiler.safe_name(repr(func)),
97+
name = fix_name(repr(func)),
9898
kernel::Bool = false,
9999
target = (),
100100
kwargs...
101101
)
102-
source = GPUCompiler.FunctionSpec(func, types, kernel, name)
102+
source = methodinstance(typeof(func), Base.to_tuple_type(types))
103103
target = external ? ExternalNativeCompilerTarget(;target...) : NativeCompilerTarget(;target...)
104104
params = StaticCompilerParams(mixtape = mixtape)
105-
StaticCompiler.CompilerJob(target, source, params), kwargs
105+
config = GPUCompiler.CompilerConfig(target, params, name = name, kernel = kernel)
106+
StaticCompiler.CompilerJob(source, config), kwargs
106107
end
107108

108-
function native_job(@nospecialize(func), @nospecialize(types), external; mixtape = NoContext(), kernel::Bool=false, name=GPUCompiler.safe_name(repr(func)), target = (), kwargs...)
109-
source = GPUCompiler.FunctionSpec(func, Base.to_tuple_type(types), kernel, name)
109+
function native_job(@nospecialize(func), @nospecialize(types), external; mixtape = NoContext(), kernel::Bool=false, name=fix_name(repr(func)), target = (), kwargs...)
110+
source = methodinstance(typeof(func), Base.to_tuple_type(types))
110111
target = external ? ExternalNativeCompilerTarget(;target...) : NativeCompilerTarget(;target...)
111112
params = StaticCompilerParams(mixtape = mixtape)
112-
GPUCompiler.CompilerJob(target, source, params), kwargs
113+
config = GPUCompiler.CompilerConfig(target, params, name = name, kernel = kernel)
114+
GPUCompiler.CompilerJob(source, config), kwargs
113115
end

test/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ CodeInfoTools = "bc773b8a-8374-437a-b9f2-0e9785855863"
33
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
44
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
55
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
6-
Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b"
6+
LLD_jll = "d55e3150-da41-5e91-b323-ecfd1eec6109"
7+
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
78
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9-
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
1010
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
1111
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1212
ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667"
1313
StaticTools = "86c06d3c-3f03-46de-9781-57580aa96d0a"
1414
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
15-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1615
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
16+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using StaticTools
99
using StrideArraysCore
1010
using CodeInfoTools
1111
using MacroTools
12+
using LLD_jll
1213

1314
addprocs(1)
1415
@everywhere using StaticCompiler, StrideArraysCore

0 commit comments

Comments
 (0)