Skip to content

Commit

Permalink
Add jit macro for simplified testing (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses authored Oct 29, 2024
1 parent 1dd24b8 commit 6866f05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,30 @@ macro compile(options, maybe_call=nothing)
end
end

"""
@jit f(args...)
Run @compile f(args..) then immediately execute it
"""
macro jit(options, maybe_call=nothing)
call = something(maybe_call, options)
options = isnothing(maybe_call) ? :(optimize = true) : options
Meta.isexpr(call, :call) || error("@compile: expected call, got $call")
if !Meta.isexpr(options, :(=)) || options.args[1] != :optimize
error("@compile: expected options in format optimize=value, got $options")
end

options = Expr(:tuple, Expr(:parameters, Expr(:kw, options.args...)))

quote
options = $(esc(options))
f = $(esc(call.args[1]))
args = $(esc(Expr(:tuple, call.args[2:end]...)))
fn = compile(f, args; options.optimize)
fn(args...)
end
end

"""
codegen_flatten!
Expand Down
4 changes: 2 additions & 2 deletions src/Reactant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const TracedType = Union{TracedRArray,TracedRNumber}
include("Tracing.jl")
include("Compiler.jl")

using .Compiler: @compile, @code_hlo, traced_getfield, create_result, compile
export ConcreteRArray, @compile, @code_hlo
using .Compiler: @compile, @code_hlo, @jit, traced_getfield, create_result, compile
export ConcreteRArray, @compile, @code_hlo, @jit

const registry = Ref{MLIR.IR.DialectRegistry}()
function __init__()
Expand Down

1 comment on commit 6866f05

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reactant.jl Benchmarks

Benchmark suite Current: 6866f05 Previous: 1dd24b8 Ratio
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme) 1331366172 ns 1332810111 ns 1.00
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant 1333147663 ns 1310849226 ns 1.02
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme) 1530087148 ns 1398288716 ns 1.09
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme) 3054505913 ns 2623910053 ns 1.16
ViT base (256 x 256 x 3 x 32)/forward/CUDA/Lux 230499086 ns 215139523 ns 1.07
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 5310260095 ns 5334887020 ns 1.00
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant 5117023688 ns 5125148459 ns 1.00
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 5696115262 ns 5128099715 ns 1.11
ViT base (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 6877852849 ns 7093041527 ns 0.97
ViT base (256 x 256 x 3 x 32)/forward/CPU/Lux 31332890298 ns 31469979010 ns 1.00
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme) 1377593493 ns 1390179366 ns 0.99
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant 1419824350 ns 1268184459.5 ns 1.12
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme) 1370284838 ns 1270873858.5 ns 1.08
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme) 2678832914 ns 2492061660 ns 1.07
ViT small (256 x 256 x 3 x 4)/forward/CUDA/Lux 8674244 ns 8221824 ns 1.06
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 1711793645 ns 1711092077 ns 1.00
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant 1593142398 ns 1558493025 ns 1.02
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1553322361 ns 1546123882 ns 1.00
ViT small (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 2788658689 ns 2735606253 ns 1.02
ViT small (256 x 256 x 3 x 4)/forward/CPU/Lux 3829077050 ns 2456759080 ns 1.56
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme) 1292126503 ns 1286461508.5 ns 1.00
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant 1255035565.5 ns 1287819878 ns 0.97
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme) 1241708897.5 ns 1229738497.5 ns 1.01
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme) 2627736445 ns 2423291169 ns 1.08
ViT tiny (256 x 256 x 3 x 32)/forward/CUDA/Lux 21072763 ns 20850848 ns 1.01
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 2141201304 ns 2148735048 ns 1.00
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant 2150005669 ns 2138885245 ns 1.01
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 2153988118 ns 2133624257 ns 1.01
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 3403989575 ns 3388591813 ns 1.00
ViT tiny (256 x 256 x 3 x 32)/forward/CPU/Lux 6112741293.5 ns 5994160924 ns 1.02
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme) 1319271524 ns 1312161644.5 ns 1.01
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant 1321146725.5 ns 1286524449.5 ns 1.03
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme) 1336696942 ns 1304833938.5 ns 1.02
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme) 2956277164 ns 2654597387 ns 1.11
ViT tiny (256 x 256 x 3 x 4)/forward/CUDA/Lux 7206908 ns 7062374 ns 1.02
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 1446752820 ns 1463335858 ns 0.99
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant 1420199736 ns 1418279069 ns 1.00
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1419361542 ns 1407215120 ns 1.01
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 2620658225 ns 2610977913 ns 1.00
ViT tiny (256 x 256 x 3 x 4)/forward/CPU/Lux 1343552629 ns 1313118431 ns 1.02
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme) 1339740837 ns 1266033162 ns 1.06
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant 1297025776.5 ns 1246060690 ns 1.04
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme) 1307783663.5 ns 1334724021 ns 0.98
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme) 2422904622 ns 2615371467 ns 0.93
ViT tiny (256 x 256 x 3 x 16)/forward/CUDA/Lux 13705203.5 ns 11338191 ns 1.21
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 1689997595 ns 1712640221 ns 0.99
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant 1709524846 ns 1714535441 ns 1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 1699909787 ns 1699386874 ns 1.00
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 2910898852 ns 2934490244 ns 0.99
ViT tiny (256 x 256 x 3 x 16)/forward/CPU/Lux 3172820959 ns 3109868396.5 ns 1.02
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme) 1272957214 ns 1304791782 ns 0.98
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant 1288787604 ns 1285502833 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme) 1292898756 ns 1277688710 ns 1.01
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme) 2528780375 ns 2599975980 ns 0.97
ViT small (256 x 256 x 3 x 16)/forward/CUDA/Lux 25554565 ns 25551082.5 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 2158163346 ns 2164823256 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant 2164587691 ns 2168156538 ns 1.00
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 2157132364 ns 2195060353 ns 0.98
ViT small (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 3395183827 ns 3415103088 ns 0.99
ViT small (256 x 256 x 3 x 16)/forward/CPU/Lux 6334070118 ns 6792188737 ns 0.93
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :after_enzyme) 1228186625 ns 1251711662 ns 0.98
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant 1202678487.5 ns 1314443020 ns 0.91
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :before_enzyme) 1189947014.5 ns 1296451333 ns 0.92
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Reactant (optimize = :only_enzyme) 2346429480 ns 2569030485 ns 0.91
ViT small (256 x 256 x 3 x 32)/forward/CUDA/Lux 50144272.5 ns 50146964 ns 1.00
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :after_enzyme) 2973474372 ns 3044550425 ns 0.98
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant 3005386081 ns 3049319408 ns 0.99
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :before_enzyme) 2959359145 ns 2999963120 ns 0.99
ViT small (256 x 256 x 3 x 32)/forward/CPU/Reactant (optimize = :only_enzyme) 4361243109 ns 4363286803 ns 1.00
ViT small (256 x 256 x 3 x 32)/forward/CPU/Lux 9378921820 ns 10042481459 ns 0.93
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :after_enzyme) 1247107066 ns 1302500995 ns 0.96
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant 1226562970 ns 1297504625 ns 0.95
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :before_enzyme) 1232975234.5 ns 1310827906 ns 0.94
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Reactant (optimize = :only_enzyme) 2344405060 ns 2446072271 ns 0.96
ViT base (256 x 256 x 3 x 16)/forward/CUDA/Lux 67888329.5 ns 67921126 ns 1.00
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :after_enzyme) 3168087012 ns 3156309083 ns 1.00
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant 3147204975 ns 3173315537 ns 0.99
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :before_enzyme) 3238059309 ns 3130494484 ns 1.03
ViT base (256 x 256 x 3 x 16)/forward/CPU/Reactant (optimize = :only_enzyme) 4525581424 ns 4504318538 ns 1.00
ViT base (256 x 256 x 3 x 16)/forward/CPU/Lux 13793978482 ns 14749507671 ns 0.94
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :after_enzyme) 1191983955 ns 1303044095 ns 0.91
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant 1202390873 ns 1304317104.5 ns 0.92
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :before_enzyme) 1204541731 ns 1332711162 ns 0.90
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Reactant (optimize = :only_enzyme) 2466522108 ns 2642760989 ns 0.93
ViT base (256 x 256 x 3 x 4)/forward/CUDA/Lux 19336923 ns 19441467 ns 0.99
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :after_enzyme) 2207876303 ns 1863044822 ns 1.19
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant 1998857639 ns 1837806913 ns 1.09
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :before_enzyme) 1904292223 ns 1855662911 ns 1.03
ViT base (256 x 256 x 3 x 4)/forward/CPU/Reactant (optimize = :only_enzyme) 3061997168 ns 3030096911 ns 1.01
ViT base (256 x 256 x 3 x 4)/forward/CPU/Lux 3696727697 ns 3331794574 ns 1.11

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.