Skip to content

Commit

Permalink
wip: JET integration
Browse files Browse the repository at this point in the history
Better than segfault?
```julia
[ Info: Setting up Base development utilities ...
julia> using Enzyme

julia> f(cond, x) = cond ? x : 0
f (generic function with 1 method)

julia> g(cond, x) = f(cond,x)*x
g (generic function with 1 method)

julia> autodiff(g, Active, true, Active(1.0))
═════ 1 possible error found ═════
┌ @ REPL[3]:1 Main.f(cond, x)
│┌ @ REPL[2]:1 f(::Bool, ::Float64)
││ Union result (`Union{Float64, Int64}`) detected: f(::Bool, ::Float64)
│└─────────────
ERROR: "Enzyme can't differentiate this program: fix the Union result"
Stacktrace:
  [1] ci_cache_populate(interp::Enzyme.Compiler.EnzymeInterpeter, cache::GPUCompiler.CodeCache, mt::Core.MethodTable, mi::Core.MethodInstance, min_world::UInt64, max_world::Int32)
    @ Enzyme.Compiler ~/julia/packages/Enzyme/src/compiler.jl:2255
  [2] compile_method_instance(job::GPUCompiler.CompilerJob, method_instance::Core.MethodInstance; ctx::LLVM.Context)
    @ GPUCompiler ~/julia/packages/GPUCompiler/src/jlgen.jl:335
  [3] macro expansion
    @ ~/.julia/packages/TimerOutputs/nDhDw/src/TimerOutput.jl:252 [inlined]
  [4] irgen(job::GPUCompiler.CompilerJob, method_instance::Core.MethodInstance; ctx::LLVM.Context)
    @ GPUCompiler ~/julia/packages/GPUCompiler/src/irgen.jl:5
  [5] macro expansion
    @ ~/julia/packages/GPUCompiler/src/driver.jl:205 [inlined]
  [6] macro expansion
    @ ~/.julia/packages/TimerOutputs/nDhDw/src/TimerOutput.jl:252 [inlined]
  [7] macro expansion
    @ ~/julia/packages/GPUCompiler/src/driver.jl:204 [inlined]
  [8] emit_llvm(job::GPUCompiler.CompilerJob, method_instance::Any; libraries::Bool, deferred_codegen::Bool, optimize::Bool, only_entry::Bool, ctx::LLVM.Context)
    @ GPUCompiler ~/julia/packages/GPUCompiler/src/utils.jl:64
  [9] codegen(output::Symbol, job::GPUCompiler.CompilerJob; libraries::Bool, deferred_codegen::Bool, optimize::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing, ctx::LLVM.Context)
    @ GPUCompiler ~/julia/packages/GPUCompiler/src/driver.jl:108
 [10] codegen(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams, GPUCompiler.FunctionSpec{typeof(g), Tuple{Bool, Float64}}}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, ctx::LLVM.Context, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/julia/packages/Enzyme/src/compiler.jl:3138
 [11] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams, GPUCompiler.FunctionSpec{typeof(g), Tuple{Bool, Float64}}})
    @ Enzyme.Compiler ~/julia/packages/Enzyme/src/compiler.jl:3707
 [12] cached_compilation(cache::Dict{UInt64, Any}, job::GPUCompiler.CompilerJob, compiler::typeof(Enzyme.Compiler._thunk), linker::typeof(Enzyme.Compiler._link))
    @ GPUCompiler ~/julia/packages/GPUCompiler/src/cache.jl:90
 [13] thunk(f::typeof(g), df::Nothing, ::Type{Active}, tt::Type{Tuple{Const{Bool}, Active{Float64}}}, ::Val{Enzyme.API.DEM_ReverseModeCombined})
    @ Enzyme.Compiler ~/julia/packages/Enzyme/src/compiler.jl:3760
 [14] autodiff(::typeof(g), ::Type{Active}, ::Bool, ::Vararg{Any})
    @ Enzyme ~/julia/packages/Enzyme/src/Enzyme.jl:197
 [15] top-level scope
    @ REPL[4]:1
```
  • Loading branch information
aviatesk committed Mar 18, 2022
1 parent e0ae6f9 commit 895d0a4
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 54 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Enzyme_jll = "7cc45869-7501-5eee-bdea-0790c847d4ef"
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
Loading

0 comments on commit 895d0a4

Please sign in to comment.