Skip to content

Commit c8d4aec

Browse files
committed
Save the CompilerJob in the GPUInterpreter.
1 parent e675335 commit c8d4aec

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ isintrinsic(@nospecialize(job::CompilerJob), fn::String) = false
183183

184184
# provide a specific interpreter to use.
185185
get_interpreter(@nospecialize(job::CompilerJob)) =
186-
GPUInterpreter(ci_cache(job), method_table(job), job.source.world)
186+
GPUInterpreter(job, ci_cache(job), method_table(job),)
187187

188188
# does this target support throwing Julia exceptions with jl_throw?
189189
# if not, calls to throw will be replaced with calls to the GPU runtime

src/jlgen.jl

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,29 @@ using Core.Compiler:
170170
AbstractInterpreter, InferenceResult, InferenceParams, InferenceState, OptimizationParams
171171

172172
struct GPUInterpreter <: AbstractInterpreter
173+
job::CompilerJob
174+
173175
global_cache::CodeCache
174176
method_table::Union{Nothing,Core.MethodTable}
175177

176178
# Cache of inference results for this particular interpreter
177179
local_cache::Vector{InferenceResult}
178-
# The world age we're working inside of
179-
world::UInt
180180

181181
# Parameters for inference and optimization
182182
inf_params::InferenceParams
183183
opt_params::OptimizationParams
184184

185-
function GPUInterpreter(cache::CodeCache, mt::Union{Nothing,Core.MethodTable}, world::UInt)
186-
@assert world <= Base.get_world_counter()
185+
function GPUInterpreter(job::CompilerJob, cache::CodeCache, mt::Union{Nothing,Core.MethodTable})
186+
@assert job.source.world <= Base.get_world_counter()
187187

188188
return new(
189+
job,
189190
cache,
190191
mt,
191192

192193
# Initially empty cache
193194
Vector{InferenceResult}(),
194195

195-
# world age counter
196-
world,
197-
198196
# parameters for inference and optimization
199197
InferenceParams(unoptimize_throw_blocks=false),
200198
VERSION >= v"1.8.0-DEV.486" ? OptimizationParams() :
@@ -205,9 +203,10 @@ end
205203

206204
Core.Compiler.InferenceParams(interp::GPUInterpreter) = interp.inf_params
207205
Core.Compiler.OptimizationParams(interp::GPUInterpreter) = interp.opt_params
208-
Core.Compiler.get_world_counter(interp::GPUInterpreter) = interp.world
206+
Core.Compiler.get_world_counter(interp::GPUInterpreter) = interp.job.source.world
209207
Core.Compiler.get_inference_cache(interp::GPUInterpreter) = interp.local_cache
210-
Core.Compiler.code_cache(interp::GPUInterpreter) = WorldView(interp.global_cache, interp.world)
208+
Core.Compiler.code_cache(interp::GPUInterpreter) =
209+
WorldView(interp.global_cache, Core.Compiler.get_world_counter(interp))
211210

212211
# No need to do any locking since we're not putting our results into the runtime cache
213212
Core.Compiler.lock_mi_inference(interp::GPUInterpreter, mi::MethodInstance) = nothing
@@ -221,11 +220,11 @@ function InferenceState(result::InferenceResult, cached::Symbol, interp::GPUInte
221220
src = retrieve_code_info(result.linfo)
222221
src === nothing && return nothing
223222
validate_code_in_debug_mode(result.linfo, src, "lowered")
224-
validate_globalrefs(result.linfo, src)
223+
validate_globalrefs(interp, result.linfo, src)
225224
return InferenceState(result, src, cached, interp)
226225
end
227226

228-
function validate_globalrefs(mi, src)
227+
function validate_globalrefs(interp, mi, src)
229228
function validate(x)
230229
if x isa Expr
231230
return Expr(x.head, validate.(x.args))
@@ -234,10 +233,10 @@ function validate_globalrefs(mi, src)
234233
# XXX: when does this happen? do we miss any cases by bailing out early?
235234
# why doesn't calling `Base.resolve(x, force=true)` work?
236235
if !Base.isdefined(x.mod, x.name)
237-
error("using undefined global: $(x.mod).$(x.name)")
236+
throw(KernelError(interp.job, "using undefined global: $(x.mod).$(x.name)"))
238237
end
239238
if !Base.isconst(x.mod, x.name)
240-
error("using mutable global: $(x.mod).$(x.name)")
239+
throw(KernelError(interp.job, "using mutable global: $(x.mod).$(x.name)"))
241240
end
242241
# XXX: can we use KernelError? and make the validation conditional? both are
243242
# complicated by the fact that we don't have the CompilerJob here,
@@ -270,14 +269,14 @@ if isdefined(Base.Experimental, Symbol("@overlay"))
270269
using Core.Compiler: OverlayMethodTable
271270
if v"1.8-beta2" <= VERSION < v"1.9-" || VERSION >= v"1.9.0-DEV.120"
272271
Core.Compiler.method_table(interp::GPUInterpreter) =
273-
OverlayMethodTable(interp.world, interp.method_table)
272+
OverlayMethodTable(Core.Compiler.get_world_counter(interp), interp.method_table)
274273
else
275274
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) =
276-
OverlayMethodTable(interp.world, interp.method_table)
275+
OverlayMethodTable(Core.Compiler.get_world_counter(interp), interp.method_table)
277276
end
278277
else
279278
Core.Compiler.method_table(interp::GPUInterpreter, sv::InferenceState) =
280-
WorldOverlayMethodTable(interp.world)
279+
WorldOverlayMethodTable(Core.Compiler.get_world_counter(interp))
281280
end
282281

283282

src/validation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function check_method(@nospecialize(job::CompilerJob))
3232
if job.source.kernel
3333
cache = ci_cache(job)
3434
mt = method_table(job)
35-
interp = GPUInterpreter(cache, mt, world)
35+
interp = GPUInterpreter(job, cache, mt)
3636
rt = return_type(only(ms); interp)
3737

3838
if rt != Nothing

0 commit comments

Comments
 (0)