Skip to content

Commit

Permalink
Merge pull request #562 from JuliaGPU/tb/nightly
Browse files Browse the repository at this point in the history
Adapt to upcoming Julia changes
  • Loading branch information
maleadt committed Apr 9, 2024
2 parents 3c1bc65 + 4fca872 commit e9c4404
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['1.8', '1.9', '1.10', '^1.11.0-alpha1'] # 'nightly'
version: ['1.8', '1.9', '1.10', '^1.11.0-alpha2'] # 'nightly'
os: [ubuntu-latest, macOS-latest, windows-latest]
arch: [x64]
llvm_args: ['']
Expand All @@ -36,15 +36,15 @@ jobs:
os: 'windows-latest'
arch: 'x64'
llvm_args: '--opaque-pointers'
- version: '^1.11.0-alpha1'
- version: '^1.11.0-alpha2'
os: 'ubuntu-latest'
arch: 'x64'
llvm_args: '--opaque-pointers'
- version: '^1.11.0-alpha1'
- version: '^1.11.0-alpha2'
os: 'macOS-latest'
arch: 'x64'
llvm_args: '--opaque-pointers'
- version: '^1.11.0-alpha1'
- version: '^1.11.0-alpha2'
os: 'windows-latest'
arch: 'x64'
llvm_args: '--opaque-pointers'
Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ end
ci_cache_token(@nospecialize(job::CompilerJob)) =
GPUCompilerCacheToken(typeof(job.config.target), job.config.always_inline, method_table(job))

# the codeinfo cache to use -- should only be used for the constructor
# the codeinstance cache to use -- should only be used for the constructor
if VERSION >= v"1.11.0-DEV.1552"
# Soft deprecated user should use `CC.code_cache(get_interpreter(job))`
ci_cache(@nospecialize(job::CompilerJob)) = CC.code_cache(get_interpreter(job))
Expand Down
1 change: 1 addition & 0 deletions src/irgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function irgen(@nospecialize(job::CompilerJob))
else
entry_fn = compiled[job.source].func
end
@assert entry_fn !== nothing
entry = functions(mod)[entry_fn]

# clean up incompatibilities
Expand Down
61 changes: 37 additions & 24 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,6 @@ function CC.getindex(wvc::WorldView{CodeCache}, mi::MethodInstance)
end

function CC.setindex!(wvc::WorldView{CodeCache}, ci::CodeInstance, mi::MethodInstance)
src = if ci.inferred isa Vector{UInt8}
ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any),
mi.def, C_NULL, ci.inferred)
else
ci.inferred
end
CC.setindex!(wvc.cache, ci, mi)
end

Expand All @@ -509,25 +503,42 @@ end # HAS_INTEGRATED_CACHE
## codegen/inference integration

function ci_cache_populate(interp, cache, mi, min_world, max_world)
src = CC.typeinf_ext_toplevel(interp, mi)

# inference populates the cache, so we don't need to jl_get_method_inferred
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)

# if src is rettyp_const, the codeinfo won't cache ci.inferred
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
ci = CC.getindex(wvc, mi)
if ci !== nothing && ci.inferred === nothing
@static if VERSION >= v"1.9.0-DEV.1115"
@atomic ci.inferred = src
else
ci.inferred = src
if VERSION >= v"1.12.0-DEV.15"
inferred_ci = CC.typeinf_ext_toplevel(interp, mi, CC.SOURCE_MODE_FORCE_SOURCE) # or SOURCE_MODE_FORCE_SOURCE_UNCACHED?

# inference should have populated our cache
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)
ci = CC.getindex(wvc, mi)

# if ci is rettype_const, the inference result won't have been cached
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
if ci.inferred === nothing
CC.setindex!(wvc, inferred_ci, mi)
ci = CC.getindex(wvc, mi)
end
else
src = CC.typeinf_ext_toplevel(interp, mi)

# inference should have populated our cache
wvc = WorldView(cache, min_world, max_world)
@assert CC.haskey(wvc, mi)
ci = CC.getindex(wvc, mi)

# if ci is rettype_const, the inference result won't have been cached
# (because it is normally not supposed to be used ever again).
# to avoid the need to re-infer, set that field here.
if ci.inferred === nothing
@static if VERSION >= v"1.9.0-DEV.1115"
@atomic ci.inferred = src
else
ci.inferred = src
end
end
end

return ci
return ci::CodeInstance
end

function ci_cache_lookup(cache, mi, min_world, max_world)
Expand Down Expand Up @@ -581,6 +592,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
cache = CC.code_cache(interp)
if ci_cache_lookup(cache, job.source, job.world, job.world) === nothing
ci_cache_populate(interp, cache, job.source, job.world, job.world)
@assert ci_cache_lookup(cache, job.source, job.world, job.world) !== nothing
end

# create a callback to look-up function in our cache,
Expand Down Expand Up @@ -698,9 +710,10 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
ccall(:jl_get_function_id, Nothing,
(Ptr{Cvoid}, Any, Ptr{Int32}, Ptr{Int32}),
native_code, ci, llvm_func_idx, llvm_specfunc_idx)
@assert llvm_func_idx[] != -1 || llvm_specfunc_idx[] != -1 "Static compilation failed"

# get the function
llvm_func = if llvm_func_idx[] >= 1
llvm_func = if llvm_func_idx[] >= 1
llvm_func_ref = ccall(:jl_get_llvm_function, LLVM.API.LLVMValueRef,
(Ptr{Cvoid}, UInt32), native_code, llvm_func_idx[]-1)
@assert llvm_func_ref != C_NULL
Expand All @@ -709,7 +722,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
nothing
end

llvm_specfunc = if llvm_specfunc_idx[] >= 1
llvm_specfunc = if llvm_specfunc_idx[] >= 1
llvm_specfunc_ref = ccall(:jl_get_llvm_function, LLVM.API.LLVMValueRef,
(Ptr{Cvoid}, UInt32), native_code, llvm_specfunc_idx[]-1)
@assert llvm_specfunc_ref != C_NULL
Expand Down
2 changes: 1 addition & 1 deletion test/ptx_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ end
@test occursin(r"@\w*kernel\w*\(\[1 x i64\] %state", ir)

# child1 doesn't use the state
@test occursin(r"@\w*child1\w*\(i64", ir)
@test occursin(r"@\w*child1\w*\((i64|i8\*)", ir)

# child2 does
@test occursin(r"@\w*child2\w*\(\[1 x i64\] %state", ir)
Expand Down

0 comments on commit e9c4404

Please sign in to comment.