1+ using Test
2+
3+ function precompile_test_harness (@nospecialize (f), testset:: String )
4+ @testset " $testset " begin
5+ precompile_test_harness (f, true )
6+ end
7+ end
8+ function precompile_test_harness (@nospecialize (f), separate:: Bool )
9+ load_path = mktempdir ()
10+ load_cache_path = separate ? mktempdir () : load_path
11+ try
12+ pushfirst! (LOAD_PATH , load_path)
13+ pushfirst! (DEPOT_PATH , load_cache_path)
14+ f (load_path)
15+ finally
16+ try
17+ rm (load_path, force= true , recursive= true )
18+ catch err
19+ @show err
20+ end
21+ if separate
22+ try
23+ rm (load_cache_path, force= true , recursive= true )
24+ catch err
25+ @show err
26+ end
27+ end
28+ filter! ((≠ )(load_path), LOAD_PATH )
29+ separate && filter! ((≠ )(load_cache_path), DEPOT_PATH )
30+ end
31+ nothing
32+ end
33+
34+ precompile_test_harness (" Inference caching" ) do load_path
35+ write (joinpath (load_path, " InferenceCaching.jl" ), :(module InferenceCaching
36+ using Enzyme
37+ using PrecompileTools
38+
39+ function mul (x, y)
40+ return x * y
41+ end
42+
43+ @setup_workload begin
44+ @compile_workload begin
45+ autodiff (Reverse, mul, Active, Active (1.0 ), Active (2.0 ))
46+ autodiff (Forward, mul, Duplicated, Duplicated (1.0 , 1.0 ), Const (2.0 ))
47+ end
48+ end
49+ end ) |> string)
50+
51+ Base. compilecache (Base. PkgId (" InferenceCaching" ))
52+ @eval let
53+ using InferenceCaching
54+ using Enzyme
55+
56+ autodiff (Reverse, InferenceCaching. mul, Active, Active (1.0 ), Active (2.0 ))
57+ autodiff (Forward, InferenceCaching. mul, Duplicated, Duplicated (1.0 , 1.0 ), Const (2.0 ))
58+ end
59+ end
0 commit comments