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

Second order AD error #2011

Open
jgreener64 opened this issue Oct 23, 2024 · 2 comments
Open

Second order AD error #2011

jgreener64 opened this issue Oct 23, 2024 · 2 comments

Comments

@jgreener64
Copy link
Contributor

I am on Enzyme 0.13.12, StaticArrays 1.9.8 and Julia 1.10.5 on Mac.

using Enzyme, StaticArrays, LinearAlgebra

function mvp(a, b)
    o = zeros(size(a, 1))
    for i in axes(a, 1)
        s = 0.0
        for j in axes(a, 2)
            s += a[i, j] * b[j]
        end
        o[i] = s
    end
    return o
end

function g(E_rep, params)
    w1, b1, w2, b2 = params
    h1 = mvp(w1, E_rep) .+ b1
    return mvp(w2, h1) .+ b2
end

function f(coords, params)
    E_rep = norm.(coords)
    E = g(E_rep, params)
    return E[1]
end

coords = rand(SVector{3, Float64}, 8)
params = (rand(16, 8), rand(16), rand(1, 16), rand(1))
f(coords, params)

function f2(coords, params)
    d_coords = zero(coords)
    autodiff(
        set_runtime_activity(Reverse),
        f,
        Active,
        Duplicated(coords, d_coords),
        Const(params),
    )
    return -d_coords
end

loss(coords, params) = f2(coords, params)[1][1]
loss(coords, params)
# First order works

