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

Allow for generic MethodTableView #494

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ isintrinsic(@nospecialize(job::CompilerJob), fn::String) = false

# provide a specific interpreter to use.
get_interpreter(@nospecialize(job::CompilerJob)) =
GPUInterpreter(job.world; method_table=method_table(job),
GPUInterpreter(job.world; method_table_view=maybe_cached(method_table_view(job)),
code_cache=ci_cache(job), inf_params=inference_params(job),
opt_params=optimization_params(job))

Expand Down Expand Up @@ -219,6 +219,7 @@ end

# the method table to use
method_table(@nospecialize(job::CompilerJob)) = GLOBAL_METHOD_TABLE
method_table_view(@nospecialize(job::CompilerJob)) = get_method_table_view(job.world, method_table(job))

# the inference parameters to use when constructing the GPUInterpreter
function inference_params(@nospecialize(job::CompilerJob))
Expand Down
51 changes: 19 additions & 32 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,34 +324,23 @@ end

## interpreter

if isdefined(Core.Compiler, :CachedMethodTable)
using Core.Compiler: CachedMethodTable
maybe_cached(mtv::CC.MethodTableView) = CachedMethodTable(mtv)
else
maybe_cached(mtv::CC.MethodTableView) = mtv
end

if isdefined(Base.Experimental, Symbol("@overlay"))
using Core.Compiler: OverlayMethodTable
const MTType = Core.MethodTable
if isdefined(Core.Compiler, :CachedMethodTable)
using Core.Compiler: CachedMethodTable
const GPUMethodTableView = CachedMethodTable{OverlayMethodTable}
get_method_table_view(world::UInt, mt::MTType) =
CachedMethodTable(OverlayMethodTable(world, mt))
else
const GPUMethodTableView = OverlayMethodTable
get_method_table_view(world::UInt, mt::MTType) = OverlayMethodTable(world, mt)
end
get_method_table_view(world::UInt, mt::Core.MethodTable) = OverlayMethodTable(world, mt)
else
const MTType = Nothing
if isdefined(Core.Compiler, :CachedMethodTable)
using Core.Compiler: CachedMethodTable
const GPUMethodTableView = CachedMethodTable{WorldOverlayMethodTable}
get_method_table_view(world::UInt, mt::MTType) =
CachedMethodTable(WorldOverlayMethodTable(world))
else
const GPUMethodTableView = WorldOverlayMethodTable
get_method_table_view(world::UInt, mt::MTType) = WorldOverlayMethodTable(world)
end
get_method_table_view(world::UInt, mt::Nothing) = WorldOverlayMethodTable(world)
end

struct GPUInterpreter <: CC.AbstractInterpreter
struct GPUInterpreter{MTV<:CC.MethodTableView} <: CC.AbstractInterpreter
world::UInt
method_table::GPUMethodTableView
method_table_view::MTV

code_cache::CodeCache
inf_cache::Vector{CC.InferenceResult}
Expand All @@ -361,28 +350,27 @@ struct GPUInterpreter <: CC.AbstractInterpreter
end

function GPUInterpreter(world::UInt=Base.get_world_counter();
method_table::MTType,
method_table_view::CC.MethodTableView,
code_cache::CodeCache,
inf_params::CC.InferenceParams,
opt_params::CC.OptimizationParams)
@assert world <= Base.get_world_counter()

method_table = get_method_table_view(world, method_table)
inf_cache = Vector{CC.InferenceResult}()

return GPUInterpreter(world, method_table,
return GPUInterpreter(world, method_table_view,
code_cache, inf_cache,
inf_params, opt_params)
end

function GPUInterpreter(interp::GPUInterpreter;
world::UInt=interp.world,
method_table::GPUMethodTableView=interp.method_table,
method_table_view::CC.MethodTableView=interp.method_table_view,
code_cache::CodeCache=interp.code_cache,
inf_cache::Vector{CC.InferenceResult}=interp.inf_cache,
inf_params::CC.InferenceParams=interp.inf_params,
opt_params::CC.OptimizationParams=interp.opt_params)
return GPUInterpreter(world, method_table,
return GPUInterpreter(world, method_table_view,
code_cache, inf_cache,
inf_params, opt_params)
end
Expand All @@ -409,9 +397,9 @@ CC.verbose_stmt_info(interp::GPUInterpreter) = false
end

if v"1.8-beta2" <= VERSION < v"1.9-" || VERSION >= v"1.9.0-DEV.120"
CC.method_table(interp::GPUInterpreter) = interp.method_table
CC.method_table(interp::GPUInterpreter) = interp.method_table_view
else
CC.method_table(interp::GPUInterpreter, sv::CC.InferenceState) = interp.method_table
CC.method_table(interp::GPUInterpreter, sv::CC.InferenceState) = interp.method_table_view
end

# semi-concrete interepretation is broken with overlays (JuliaLang/julia#47349)
Expand Down Expand Up @@ -489,7 +477,7 @@ end

## codegen/inference integration

function ci_cache_populate(interp, cache, mt, mi, min_world, max_world)
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
Expand Down Expand Up @@ -558,10 +546,9 @@ end
function compile_method_instance(@nospecialize(job::CompilerJob))
# populate the cache
cache = ci_cache(job)
mt = method_table(job)
interp = get_interpreter(job)
if ci_cache_lookup(cache, job.source, job.world, job.world) === nothing
ci_cache_populate(interp, cache, mt, job.source, job.world, job.world)
ci_cache_populate(interp, cache, job.source, job.world, job.world)
end

# create a callback to look-up function in our cache,
Expand Down