Skip to content

Commit

Permalink
Merge pull request #631 from JuliaGPU/tb/nightly
Browse files Browse the repository at this point in the history
Re-enable nightly testing.
  • Loading branch information
maleadt committed Sep 17, 2024
2 parents d6fde40 + 6540a44 commit 4d9b27f
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 122 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['1.10', 'pre'] # 'nightly'
version: ['1.10', 'pre', 'nightly']
os: [ubuntu-latest, macOS-latest, windows-latest]
arch: [x64]
llvm_args: ['']
include:
# starting with Julia 1.10, we can enable opaque pointers
# from Juila 1.12 on, this is the default.
- version: '1.10'
os: 'ubuntu-latest'
arch: 'x64'
Expand All @@ -48,18 +49,6 @@ jobs:
os: 'windows-latest'
arch: 'x64'
llvm_args: '--opaque-pointers'
#- version: 'nightly'
# os: 'ubuntu-latest'
# arch: 'x64'
# llvm_args: '--opaque-pointers'
#- version: 'nightly'
# os: 'macOS-latest'
# arch: 'x64'
# llvm_args: '--opaque-pointers'
#- version: 'nightly'
# os: 'windows-latest'
# arch: 'x64'
# llvm_args: '--opaque-pointers'
steps:
- uses: actions/checkout@v4

Expand Down
6 changes: 5 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ method_table(@nospecialize(job::CompilerJob)) = GLOBAL_METHOD_TABLE

# the inference parameters to use when constructing the GPUInterpreter
function inference_params(@nospecialize(job::CompilerJob))
return CC.InferenceParams(; unoptimize_throw_blocks=false)
if VERSION >= v"1.12.0-DEV.1017"
CC.InferenceParams()
else
CC.InferenceParams(; unoptimize_throw_blocks=false)
end
end

# the optimization parameters to use when constructing the GPUInterpreter
Expand Down
10 changes: 10 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ end
# XXX: it's not allowed to switch tasks while under this lock, can we guarantee that?
# its probably easier to start using our own LLVM context when that's possible.
macro locked(ex)
if VERSION >= v"1.12.0-DEV.769"
# no need to handle locking; it's taken care of by the engine
# as long as we use a correct cache owner token.
return esc(ex)
end

def = splitdef(ex)
def[:body] = quote
ccall(:jl_typeinf_lock_begin, Cvoid, ())
Expand All @@ -109,6 +115,10 @@ end

# HACK: temporarily unlock again to perform a task switch
macro unlocked(ex)
if VERSION >= v"1.12.0-DEV.769"
return esc(ex)
end

def = splitdef(ex)
def[:body] = quote
ccall(:jl_typeinf_lock_end, Cvoid, ())
Expand Down
12 changes: 12 additions & 0 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ function check_ir!(job, errors::Vector{IRError}, inst::LLVM.CallInst)
@safe_debug "Decoding arguments to jl_get_binding_or_error failed" inst bb=LLVM.parent(inst)
push!(errors, (DELAYED_BINDING, bt, nothing))
end
elseif fn == "jl_reresolve_binding_value_seqcst" || fn == "ijl_reresolve_binding_value_seqcst"
try
# pry the binding from the IR
expr = arguments(inst)[1]::ConstantExpr
expr = first(operands(expr))::ConstantInt # get rid of inttoptr
ptr = Ptr{Any}(convert(Int, expr))
obj = Base.unsafe_pointer_to_objref(ptr)
push!(errors, (DELAYED_BINDING, bt, obj.globalref))
catch e
@safe_debug "Decoding arguments to jl_reresolve_binding_value_seqcst failed" inst bb=LLVM.parent(inst)
push!(errors, (DELAYED_BINDING, bt, nothing))
end
elseif fn == "jl_invoke" || fn == "ijl_invoke"
try
f, args, nargs, meth = arguments(inst)
Expand Down
53 changes: 30 additions & 23 deletions test/gcn_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,44 +74,51 @@ end
# bug: depending on a child function from multiple parents resulted in
# the child only being present once

@noinline child(i) = sink_gcn(i)
function parent1(i)
child(i)
return
mod = @eval module $(gensym())
export child, parent1, parent2

@noinline child(i) = sink_gcn(i)
function parent1(i)
child(i)
return
end
function parent2(i)
child(i+1)
return
end
end

asm = sprint(io->GCN.code_native(io, parent1, Tuple{Int}; dump_module=true))
asm = sprint(io->GCN.code_native(io, mod.parent1, Tuple{Int}; dump_module=true))
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child_\d*,@function", asm)

function parent2(i)
child(i+1)
return
end