d_params = (zeros(16, 8), zeros(16), zeros(1, 16), zeros(1))
autodiff(
    set_runtime_activity(Reverse),
    loss,
    Active,
    Const(coords),
    Duplicated(params, d_params),
)
# Second order errors
freeing without malloc   %2 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 4
freeing without malloc   %2 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 4
ERROR: LoadError: Enzyme cannot deduce type
Current scope:
; Function Attrs: mustprogress willreturn
define private fastcc void @preprocess_diffejulia_mvp_3682({} addrspace(10)* nocapture nonnull readonly align 16 dereferenceable(40) "enzyme_type"="{[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}" "enzymejl_parmtype"="4721353664" "enzymejl_parmtype_ref"="2" %0, {} addrspace(10)* nocapture readonly align 16 "enzyme_type"="{[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}" "enzymejl_parmtype"="4721353664" "enzymejl_parmtype_ref"="2" %"'", { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg) unnamed_addr #20 !dbg !3379 {
top:
  %1 = call {}*** @julia.get_pgcstack() #33
  %2 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 4
  %arraysize = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 1, !dbg !3380
  %3 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 0, !dbg !3380
  %arraylen = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 2, !dbg !3386
  %.not = icmp eq i64 %arraylen, 0, !dbg !3386
  %.not73 = icmp eq i64 %arraysize, 0, !dbg !3392
  br i1 %.not73, label %invertL33, label %invertidxend51.preheader, !dbg !3396

inverttop:                                        ; preds = %invertL33, %inverttop.L15_crit_edge
  fence syncscope("singlethread") seq_cst
  ret void

inverttop.L15_crit_edge:                          ; preds = %invertL33
  %_unwrap = shl nuw i64 %arraylen, 3, !dbg !3397
  %"'ipc_unwrap" = addrspacecast {} addrspace(10)* %3 to i8 addrspace(13)* addrspace(11)*, !dbg !3397
  %"arrayptr.pre7190'il_phi_unwrap" = load i8 addrspace(13)*, i8 addrspace(13)* addrspace(11)* %"'ipc_unwrap", align 8, !dbg !3397, !tbaa !128, !alias.scope !3399, !noalias !3408
  call void @llvm.memset.p13i8.i64(i8 addrspace(13)* align 8 %"arrayptr.pre7190'il_phi_unwrap", i8 noundef 0, i64 %_unwrap, i1 noundef false) #33, !dbg !3397, !tbaa !424, !noalias !3410
  br label %inverttop

invertL33:                                        ; preds = %invertL33.L45_crit_edge, %top
  br i1 %.not, label %inverttop, label %inverttop.L15_crit_edge

invertL33.L45_crit_edge:                          ; preds = %invertL45
  %4 = bitcast double* %2 to i8*
  call void @free(i8* nonnull %4) #33, !dbg !3411
  br label %invertL33

invertL45.loopexit:                               ; preds = %invertidxend38_amerge
  br label %invertL45

invertL45:                                        ; preds = %invertL45.loopexit, %invertidxend51
  %"'de.0" = phi double [ %19, %invertidxend51 ], [ 0.000000e+00, %invertL45.loopexit ]
  %5 = icmp eq i64 %storemerge, 0
  br i1 %5, label %invertL33.L45_crit_edge, label %invertidxend51

invertidxend51.preheader:                         ; preds = %top
  %arraysize18.pre = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 3
  %.not74 = icmp eq i64 %arraysize18.pre, 0
  %"'ipc30_unwrap" = addrspacecast {} addrspace(10)* %3 to double addrspace(13)* addrspace(11)*
  %"arrayptr5379'il_phi_unwrap" = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %"'ipc30_unwrap", align 8, !tbaa !128, !alias.scope !3399, !noalias !3408, !nonnull !0
  %_unwrap21 = addrspacecast {} addrspace(10)* %0 to double addrspace(13)* addrspace(11)*
  %arrayptr4077_unwrap = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %_unwrap21, align 16, !alias.scope !3412
  %"'ipc11_unwrap" = addrspacecast {} addrspace(10)* %"'" to double addrspace(13)* addrspace(11)*
  br label %invertidxend51

invertidxend38:                                   ; preds = %invertidxend38.preheader, %invertidxend38_amerge
  %iv1 = phi i64 [ 0, %invertidxend38.preheader ], [ %iv.next2, %invertidxend38_amerge ]
  %6 = mul nsw i64 %iv1, -1
  %iv.next2 = add nuw nsw i64 %iv1, 1
  %7 = add nsw i64 %arraysize18.pre, %6
  %storemerge1 = add nsw i64 %7, -1
  br i1 %.not2, label %invertidxend38_amerge, label %invertidxend38_active, !dbg !3413

invertidxend38_active:                            ; preds = %invertidxend38
  %8 = add nuw nsw i64 %storemerge1, %20, !dbg !3415
  %9 = getelementptr inbounds double, double* %2, i64 %8, !dbg !3415
  %10 = load double, double* %9, align 8, !dbg !3416, !tbaa !424, !alias.scope !41, !noalias !1118, !invariant.group !3417
  %"'ipg_unwrap" = getelementptr inbounds double, double addrspace(13)* %"arrayptr4077'ipl_unwrap", i64 %storemerge1, !dbg !3413
  %11 = fmul fast double %10, %19, !dbg !3415
  %12 = load double, double addrspace(13)* %"'ipg_unwrap", align 8, !dbg !3413, !tbaa !424, !alias.scope !3418, !noalias !3421
  %13 = fadd fast double %12, %11, !dbg !3413
  store double %13, double addrspace(13)* %"'ipg_unwrap", align 8, !dbg !3413, !tbaa !424, !alias.scope !3418, !noalias !3423
  br label %invertidxend38_amerge, !dbg !3413

invertidxend38_amerge:                            ; preds = %invertidxend38_active, %invertidxend38
  %14 = icmp eq i64 %storemerge1, 0
  br i1 %14, label %invertL45.loopexit, label %invertidxend38

invertidxend51:                                   ; preds = %invertidxend51.preheader, %invertL45
  %iv = phi i64 [ 0, %invertidxend51.preheader ], [ %iv.next, %invertL45 ]
  %"'de.2" = phi double [ %"'de.0", %invertL45 ], [ 0.000000e+00, %invertidxend51.preheader ]
  %15 = mul nsw i64 %iv, -1
  %iv.next = add nuw nsw i64 %iv, 1
  %16 = add nsw i64 %arraysize, %15
  %storemerge = add nsw i64 %16, -1
  %"'ipg29_unwrap" = getelementptr inbounds double, double addrspace(13)* %"arrayptr5379'il_phi_unwrap", i64 %storemerge, !dbg !3424
  %17 = load double, double addrspace(13)* %"'ipg29_unwrap", align 8, !dbg !3424, !tbaa !424, !alias.scope !3426, !noalias !3429
  store double 0.000000e+00, double addrspace(13)* %"'ipg29_unwrap", align 8, !dbg !3424, !tbaa !424, !alias.scope !3426, !noalias !3431
  %18 = select fast i1 %.not74, double 0.000000e+00, double %17
  %19 = fadd fast double %18, %"'de.2"
  br i1 %.not74, label %invertL45, label %invertidxend38.preheader

invertidxend38.preheader:                         ; preds = %invertidxend51
  %"arrayptr4077'ipl_unwrap" = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %"'ipc11_unwrap", align 16, !alias.scope !3432, !noalias !3435, !invariant.group !3437
  %.not2 = icmp eq double addrspace(13)* %arrayptr4077_unwrap, %"arrayptr4077'ipl_unwrap"
  %20 = mul nuw nsw i64 %storemerge, %arraysize18.pre
  br label %invertidxend38, !dbg !3413
}

 Type analysis state:
