Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for nightly #651

Merged
merged 4 commits into from
Nov 28, 2024
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
31 changes: 27 additions & 4 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end

# on 1.11 (JuliaLang/julia#52572, merged as part of JuliaLang/julia#52233) we can use
# Julia's cached method lookup to simply look up method instances at run time.
if VERSION >= v"1.11.0-DEV.1552"
@static if VERSION >= v"1.11.0-DEV.1552"

# XXX: version of Base.method_instance that uses a function type
@inline function methodinstance(@nospecialize(ft::Type), @nospecialize(tt::Type),
Expand Down Expand Up @@ -395,7 +395,7 @@ CC.InferenceParams(interp::GPUInterpreter) = interp.inf_params
CC.OptimizationParams(interp::GPUInterpreter) = interp.opt_params
#=CC.=#get_inference_world(interp::GPUInterpreter) = interp.world
CC.get_inference_cache(interp::GPUInterpreter) = interp.inf_cache
if HAS_INTEGRATED_CACHE
@static if HAS_INTEGRATED_CACHE
CC.cache_owner(interp::GPUInterpreter) = interp.token
else
CC.code_cache(interp::GPUInterpreter) = WorldView(interp.code_cache, interp.world)
Expand All @@ -412,7 +412,9 @@ end
CC.may_optimize(interp::GPUInterpreter) = true
CC.may_compress(interp::GPUInterpreter) = true
CC.may_discard_trees(interp::GPUInterpreter) = true
@static if VERSION <= v"1.12.0-DEV.1531"
CC.verbose_stmt_info(interp::GPUInterpreter) = false
end
CC.method_table(interp::GPUInterpreter) = interp.method_table

# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)
Expand Down Expand Up @@ -615,9 +617,11 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
prefer_specsig = true,
gnu_pubnames = false,
debug_info_kind = Cint(debug_info_kind),
lookup = Base.unsafe_convert(Ptr{Nothing}, lookup_cb),
safepoint_on_entry = can_safepoint(job),
gcstack_arg = false)
if VERSION < v"1.12.0-DEV.1667"
cgparams = (; lookup = Base.unsafe_convert(Ptr{Nothing}, lookup_cb), cgparams... )
end
params = Base.CodegenParams(; cgparams...)

# generate IR
Expand All @@ -635,9 +639,15 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
Metadata(ConstantInt(DEBUG_METADATA_VERSION()))
end

native_code = ccall(:jl_create_native, Ptr{Cvoid},
native_code = if VERSION >= v"1.12.0-DEV.1667"
ccall(:jl_create_native, Ptr{Cvoid},
(Vector{MethodInstance}, LLVM.API.LLVMOrcThreadSafeModuleRef, Ptr{Base.CodegenParams}, Cint, Cint, Cint, Csize_t, Ptr{Cvoid}),
[job.source], ts_mod, Ref(params), CompilationPolicyExtern, #=imaging mode=# 0, #=external linkage=# 0, job.world, Base.unsafe_convert(Ptr{Nothing}, lookup_cb))
else
ccall(:jl_create_native, Ptr{Cvoid},
(Vector{MethodInstance}, LLVM.API.LLVMOrcThreadSafeModuleRef, Ptr{Base.CodegenParams}, Cint, Cint, Cint, Csize_t),
[job.source], ts_mod, Ref(params), CompilationPolicyExtern, #=imaging mode=# 0, #=external linkage=# 0, job.world)
end
@assert native_code != C_NULL

llvm_mod_ref =
Expand All @@ -658,6 +668,19 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
cache_gbl = nothing
end

if VERSION >= v"1.12.0-DEV.1703"
# on sufficiently recent versions of Julia, we can query the MIs compiled.
# this is required after the move to `invokce(::CodeInstance)`, because our
# lookup function (used to populate method_instances) isn't always called then.

num_mis = Ref{Csize_t}(0)
@ccall jl_get_llvm_mis(native_code::Ptr{Cvoid}, num_mis::Ptr{Csize_t},
C_NULL::Ptr{Cvoid})::Nothing
resize!(method_instances, num_mis[])
@ccall jl_get_llvm_mis(native_code::Ptr{Cvoid}, num_mis::Ptr{Csize_t},
method_instances::Ptr{Cvoid})::Nothing
end

# process all compiled method instances
compiled = Dict()
for mi in method_instances
Expand Down
4 changes: 2 additions & 2 deletions test/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ end
Native.code_execution(mod.func, Tuple{})) do msg
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.DYNAMIC_CALL, msg) &&
occursin("call to println", msg) &&
occursin("call to print", msg) &&
occursin("[2] func", msg)
end
end
Expand Down Expand Up @@ -604,7 +604,7 @@ precompile_test_harness("Inference caching") do load_path
@test check_presence(kernel_mi, token)

# check that identity survived
@test check_presence(identity_mi, token)
@test check_presence(identity_mi, token) broken=VERSION>=v"1.12.0-DEV.1268"

GPUCompiler.clear_disk_cache!()
@test GPUCompiler.disk_cache_enabled() == false
Expand Down
2 changes: 1 addition & 1 deletion test/ptx_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ precompile_test_harness("Inference caching") do load_path
@test check_presence(kernel_mi, token)

# check that identity survived
@test check_presence(identity_mi, token)
@test check_presence(identity_mi, token) broken=VERSION>=v"1.12.0-DEV.1268"
end
end

Expand Down
Loading