Hessian failure, enzyme_const global unrecognzied(?)
- Dominant language
- LLVM
- Stars
- 1.7k
- Forks
- 188
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 26
Description
While looking at https://github.com/rust-lang/rust/issues/160470#issuecomment-5185373594, I noticed a different enzyme failure:
`opt bar.ll -load-pass-plugin=enzyme-23.so -passes="enzyme" -enzyme-strict-aliasing=0`
```
error: :0:0: in function preprocess_bar void (ptr, i64): Enzyme: No forward mode derivative found for __enzyme_autodiff
at context: %3 = call {} (...) @__enzyme_autodiff(ptr @baz, ptr @enzyme_const, ptr %0, ptr @enzyme_const, i64 %1) #1
error: :0:0: in function fwddiffebar void (ptr, ptr, i64): Enzyme: Cannot cast __enzyme_autodiff primal argument 3, found ptr %0, type ptr (simplified to ptr %0 ) - to arg 1, i64
```
Presumably enzyme doesn't recognize named globals in nested autodiff calls, which then makes the outer fwddiff call fall as well?
```llvm
; ModuleID = 'std-ca0eb62edd1eb486.std.a58e486c150d32d8-cgu.0.rcgu.o'
source_filename = "std.a58e486c150d32d8-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@enzyme_const = external global ptr
@enzyme_dup = external global ptr
; Function Attrs: nonlazybind uwtable
define internal void @outer(ptr align 8 %0, i64 %1, ptr align 8 %2) {
%20 = call {} (...) @__enzyme_fwddiff(ptr @foo, ptr @enzyme_dup, ptr %0, ptr %2, ptr @enzyme_const, i64 %1)
ret void
}
; Function Attrs: nonlazybind uwtable
define internal void @foo(ptr align 8 %0, i64 %1) {
call void @bar(ptr align 8 %0, i64 %1)
ret void
}
declare {} @__enzyme_fwddiff(...)
; Function Attrs: nonlazybind uwtable
define internal void @bar(ptr align 8 %0, i64 %1) {
%5 = call {} (...) @__enzyme_autodiff(ptr @baz, ptr @enzyme_const, ptr %0, ptr @enzyme_const, i64 %1)
ret void
}
; Function Attrs: nonlazybind uwtable
define internal void @baz(ptr align 8 %0, i64 %1) {
ret void
}
declare {} @__enzyme_autodiff(...)
```
Contributor guide
Research direction
Use the reported opt command and LLVM IR reproducer as the entry point. Trace how nested __enzyme_autodiff calls handle the named @enzyme_const and @enzyme_dup globals; done means the reproducer no longer reports the missing forward derivative or the incorrect primal-argument cast.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100