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 derivative computation not working for certain functions #2253

Open
Arpit-Babbar opened this issue Jan 6, 2025 · 1 comment
Open

Comments

@Arpit-Babbar
Copy link

The feature to compute derivatives beyond second has been recently added to Enzyme in #2161, so this issue (concerning only the second) may be related to that.

Basically, I can compute the second derivative of $f(x) = x^4 + x^7$ but not of $f(x) = x^4$. Here is the code that reproduces it

using Enzyme

function second_derivative(f, x, z, w)
    autodiff(Forward,
        (x,dx) -> autodiff(Forward, f, Duplicated, Duplicated(x, dx))[1],
        Duplicated, Duplicated(x, z), Duplicated(z, w))[1]
end

function f_works(x)
    x[1]^4 + x[1]^7
end

function f_crashes(x)
    x[1]^4
end

second_derivative(f_works, 1.0, 1.0, 1.0) # works
second_derivative(f_crashes, 1.0, 1.0, 1.0) # crashes

This is the error message

Error message

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12112(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12112(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12161(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12161(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12170(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12170(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12179(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12179(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12205(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12205(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

Incorrect number of arguments passed to called function!
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
; Function Attrs: mustprogress nofree willreturn memory(read, argmem: none, inaccessiblemem: none)
define "enzyme_type"="{[-1]:Float@double}" double @preprocess_julia__1_12214(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1) local_unnamed_addr #6 !dbg !69 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !70
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !71, !noalias !74
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !76, !noalias !79
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !81
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !88
  %6 = fmul fast double %1, 4.000000e+00, !dbg !88
  %7 = fmul fast double %6, %5, !dbg !88
  ret double %7, !dbg !90
}

; Function Attrs: mustprogress nofree
define internal double @fwddiffejulia__1_12214(double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %0, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'", double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %1, double "enzyme_type"="{[-1]:Float@double}" "enzymejl_parmtype"="140045604181472" "enzymejl_parmtype_ref"="0" %"'1") local_unnamed_addr #7 !dbg !91 {
top:
  %pgcstack = call {}*** @julia.get_pgcstack() #8
  %ptls_field3 = getelementptr inbounds {}**, {}*** %pgcstack, i64 2
  %2 = bitcast {}*** %ptls_field3 to i64***
  %ptls_load45 = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !92, !noalias !95
  %3 = getelementptr inbounds i64*, i64** %ptls_load45, i64 2
  %safepoint = load i64*, i64** %3, align 8, !tbaa !18, !alias.scope !97, !noalias !100
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint) #8, !dbg !102
  fence syncscope("singlethread") seq_cst
  %ptls_load45.i.i = load i64**, i64*** %2, align 8, !tbaa !14, !alias.scope !103, !noalias !104
  %4 = getelementptr inbounds i64*, i64** %ptls_load45.i.i, i64 2
  %safepoint.i.i = load i64*, i64** %4, align 8, !tbaa !18, !alias.scope !105, !noalias !108
  fence syncscope("singlethread") seq_cst
  call void @julia.safepoint(i64* %safepoint.i.i) #8, !dbg !110
  fence syncscope("singlethread") seq_cst
  %5 = call fastcc double @julia___12026(double %0) #8, !dbg !117
  %6 = fcmp fast oeq double %"'", 0.000000e+00, !dbg !117
  %7 = and i1 false, %6, !dbg !117
  %8 = or i1 false, %7, !dbg !117
  %9 = call fast fastcc double @julia___12026(double %0, double (double)* @julia___12026), !dbg !117
  %10 = fmul fast double sitofp (double (double)* @julia___12026 to double), %9, !dbg !117
  %11 = fmul fast double %"'", %10, !dbg !117
  %12 = select fast i1 %8, double 0.000000e+00, double %11, !dbg !117
  %13 = fmul fast double %1, 4.000000e+00, !dbg !117
  %14 = fmul fast double %"'1", 4.000000e+00, !dbg !117
  %15 = fmul fast double %14, %5, !dbg !119
  %16 = fmul fast double %12, %13, !dbg !119
  %17 = fadd fast double %15, %16, !dbg !119
  ret double %17
}

ERROR: LoadError: LLVM error: function failed verification (4)
Stacktrace:
  [1] handle_error(reason::Cstring)
    @ LLVM ~/.julia/packages/LLVM/wMjUU/src/core/context.jl:194
  [2] EnzymeCreateForwardDiff(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{…}, TA::Enzyme.TypeAnalysis, returnValue::Bool, mode::Enzyme.API.CDerivativeMode, runtimeActivity::Bool, width::Int64, additionalArg::Ptr{…}, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{…})
    @ Enzyme.API ~/.julia/packages/Enzyme/R6sE8/src/api.jl:334
  [3] enzyme!(job::GPUCompiler.CompilerJob{…}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::NTuple{…} where N, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{…}, boxedArgs::Set{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:1745
  [4] codegen(output::Symbol, job::GPUCompiler.CompilerJob{…}; libraries::Bool, deferred_codegen::Bool, optimize::Bool, toplevel::Bool, strip::Bool, validate::Bool, only_entry::Bool, parent_job::Nothing)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:4550
  [5] codegen
    @ ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:3353 [inlined]
  [6] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget, Enzyme.Compiler.EnzymeCompilerParams}, postopt::Bool)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:5410
  [7] _thunk
    @ ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:5410 [inlined]
  [8] cached_compilation
    @ ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:5462 [inlined]
  [9] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{…}, A::Type{…}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::NTuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, edges::Vector{…})
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:5573
 [10] thunk_generator(world::UInt64, source::LineNumberNode, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::NTuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, self::Any, fakeworld::Any, fa::Type, a::Type, tt::Type, mode::Type, width::Type, modifiedbetween::Type, returnprimal::Type, shadowinit::Type, abi::Type, erriffuncwritten::Type, runtimeactivity::Type)
    @ Enzyme.Compiler ~/.julia/packages/Enzyme/R6sE8/src/compiler.jl:5758
 [11] autodiff
    @ ~/.julia/packages/Enzyme/R6sE8/src/Enzyme.jl:640 [inlined]
 [12] autodiff(::ForwardMode{false, FFIABI, false, false}, ::var"#1#2"{typeof(f_crashes)}, ::Type{Duplicated}, ::Duplicated{Float64}, ::Duplicated{Float64})
    @ Enzyme ~/.julia/packages/Enzyme/R6sE8/src/Enzyme.jl:524
 [13] second_derivative(f::Function, x::Float64, z::Float64, w::Float64)
    @ Main ~/repositories/2024_ad_lw_dev/TenkaiAD/misc/weird_enzyme_bug.jl:4
 [14] top-level scope
    @ ~/repositories/2024_ad_lw_dev/TenkaiAD/misc/weird_enzyme_bug.jl:18
 [15] include(fname::String)
    @ Main ./sysimg.jl:38
 [16] top-level scope
    @ REPL[6]:1
in expression starting at /uni-mainz.de/homes/ababbar/repositories/2024_ad_lw_dev/TenkaiAD/misc/weird_enzyme_bug.jl:18
Some type information was truncated. Use `show(err)` to see complete types.


versioninfo()
Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 104 × Intel(R) Xeon(R) Gold 5320 CPU @ 2.20GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, icelake-server)
Threads: 1 default, 0 interactive, 1 GC (on 104 virtual cores)

I am using Enzyme v0.13.28. Along with the above Intel processor, this issue also occurs on a Mac M3 pro processor.

@Arpit-Babbar
Copy link
Author

It seems to be the same as #2102.

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

No branches or pull requests

1 participant