asm = sprint(io->GCN.code_native(io, parent2, Tuple{Int}; dump_module=true))
asm = sprint(io->GCN.code_native(io, mod.parent2, Tuple{Int}; dump_module=true))
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child_\d*,@function", asm)
end

@testset "child function reuse bis" begin
# bug: similar, but slightly different issue as above
# in the case of two child functions
@noinline child1(i) = sink_gcn(i)
@noinline child2(i) = sink_gcn(i+1)
function parent1(i)
child1(i) + child2(i)
return

mod = @eval module $(gensym())
export parent1, parent2, child1, child2

@noinline child1(i) = sink_gcn(i)
@noinline child2(i) = sink_gcn(i+1)
function parent1(i)
child1(i) + child2(i)
return
end
function parent2(i)
child1(i+1) + child2(i+1)
return
end
end

asm = sprint(io->GCN.code_native(io, parent1, Tuple{Int}; dump_module=true))
asm = sprint(io->GCN.code_native(io, mod.parent1, Tuple{Int}; dump_module=true))
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child1_\d*,@function", asm)
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child2_\d*,@function", asm)

function parent2(i)
child1(i+1) + child2(i+1)
return
end

asm = sprint(io->GCN.code_native(io, parent2, Tuple{Int}; dump_module=true))
asm = sprint(io->GCN.code_native(io, mod.parent2, Tuple{Int}; dump_module=true))
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child1_\d*,@function", asm)
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child2_\d*,@function", asm)
end
Expand Down
46 changes: 32 additions & 14 deletions test/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,46 +388,61 @@ Base.unsafe_trunc(::Type{Int}, x::CleverType) = unsafe_trunc(Int, x.x)
end

@testset "invalid LLVM IR" begin
foobar(i) = println(i)
mod = @eval module $(gensym())
export foobar
foobar(i) = println(i)
end

@test_throws_message(InvalidIRError,
Native.code_execution(foobar, Tuple{Int})) do msg
Native.code_execution(mod.foobar, Tuple{Int})) do msg
occursin("invalid LLVM IR", msg) &&
(occursin(GPUCompiler.RUNTIME_FUNCTION, msg) ||
occursin(GPUCompiler.UNKNOWN_FUNCTION, msg) ||
occursin(GPUCompiler.DYNAMIC_CALL, msg)) &&
occursin("[1] println", msg) &&
occursin(r"\[2\] .*foobar", msg)
occursin("[2] foobar", msg)
end
end

@testset "invalid LLVM IR (ccall)" begin
foobar(p) = (unsafe_store!(p, ccall(:time, Cint, ())); nothing)
mod = @eval module $(gensym())
export foobar
function foobar(p)
unsafe_store!(p, ccall(:time, Cint, ()))
return
end
end

@test_throws_message(InvalidIRError,
Native.code_execution(foobar, Tuple{Ptr{Int}})) do msg
Native.code_execution(mod.foobar, Tuple{Ptr{Int}})) do msg
if VERSION >= v"1.11-"
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.LAZY_FUNCTION, msg) &&
occursin("call to time", msg) &&
occursin(r"\[1\] .*foobar", msg)
occursin("[1] foobar", msg)
else
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.POINTER_FUNCTION, msg) &&
occursin(r"\[1\] .*foobar", msg)
occursin("[1] foobar", msg)
end
end
end

@testset "delayed bindings" begin
kernel() = (undefined; return)
mod = @eval module $(gensym())
export kernel
function kernel()
undefined
return
end
end

@test_throws_message(InvalidIRError,
Native.code_execution(kernel, Tuple{})) do msg
Native.code_execution(mod.kernel, Tuple{})) do msg
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.DELAYED_BINDING, msg) &&
occursin("use of 'undefined'", msg) &&
occursin(r"\[1\] .*kernel", msg)
occursin(r"use of '.*undefined'", msg) &&
occursin("[1] kernel", msg)
end
end

Expand All @@ -442,15 +457,18 @@ end
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.DYNAMIC_CALL, msg) &&
occursin("call to nospecialize_child", msg) &&
occursin(r"\[1\] kernel", msg)
occursin("[1] kernel", msg)
end
end

@testset "dynamic call (apply)" begin
func() = println(1)
mod = @eval module $(gensym())
export func
func() = println(1)
end

@test_throws_message(InvalidIRError,
Native.code_execution(func, Tuple{})) do msg
Native.code_execution(mod.func, Tuple{})) do msg
occursin("invalid LLVM IR", msg) &&
occursin(GPUCompiler.DYNAMIC_CALL, msg) &&
occursin("call to println", msg) &&
Expand Down
Loading

0 comments on commit 4d9b27f

Please sign in to comment.