Skip to content

Commit ff3085f

Browse files
committed
Introduce precompile function
1 parent b0ef784 commit ff3085f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/jlgen.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,27 @@ macro in_world(world, ex)
587587
end
588588
end
589589

590+
"""
591+
precompile(job::CompilerJob)
592+
593+
Compile the GPUCompiler job. In particular this will run inference using the foreign
594+
abstract interpreter.
595+
"""
596+
function Base.precompile(@nospecialize(job::CompilerJob))
597+
if job.source.def.primary_world > job.world || job.world > job.source.def.deleted_world
598+
error("Cannot compile $(job.source) for world $(job.world); method is only valid in worlds $(job.source.def.primary_world) to $(job.source.def.deleted_world)")
599+
end
600+
601+
# populate the cache
602+
interp = get_interpreter(job)
603+
cache = CC.code_cache(interp)
604+
if ci_cache_lookup(cache, job.source, job.world, job.world) === nothing
605+
ci_cache_populate(interp, cache, job.source, job.world, job.world)
606+
return ci_cache_lookup(cache, job.source, job.world, job.world) !== nothing
607+
end
608+
return true
609+
end
610+
590611
function compile_method_instance(@nospecialize(job::CompilerJob))
591612
if job.source.def.primary_world > job.world || job.world > job.source.def.deleted_world
592613
error("Cannot compile $(job.source) for world $(job.world); method is only valid in worlds $(job.source.def.primary_world) to $(job.source.def.deleted_world)")

test/native_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,14 @@ precompile_test_harness("Inference caching") do load_path
556556

557557
let
558558
job, _ = NativeCompiler.create_job(kernel, (Vector{Int}, Int))
559-
GPUCompiler.code_typed(job)
559+
precompile(job)
560560
end
561561

562562
# identity is foreign
563563
@setup_workload begin
564564
job, _ = NativeCompiler.create_job(identity, (Int,))
565565
@compile_workload begin
566-
GPUCompiler.code_typed(job)
566+
precompile(job)
567567
end
568568
end
569569
end) |> string)

test/ptx_tests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ precompile_test_harness("Inference caching") do load_path
339339

340340
let
341341
job, _ = PTXCompiler.create_job(kernel, ())
342-
GPUCompiler.code_typed(job)
342+
precompile(job)
343343
end
344344

345345
# identity is foreign
346346
@setup_workload begin
347347
job, _ = PTXCompiler.create_job(identity, (Int,))
348348
@compile_workload begin
349-
GPUCompiler.code_typed(job)
349+
precompile(job)
350350
end
351351
end
352352
end) |> string)

0 commit comments

Comments
 (0)