Skip to content

Commit

Permalink
Add generic interface to change codegen params
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Dec 5, 2023
1 parent 21ca075 commit 16fd0e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ get_interpreter(@nospecialize(job::CompilerJob)) =
# if not, calls to throw will be replaced with calls to the GPU runtime
can_throw(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job)

function codegen_params(@nospecialize(job::CompilerJob))
return (;)
end

# does this target support loading from Julia safepoints?
# if not, safepoints at function entry will not be emitted
can_safepoint(@nospecialize(job::CompilerJob)) = uses_julia_runtime(job)
Expand Down
1 change: 1 addition & 0 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
@static if VERSION >= v"1.10.0-DEV.1499"
cgparams = merge(cgparams, (;gcstack_arg = false))
end
cgparams = merge(cgparams, codegen_params(job))
params = Base.CodegenParams(; cgparams...)

# generate IR
Expand Down
12 changes: 12 additions & 0 deletions test/native_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ end
end
end

@static if VERSION > v"1.11.0-DEV.398"
# TODO: teach the verifier to accept ccalls without the plt
@testset "invalid LLVM IR (ccall)" begin
foobar(p) = (unsafe_store!(p, ccall(:time, Cint, ())); nothing)

@test_throws_message(InvalidIRError,
Native.code_execution(foobar, Tuple{Ptr{Int}}), use_jlplt=true) do msg
occursin("Reason: unsupported call to the Julia runtime", msg)
end
end
end

@testset "delayed bindings" begin
kernel() = (undefined; return)

Expand Down
14 changes: 9 additions & 5 deletions test/native_testsetup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ using GPUCompiler

# create a native test compiler, and generate reflection methods for it

include("runtime.jl")
# include("runtime.jl")

# local method table for device functions
Base.Experimental.@MethodTable(test_method_table)

struct CompilerParams <: AbstractCompilerParams
entry_safepoint::Bool
use_jlplt::Bool
method_table

CompilerParams(entry_safepoint::Bool=false, method_table=test_method_table) =
new(entry_safepoint, method_table)
CompilerParams(entry_safepoint::Bool=false, use_jlplt::Bool=true, method_table=test_method_table) =
new(entry_safepoint, use_jlplt, method_table)
end

NativeCompilerJob = CompilerJob{NativeCompilerTarget,CompilerParams}
GPUCompiler.runtime_module(::NativeCompilerJob) = TestRuntime

GPUCompiler.method_table(@nospecialize(job::NativeCompilerJob)) = job.config.params.method_table
GPUCompiler.can_safepoint(@nospecialize(job::NativeCompilerJob)) = job.config.params.entry_safepoint
@static if VERSION > v"1.11.0-DEV.398"
GPUCompiler.codegen_params(@nospecialize(job::NativeCompilerJob)) = (;use_jlplt=job.config.params.use_jlplt)
end

function create_job(@nospecialize(func), @nospecialize(types); kernel::Bool=false,
entry_abi=:specfunc, entry_safepoint::Bool=false, always_inline=false,
entry_abi=:specfunc, entry_safepoint::Bool=false, use_jlplt::Bool=true, always_inline=false,
method_table=test_method_table, kwargs...)
source = methodinstance(typeof(func), Base.to_tuple_type(types), Base.get_world_counter())
target = NativeCompilerTarget()
params = CompilerParams(entry_safepoint, method_table)
params = CompilerParams(entry_safepoint, use_jlplt, method_table)
config = CompilerConfig(target, params; kernel, entry_abi, always_inline)
CompilerJob(source, config), kwargs
end
Expand Down

0 comments on commit 16fd0e4

Please sign in to comment.