<analysis>
i64 1: {[-1]:Integer}, intvals: {1,}
i64 0: {[-1]:Anything}, intvals: {0,}
i64 3: {[-1]:Integer}, intvals: {3,}
i64 -1: {[-1]:Anything}, intvals: {-1,}
double 0.000000e+00: {[-1]:Anything}, intvals: {}
  %18 = select fast i1 %.not74, double 0.000000e+00, double %17: {[-1]:Float@double}, intvals: {}
  %"'ipg_unwrap" = getelementptr inbounds double, double addrspace(13)* %"arrayptr4077'ipl_unwrap", i64 %storemerge1, !dbg !82: {[-1]:Pointer, [-1,-1]:Float@double}, intvals: {}
  %"'ipg29_unwrap" = getelementptr inbounds double, double addrspace(13)* %"arrayptr5379'il_phi_unwrap", i64 %storemerge, !dbg !99: {[-1]:Pointer, [-1,0]:Float@double}, intvals: {}
  call void @free(i8* nonnull %4) #33, !dbg !80: {}, intvals: {}
  %9 = getelementptr inbounds double, double* %2, i64 %8, !dbg !86: {[-1]:Pointer, [-1,0]:Float@double}, intvals: {}
  %12 = load double, double addrspace(13)* %"'ipg_unwrap", align 8, !dbg !82, !tbaa !76, !alias.scope !93, !noalias !96: {[-1]:Float@double}, intvals: {}
  %"arrayptr.pre7190'il_phi_unwrap" = load i8 addrspace(13)*, i8 addrspace(13)* addrspace(11)* %"'ipc_unwrap", align 8, !dbg !51, !tbaa !54, !alias.scope !59, !noalias !70: {[-1]:Pointer}, intvals: {}
  %arrayptr4077_unwrap = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %_unwrap21, align 16, !alias.scope !81: {[-1]:Pointer, [-1,-1]:Float@double}, intvals: {}
  %"'ipc_unwrap" = addrspacecast {} addrspace(10)* %3 to i8 addrspace(13)* addrspace(11)*, !dbg !51: {[-1]:Pointer, [-1,0]:Pointer}, intvals: {}
  %10 = load double, double* %9, align 8, !dbg !89, !tbaa !76, !alias.scope !90, !noalias !91, !invariant.group !92: {[-1]:Float@double}, intvals: {}
  %4 = bitcast double* %2 to i8*: {[-1]:Pointer}, intvals: {}
  %"'ipc30_unwrap" = addrspacecast {} addrspace(10)* %3 to double addrspace(13)* addrspace(11)*: {[-1]:Pointer, [-1,0]:Pointer}, intvals: {}
  %"arrayptr5379'il_phi_unwrap" = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %"'ipc30_unwrap", align 8, !tbaa !54, !alias.scope !59, !noalias !70, !nonnull !0: {[-1]:Pointer}, intvals: {}
  %17 = load double, double addrspace(13)* %"'ipg29_unwrap", align 8, !dbg !99, !tbaa !76, !alias.scope !101, !noalias !104: {[-1]:Float@double}, intvals: {}
  %_unwrap21 = addrspacecast {} addrspace(10)* %0 to double addrspace(13)* addrspace(11)*: {[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}, intvals: {}
  %"'ipc11_unwrap" = addrspacecast {} addrspace(10)* %"'" to double addrspace(13)* addrspace(11)*: {[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}, intvals: {}
  %"arrayptr4077'ipl_unwrap" = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %"'ipc11_unwrap", align 16, !alias.scope !107, !noalias !110, !invariant.group !112: {[-1]:Pointer, [-1,-1]:Float@double}, intvals: {}
  %iv1 = phi i64 [ 0, %invertidxend38.preheader ], [ %iv.next2, %invertidxend38_amerge ]: {[-1]:Integer}, intvals: {0,}
  %iv = phi i64 [ 0, %invertidxend51.preheader ], [ %iv.next, %invertL45 ]: {[-1]:Integer}, intvals: {0,}
  %"'de.0" = phi double [ %19, %invertidxend51 ], [ 0.000000e+00, %invertL45.loopexit ]: {[-1]:Float@double}, intvals: {}
  %"'de.2" = phi double [ %"'de.0", %invertL45 ], [ 0.000000e+00, %invertidxend51.preheader ]: {[-1]:Float@double}, intvals: {}
  %1 = call {}*** @julia.get_pgcstack() #33: {}, intvals: {}
  %.not73 = icmp eq i64 %arraysize, 0, !dbg !46: {[-1]:Integer}, intvals: {}
  %14 = icmp eq i64 %storemerge1, 0: {[-1]:Integer}, intvals: {}
  %storemerge1 = add nsw i64 %7, -1: {[-1]:Integer}, intvals: {}
  %16 = add nsw i64 %arraysize, %15: {[-1]:Integer}, intvals: {}
  %iv.next = add nuw nsw i64 %iv, 1: {[-1]:Integer}, intvals: {1,}
  %storemerge = add nsw i64 %16, -1: {[-1]:Integer}, intvals: {}
  %20 = mul nuw nsw i64 %storemerge, %arraysize18.pre: {[-1]:Integer}, intvals: {}
  %arraysize = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 1, !dbg !22: {[-1]:Integer}, intvals: {}
  %.not2 = icmp eq double addrspace(13)* %arrayptr4077_unwrap, %"arrayptr4077'ipl_unwrap": {[-1]:Integer}, intvals: {}
  %11 = fmul fast double %10, %19, !dbg !86: {[-1]:Float@double}, intvals: {}
  %2 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 4: {[-1]:Pointer}, intvals: {}
  %7 = add nsw i64 %arraysize18.pre, %6: {[-1]:Integer}, intvals: {}
  %5 = icmp eq i64 %storemerge, 0: {[-1]:Integer}, intvals: {}
  %arraysize18.pre = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 3: {[-1]:Integer}, intvals: {}
  %13 = fadd fast double %12, %11, !dbg !82: {[-1]:Float@double}, intvals: {}
  %arraylen = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 2, !dbg !32: {}, intvals: {}
{} addrspace(10)* %0: {[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}, intvals: {}
{} addrspace(10)* %"'": {[-1]:Pointer, [-1,0]:Pointer, [-1,0,-1]:Float@double, [-1,8]:Integer, [-1,9]:Integer, [-1,10]:Integer, [-1,11]:Integer, [-1,12]:Integer, [-1,13]:Integer, [-1,14]:Integer, [-1,15]:Integer, [-1,16]:Integer, [-1,17]:Integer, [-1,18]:Integer, [-1,19]:Integer, [-1,20]:Integer, [-1,21]:Integer, [-1,22]:Integer, [-1,23]:Integer, [-1,24]:Integer, [-1,25]:Integer, [-1,26]:Integer, [-1,27]:Integer, [-1,28]:Integer, [-1,29]:Integer, [-1,30]:Integer, [-1,31]:Integer, [-1,32]:Integer, [-1,33]:Integer, [-1,34]:Integer, [-1,35]:Integer, [-1,36]:Integer, [-1,37]:Integer, [-1,38]:Integer, [-1,39]:Integer}, intvals: {}
{ {} addrspace(10)*, i64, i64, i64, double* } %tapeArg: {[0]:Pointer, [0,0]:Pointer, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Pointer}, intvals: {}
  %8 = add nuw nsw i64 %storemerge1, %20, !dbg !86: {[-1]:Integer}, intvals: {}
  %15 = mul nsw i64 %iv, -1: {[-1]:Integer}, intvals: {0,}
  %3 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 0, !dbg !22: {[-1]:Pointer, [-1,0]:Pointer}, intvals: {}
  %6 = mul nsw i64 %iv1, -1: {[-1]:Integer}, intvals: {0,}
  %19 = fadd fast double %18, %"'de.2": {[-1]:Float@double}, intvals: {}
  %.not74 = icmp eq i64 %arraysize18.pre, 0: {[-1]:Integer}, intvals: {}
  %iv.next2 = add nuw nsw i64 %iv1, 1: {[-1]:Integer}, intvals: {1,}
  %_unwrap = shl nuw i64 %arraylen, 3, !dbg !51: {}, intvals: {}
  %.not = icmp eq i64 %arraylen, 0, !dbg !32: {[-1]:Integer}, intvals: {}
</analysis>

Cannot deduce type of memset   call void @llvm.memset.p13i8.i64(i8 addrspace(13)* align 8 %"arrayptr.pre7190'il_phi_unwrap", i8 noundef 0, i64 %_unwrap, i1 noundef false) #33, !dbg !51, !tbaa !76, !noalias !79

Caused by:
Stacktrace:
 [1] setindex!
   @ ./array.jl:1021
 [2] fill!
   @ ./array.jl:395
 [3] zeros
   @ ./array.jl:637
 [4] zeros
   @ ./array.jl:633
 [5] zeros
   @ ./array.jl:631
 [6] mvp
   @ ~/Downloads/enzyme_err.jl:4
within MethodInstance for mvp(::Matrix{Float64}, ::Vector{Float64})


Stacktrace:
  [1] setindex!
    @ ./array.jl:1021 [inlined]
  [2] fill!
    @ ./array.jl:395 [inlined]
  [3] zeros
    @ ./array.jl:637 [inlined]
  [4] zeros
    @ ./array.jl:633 [inlined]
  [5] zeros
    @ ./array.jl:631 [inlined]
  [6] mvp
    @ ~/Downloads/enzyme_err.jl:4
  [7] g
    @ ~/Downloads/enzyme_err.jl:15
  [8] f
    @ ~/Downloads/enzyme_err.jl:23 [inlined]
  [9] f
    @ ~/Downloads/enzyme_err.jl:0 [inlined]
 [10] diffejulia_f_3663_inner_1wrap
    @ ~/Downloads/enzyme_err.jl:0 [inlined]
 [11] macro expansion
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:8137 [inlined]
 [12] enzyme_call
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7703 [inlined]
 [13] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7476 [inlined]
 [14] autodiff_deferred
    @ ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:781 [inlined]
 [15] autodiff
    @ ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:512 [inlined]
 [16] f2
    @ ~/Downloads/enzyme_err.jl:42
 [17] loss
    @ ~/Downloads/enzyme_err.jl:52 [inlined]
 [18] loss
    @ ~/Downloads/enzyme_err.jl:0 [inlined]
 [19] diffejulia_loss_3263_inner_1wrap
    @ ~/Downloads/enzyme_err.jl:0
 [20] macro expansion
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:8137 [inlined]
 [21] enzyme_call
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7703 [inlined]
 [22] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7476 [inlined]
 [23] autodiff
    @ ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:491 [inlined]
 [24] autodiff(::ReverseMode{false, true, FFIABI, false, false}, ::typeof(loss), ::Type{Active}, ::Const{Vector{SVector{3, Float64}}}, ::Duplicated{Tuple{Matrix{Float64}, Vector{Float64}, Matrix{Float64}, Vector{Float64}}})
    @ Enzyme ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:512
 [25] top-level scope
    @ ~/Downloads/enzyme_err.jl:56
in expression starting at /Users/jgreener/Downloads/enzyme_err.jl:56
@wsmoses
Copy link
Member

wsmoses commented Dec 7, 2024

@jgreener64 I just landed various higher order AD fixes, did that resolve this by chance?

@jgreener64
Copy link
Contributor Author

On main (1d3b801) it errors with

freeing without malloc   %2 = extractvalue { {} addrspace(10)*, i64, i64, i64, double* } %tapeArg, 4
julia: /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::BranchInst; From = llvm::Instruction]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

[3888121] signal (6.-6): Aborted
in expression starting at REPL[13]:1
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7fee708fd728)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
cast<llvm::BranchInst, llvm::Instruction> at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/Support/Casting.h:578 [inlined]
cast<llvm::BranchInst, llvm::Instruction> at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/Support/Casting.h:577
unwrapM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:1814
lookupM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:6630
unwrapM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:1106
lookupM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:6630
unwrapM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:1106
lookupM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:6630
unwrapM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:1106
lookupM at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:6630
getReverseOrLatchMerge at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:3780
createInvertedTerminator at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:3192
CreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:4309
recursivelyHandleSubfunction at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:5742
visitCallInst at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:6479
visit at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/InstVisitor.h:111 [inlined]
CreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:4305
recursivelyHandleSubfunction at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:5742
visitCallInst at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:6479
visit at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/InstVisitor.h:111 [inlined]
CreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:4305
EnzymeCreatePrimalAndGradient at /workspace/srcdir/Enzyme/enzyme/Enzyme/CApi.cpp:633
EnzymeCreatePrimalAndGradient at /home/jgreener/.julia/dev/Enzyme/src/api.jl:268
jfptr_EnzymeCreatePrimalAndGradient_21521 at /home/jgreener/.julia/compiled/v1.10/Enzyme/G1p5n_GtoaE.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
enzyme! at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:1576
#codegen#18938 at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:4425
codegen at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:3223 [inlined]
_thunk at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:5273
_thunk at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:5273 [inlined]
cached_compilation at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:5324 [inlined]
thunkbase at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:5434
thunk_generator at /home/jgreener/.julia/dev/Enzyme/src/compiler.jl:5601
jfptr_thunk_generator_32093 at /home/jgreener/.julia/compiled/v1.10/Enzyme/G1p5n_GtoaE.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_call_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:540
ijl_code_for_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:593
get_staged at ./compiler/utilities.jl:123
retrieve_code_info at ./compiler/utilities.jl:135 [inlined]
InferenceState at ./compiler/inferencestate.jl:430
typeinf_edge at ./compiler/typeinfer.jl:920
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2889
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_edge at ./compiler/typeinfer.jl:930
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_apply at ./compiler/abstractinterpretation.jl:1612
abstract_call_known at ./compiler/abstractinterpretation.jl:2004
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2913
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_ext at ./compiler/typeinfer.jl:1051
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1082
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1078
jfptr_typeinf_ext_toplevel_35741.1 at /home/jgreener/soft/julia/julia-1.10.6/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
jl_type_infer at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:394
jl_generate_fptr_impl at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jitlayers.cpp:504
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2481 [inlined]
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2368
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2887 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
do_call at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:126
eval_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:617
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:775
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:934
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:877
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385 [inlined]
eval_user_input at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:150
repl_backend_loop at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:246
#start_repl_backend#46 at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:231
start_repl_backend at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:228
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#run_repl#59 at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:389
run_repl at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/REPL/src/REPL.jl:375
jfptr_run_repl_91949.1 at /home/jgreener/soft/julia/julia-1.10.6/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#1013 at ./client.jl:437
jfptr_YY.1013_82918.1 at /home/jgreener/soft/julia/julia-1.10.6/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
jl_f__call_latest at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/builtins.c:812
#invokelatest#2 at ./essentials.jl:892 [inlined]
invokelatest at ./essentials.jl:889 [inlined]
run_main_repl at ./client.jl:421
exec_options at ./client.jl:338
_start at ./client.jl:557
jfptr__start_82944.1 at /home/jgreener/soft/julia/julia-1.10.6/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
true_main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:582
jl_repl_entrypoint at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:731
main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/cli/loader_exe.c:58
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 14302240 (Pool: 14283630; Big: 18610); GC: 20
Aborted (core dumped)

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

No branches or pull requests

2 participants