Skip to content

Commit 7e36691

Browse files
VarLadkylincasterkylincaster
authored
Support for julia 1.12 (tshort#181)
* update to julia1.11 and GPUCompiler 1.5.2 * update Project.toml * pass the test for julia 1.8~1.11 in ubuntu * update the version to 0.7.3 * update for GPUCompiler by removing the deprecated API * initial 1.12 support * address reviews * re-enable Bumper tests, comment printdlm * revert printf * use 1.11 and 1.12 in ci * mark loopvec tests as broken * address comments * comment printdlm again --------- Co-authored-by: kylin <[email protected]> Co-authored-by: kylincaster <[email protected]>
1 parent 683e919 commit 7e36691

File tree

15 files changed

+126
-174
lines changed

15 files changed

+126
-174
lines changed

.github/workflows/ci-integration.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.8'
22-
- '1.9'
23-
- '1.10.0-rc1'
21+
- '1.11'
22+
- '1.12'
2423
os:
2524
- ubuntu-latest
2625
- macOS-latest

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.8'
22-
- '1.9'
23-
- '1.10'
21+
- '1.11'
22+
- '1.12'
2423
os:
2524
- ubuntu-latest
2625
- macOS-latest

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StaticCompiler"
22
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
33
authors = ["Tom Short and contributors"]
4-
version = "0.7.2"
4+
version = "0.7.3"
55

66

77
[deps]
@@ -18,11 +18,11 @@ StaticTools = "86c06d3c-3f03-46de-9781-57580aa96d0a"
1818

1919
[compat]
2020
CodeInfoTools = "0.3"
21-
GPUCompiler = "0.21, 0.22, 0.23, 0.24, 0.25, 0.26"
22-
LLVM = "6"
21+
GPUCompiler = "1.3"
22+
LLVM = "9"
2323
MacroTools = "0.5"
2424
StaticTools = "0.8"
25-
julia = "1.8, 1.9"
25+
julia = "1.11"
2626

2727
[extras]
2828
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"

src/StaticCompiler.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export static_code_llvm, static_code_typed, static_llvm_module, static_code_nati
1919
export @device_override, @print_and_throw
2020
export StaticTarget
2121

22+
include("quirks.jl")
2223
include("interpreter.jl")
2324
include("target.jl")
2425
include("pointer_warning.jl")
25-
include("quirks.jl")
2626
include("dllexport.jl")
2727

2828
fix_name(f::Function) = fix_name(string(nameof(f)))
@@ -450,9 +450,9 @@ function static_llvm_module(f, tt, name=fix_name(f); demangle=true, target::Stat
450450
if !demangle
451451
name = "julia_"*name
452452
end
453-
job, kwargs = static_job(f, tt; name, target, kwargs...)
453+
job, kwargs = static_job(f, tt; name, target, strip=true, only_entry=false, validate=false, libraries=false, kwargs...)
454454
m = GPUCompiler.JuliaContext() do context
455-
m, _ = GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, libraries=false)
455+
m, _ = GPUCompiler.compile(:llvm, job; kwargs...)
456456
locate_pointers_and_runtime_calls(m)
457457
m
458458
end
@@ -467,17 +467,17 @@ function static_llvm_module(funcs::Union{Array,Tuple}; demangle=true, target::St
467467
if !demangle
468468
name_f = "julia_"*name_f
469469
end
470-
job, kwargs = static_job(f, tt; name = name_f, target, kwargs...)
471-
mod,_ = GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, libraries=false)
470+
job, kwargs = static_job(f, tt; name = name_f, target, strip=true, only_entry=false, validate=false, libraries=false, kwargs...)
471+
mod,_ = GPUCompiler.compile(:llvm, job; kwargs...)
472472
if length(funcs) > 1
473473
for func in funcs[2:end]
474474
f,tt = func
475475
name_f = fix_name(f)
476476
if !demangle
477477
name_f = "julia_"*name_f
478478
end
479-
job, kwargs = static_job(f, tt; name = name_f, target, kwargs...)
480-
tmod,_ = GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false, libraries=false)
479+
job, kwargs = static_job(f, tt; name = name_f, target, strip=true, only_entry=false, validate=false, libraries=false, kwargs...)
480+
tmod,_ = GPUCompiler.compile(:llvm, job; kwargs...)
481481
link!(mod,tmod)
482482
end
483483
end
@@ -493,9 +493,10 @@ function static_llvm_module(funcs::Union{Array,Tuple}; demangle=true, target::St
493493
name!(modfunc,fname[d:end])
494494
end
495495
end
496-
LLVM.ModulePassManager() do pass_manager #remove duplicate functions
497-
LLVM.merge_functions!(pass_manager)
498-
LLVM.run!(pass_manager, mod)
496+
@dispose pb = NewPMPassBuilder(merge_functions=true) begin
497+
add!(pb, NewPMModulePassManager()) do pass_manager
498+
run!(pb, mod)
499+
end
499500
end
500501
return mod
501502
end
@@ -529,7 +530,7 @@ The defaults compile to the native target.
529530
If `demangle` is set to `false`, compiled function names are prepended with "julia_".
530531
531532
### Examples
532-
```julia
533+
```
533534
julia> fib(n) = n <= 1 ? n : fib(n - 1) + fib(n - 2)
534535
fib (generic function with 1 method)
535536
@@ -587,8 +588,8 @@ function generate_obj(funcs::Union{Array,Tuple}, path::String = tempname(), file
587588
obj_path = joinpath(path, "$filenamebase.o")
588589
obj = GPUCompiler.JuliaContext() do ctx
589590
fakejob, _ = static_job(f, tt; target, kwargs...)
590-
obj, _ = GPUCompiler.emit_asm(fakejob, mod; strip=strip_asm, validate=false, format=LLVM.API.LLVMObjectFile)
591-
obj
591+
obj, _ = GPUCompiler.emit_asm(fakejob, mod, LLVM.API.LLVMObjectFile)
592+
obj
592593
end
593594
open(obj_path, "w") do io
594595
write(io, obj)

src/interpreter.jl

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,47 @@
11
## interpreter
22

33
using Core.Compiler:
4-
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, MethodInstance, OptimizationParams, WorldView, get_world_counter
4+
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, MethodInstance, OptimizationParams, WorldView
55
using GPUCompiler:
6-
@safe_debug, AbstractCompilerParams, CodeCache, CompilerJob, methodinstance
6+
@safe_debug, AbstractCompilerParams, CompilerJob, methodinstance, CodeInstance, inference_params, optimization_params, get_inference_world
77
using CodeInfoTools
88
using CodeInfoTools: resolve
99

10+
1011
struct StaticInterpreter <: AbstractInterpreter
11-
global_cache::CodeCache
12+
# The world age we're working inside of
13+
world::UInt
1214
method_table::Union{Nothing,Core.MethodTable}
1315

16+
token::Any
17+
1418
# Cache of inference results for this particular interpreter
1519
local_cache::Vector{InferenceResult}
16-
# The world age we're working inside of
17-
world::UInt
1820

1921
# Parameters for inference and optimization
2022
inf_params::InferenceParams
2123
opt_params::OptimizationParams
22-
23-
function StaticInterpreter(cache::CodeCache, mt::Union{Nothing,Core.MethodTable}, world::UInt, ip::InferenceParams, op::OptimizationParams)
24+
function StaticInterpreter(world::UInt, mt::Union{Nothing,Core.MethodTable}, token_or_cache, ip::InferenceParams, op::OptimizationParams)
2425
@assert world <= Base.get_world_counter()
25-
26-
return new(
27-
cache,
28-
mt,
29-
30-
# Initially empty cache
31-
Vector{InferenceResult}(),
32-
33-
# world age counter
34-
world,
35-
36-
# parameters for inference and optimization
37-
ip,
38-
op
39-
)
26+
local_cache = Vector{Core.Compiler.InferenceResult}() # Initially empty cache
27+
return new(world, mt, token_or_cache, local_cache, ip, op)
4028
end
4129
end
4230

43-
4431
Core.Compiler.InferenceParams(interp::StaticInterpreter) = interp.inf_params
4532
Core.Compiler.OptimizationParams(interp::StaticInterpreter) = interp.opt_params
46-
Core.Compiler.get_world_counter(interp::StaticInterpreter) = interp.world
33+
GPUCompiler.get_inference_world(interp::StaticInterpreter) = interp.world
4734
Core.Compiler.get_inference_cache(interp::StaticInterpreter) = interp.local_cache
48-
Core.Compiler.code_cache(interp::StaticInterpreter) = WorldView(interp.global_cache, interp.world)
35+
Core.Compiler.cache_owner(interp::StaticInterpreter) = interp.token
4936

5037
# No need to do any locking since we're not putting our results into the runtime cache
5138
Core.Compiler.lock_mi_inference(interp::StaticInterpreter, mi::MethodInstance) = nothing
5239
Core.Compiler.unlock_mi_inference(interp::StaticInterpreter, mi::MethodInstance) = nothing
5340

5441
function Core.Compiler.add_remark!(interp::StaticInterpreter, sv::InferenceState, msg)
55-
@safe_debug "Inference remark during static compilation of $(sv.linfo): $msg"
42+
@safe_debug "Inference remark during static compilation of $(sv.linfo): $msg"
5643
end
5744

58-
5945
#####
6046
##### Pre-inference
6147
#####
@@ -77,58 +63,46 @@ function custom_pass!(interp::StaticInterpreter, result::InferenceResult, mi::Co
7763
end
7864

7965
function Core.Compiler.InferenceState(result::InferenceResult, cache::Symbol, interp::StaticInterpreter)
80-
world = get_world_counter(interp)
81-
src = @static if VERSION >= v"1.10.0-DEV.873"
82-
Core.Compiler.retrieve_code_info(result.linfo, world)
83-
else
84-
Core.Compiler.retrieve_code_info(result.linfo)
85-
end
66+
world = get_inference_world(interp)
67+
src = Core.Compiler.retrieve_code_info(result.linfo, world)
8668
mi = result.linfo
8769
src = custom_pass!(interp, result, mi, src)
88-
src === nothing && return nothing
89-
Core.Compiler.validate_code_in_debug_mode(result.linfo, src, "lowered")
70+
src === nothing && return Core.Compiler.maybe_validate_code(result.linfo, src, "lowered")
9071
return InferenceState(result, src, cache, interp)
9172
end
9273

9374
Core.Compiler.may_optimize(interp::StaticInterpreter) = true
9475
Core.Compiler.may_compress(interp::StaticInterpreter) = true
9576
Core.Compiler.may_discard_trees(interp::StaticInterpreter) = true
96-
Core.Compiler.verbose_stmt_info(interp::StaticInterpreter) = false
97-
77+
if isdefined(Core.Compiler, :verbose_stmt_inf)
78+
Core.Compiler.verbose_stmt_info(interp::StaticInterpreter) = false
79+
end
9880

9981
if isdefined(Base.Experimental, Symbol("@overlay"))
10082
using Core.Compiler: OverlayMethodTable
101-
if v"1.8-beta2" <= VERSION < v"1.9-" || VERSION >= v"1.9.0-DEV.120"
102-
Core.Compiler.method_table(interp::StaticInterpreter) =
103-
OverlayMethodTable(interp.world, interp.method_table)
104-
else
105-
Core.Compiler.method_table(interp::StaticInterpreter, sv::InferenceState) =
83+
Core.Compiler.method_table(interp::StaticInterpreter) =
10684
OverlayMethodTable(interp.world, interp.method_table)
107-
end
10885
else
10986
Core.Compiler.method_table(interp::StaticInterpreter, sv::InferenceState) =
11087
WorldOverlayMethodTable(interp.world)
11188
end
11289

11390
# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)
114-
@static if VERSION >= v"1.9.0-DEV.1248"
11591
function Core.Compiler.concrete_eval_eligible(interp::StaticInterpreter,
11692
@nospecialize(f), result::Core.Compiler.MethodCallResult, arginfo::Core.Compiler.ArgInfo)
11793
ret = @invoke Core.Compiler.concrete_eval_eligible(interp::AbstractInterpreter,
11894
f::Any, result::Core.Compiler.MethodCallResult, arginfo::Core.Compiler.ArgInfo)
11995
ret === false && return nothing
12096
return ret
12197
end
122-
end
12398

12499
struct StaticCompilerParams <: AbstractCompilerParams
125100
opt::Bool
126101
optlevel::Int
127-
cache::CodeCache
128102
end
129103

130-
function StaticCompilerParams(; opt = false,
131-
optlevel = Base.JLOptions().opt_level,
132-
cache = CodeCache())
133-
return StaticCompilerParams(opt, optlevel, cache)
104+
function StaticCompilerParams(; opt=false,
105+
optlevel=Base.JLOptions().opt_level
106+
)
107+
return StaticCompilerParams(opt, optlevel)
134108
end

src/pointer_warning.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ function locate_pointers_and_runtime_calls(mod)
3030
end
3131
end
3232
if warned
33+
lines = split(string(func),"\n")
3334
@warn("LLVM function generated warnings due to raw pointers embedded in the code. This will likely cause errors or undefined behaviour.",
34-
func = func)
35+
func = join(lines[1:min(20, end)], "\n")) # just print the first 20 lines
3536
end
3637
end
3738
end

src/quirks.jl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
libcexit(x::Int32) = @symbolcall exit(x::Int32)::Nothing
1+
@static if isdefined(Base.Experimental, Symbol("@overlay"))
2+
Base.Experimental.@MethodTable(method_table)
3+
Base.Experimental.@MethodTable(empty_table)
4+
else
5+
const method_table = nothing
6+
end
7+
8+
"""
9+
```julia
10+
@device_override old_bad_method(arg1::Type1, arg2::Type2) = new_good_method(arg1, arg2)
11+
```
12+
Override a non-static-compilable method (e.g. `old_bad_method(::Type1, ::Type2)`)
13+
with a more compileable replacement.
14+
### Examples
15+
```
16+
@device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} =
17+
@print_and_throw c"Inexact conversion"
18+
```
19+
"""
20+
macro device_override(ex)
21+
code = quote
22+
$Base.Experimental.@overlay($StaticCompiler.method_table, $ex)
23+
end
24+
return esc(code)
25+
end
26+
227
macro print_and_throw(err)
328
quote
429
println($err)
530
libcexit(Int32(1))
631
end
732
end
33+
libcexit(x::Int32) = @symbolcall exit(x::Int32)::Nothing
834

935
# math.jl
1036
@device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) =
@@ -37,7 +63,6 @@ end
3763
@device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} =
3864
@print_and_throw c"Inexact conversion"
3965

40-
# abstractarray.jl
4166
@device_override @noinline Base.throw_boundserror(A, I) =
4267
@print_and_throw c"Out-of-bounds array access"
4368

0 commit comments

Comments
 (0)