Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate dsyevr_64_ #64

Closed
Roger-luo opened this issue May 28, 2021 · 5 comments
Closed

Differentiate dsyevr_64_ #64

Roger-luo opened this issue May 28, 2021 · 5 comments
Assignees
Labels

Comments

@Roger-luo
Copy link

I'm not sure why it complains the return type is Union{}, the return type of this foo function is quite simple? I got

julia> foo(x) = sum(exp(fill(x, 10, 10)))
foo (generic function with 1 method)

julia> Enzyme.autodiff(foo, Active(2.0))
ERROR: return type is Union{}, giving up.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] enzyme!(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams, GPUCompiler.FunctionSpec{typeof(Cassette.overdub), Tuple{Cassette.Context{nametype(EnzymeCtx), Nothing, Nothing, Enzyme.Compiler.var"##PassType#257", Nothing, Cassette.DisableHooks}, typeof(foo), Float64}}}, mod::LLVM.Module, primalf::LLVM.Function, adjoint::GPUCompiler.FunctionSpec{typeof(foo), Tuple{Active{Float64}}}, split::Bool, parallel::Bool)
   @ Enzyme.Compiler ~/.julia/packages/Enzyme/A97If/src/compiler.jl:143
 [3] codegen(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams, GPUCompiler.FunctionSpec{typeof(Cassette.overdub), Tuple{Cassette.Context{nametype(EnzymeCtx), Nothing, Nothing, Enzyme.Compiler.var"##PassType#257", Nothing, Cassette.DisableHooks}, typeof(foo), Float64}}}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
   @ Enzyme.Compiler ~/.julia/packages/Enzyme/A97If/src/compiler.jl:435
 [4] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams, GPUCompiler.FunctionSpec{typeof(Cassette.overdub), Tuple{Cassette.Context{nametype(EnzymeCtx), Nothing, Nothing, Enzyme.Compiler.var"##PassType#257", Nothing, Cassette.DisableHooks}, typeof(foo), Float64}}})
   @ Enzyme.Compiler ~/.julia/packages/Enzyme/A97If/src/compiler.jl:761
 [5] callback(orc_ref::Ptr{LLVM.API.LLVMOrcOpaqueJITStack}, callback_ctx::Ptr{Nothing})
   @ Enzyme.Compiler ~/.julia/packages/Enzyme/A97If/src/compiler.jl:822
 [6] top-level scope
   @ REPL[11]:1

julia> @code_warntype foo(2.0)
Variables
  #self#::Core.Const(foo)
  x::Float64

Body::Float64
1%1 = Main.fill(x, 10, 10)::Matrix{Float64}%2 = Main.exp(%1)::Matrix{Float64}%3 = Main.sum(%2)::Float64
└──      return %3
@wsmoses
Copy link
Member

wsmoses commented May 28, 2021

What happens if you do autodiff_no_casette?

@Roger-luo
Copy link
Author

It crash with like over 1k line error for autodiff_no_cassette (this is on another machine on MacOS, I can try it on the Linux machine if needed)

784768, i64 -6940216133781273352, i64 -6832105780228080109, i64 -5841289834741351288, i64 -8696547905883959080, i64 -5989860371902311149, i64 7129149566058721777, i64 8408196149339104217]: {[-1]:Pointer}, intvals: {}
  %13 = getelementptr inbounds [256 x i64], [256 x i64]* @_j_const5, i64 0, i64 %12, !dbg !165: {[-1]:Pointer}, intvals: {}
  %merge = phi double [ 0x7FF0000000000000, %L44 ], [ 0.000000e+00, %L47 ]: {[-1]:Float@double}, intvals: {}
  %35 = icmp sgt i32 %5, -13313, !dbg !211: {[-1]:Integer}, intvals: {}
  %10 = fsub contract double %8, %9, !dbg !155: {[-1]:Float@double}, intvals: {}
  %8 = fsub contract double %0, %7, !dbg !153: {[-1]:Float@double}, intvals: {}
</analysis>
Illegal updateAnalysis prev:{[-1]:Float@double} new: {[-1]:Integer}
val:   %5 = trunc i64 %4 to i32, !dbg !147 origin=  %35 = icmp sgt i32 %5, -13313, !dbg !211
Assertion failed: (0 && "Performed illegal updateAnalysis"), function updateAnalysis, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp, line 511.

signal (6): Abort trap: 6
in expression starting at REPL[3]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 35817871 (Pool: 35799479; Big: 18392); GC: 38
[1]    19138 abort      julia

@wsmoses
Copy link
Member

wsmoses commented Jun 1, 2021

Yeah this is primarily a cassette bug and unfortunately doesn't appear to have a good fix without cassette fixing the bug on their side. The with cassette version fails per that bug. The version without cassette means differentiating the bithack internals of exp (which we can, but shouldn't do)

@wsmoses
Copy link
Member

wsmoses commented Jul 9, 2021

Having since worked around cassette this now reached the point where it cannot be differentiated due to the following blas function not having a gradient defined:

declare void @dsyevr_64_(i8*, i8*, i8*, i8*, i64, i8*, i8*, i8*, i8*, i8*, i8*, i64, i64, i64, i8*, i64, i64, i8*, i64, i8*, i64, i64, i64, i64) local_unnamed_addr

@reikdas perhaps one to consider after ddot goes through.

@vchuravy vchuravy changed the title return type is Union{}, giving up for a simple matrix function Differentiate dsyevr_64_ Jul 18, 2021
@vchuravy vchuravy added the upstream Enzyme proper label Jul 18, 2021
@vchuravy
Copy link
Member

bump. Does Enzyme now support dsyevr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants