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

What is ABI? #1345

Closed
gdalle opened this issue Mar 15, 2024 · 4 comments
Closed

What is ABI? #1345

gdalle opened this issue Mar 15, 2024 · 4 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Mar 15, 2024

Apparently it plays a part in the mode choice?

"""
struct ReverseMode{ReturnPrimal,ABI} <: Mode{ABI}
Reverse mode differentiation.
- `ReturnPrimal`: Should Enzyme return the primal return value from the augmented-forward.
"""

@wsmoses
Copy link
Member

wsmoses commented Jun 23, 2024

It's somewhat intentionally underdocumented at the moment.

Specifically it is used to specify how Enzyme injects the code it produces into the Julia runtime.

There's presently only one "officially" supported runtime, the DefaultABI aka FFIABI (in which we inject the code into Julia's JIT after we run our own separate compilation).

There's a second "hidden" ABI, InlineABI, which basically causes Enzyme to emit things as an inline llvmcall. It's mostly used by Enzyme devs for debugging, but may also enable support with precompilation. That said the reason it's hidden is that @vchuravy is skeptical of the integration with other components so we intentionally haven't advertised it.

@wsmoses
Copy link
Member

wsmoses commented Jun 23, 2024

If curious for specifics, see below:

julia> @code_llvm Enzyme.autodiff(Reverse, sin, Active(3.0))
;  @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:317 within `autodiff`
define [1 x [1 x double]] @julia_autodiff_2864([1 x double]* nocapture noundef nonnull readonly align 8 dereferenceable(8) %0) #0 {
guard_exit5:
  %memcpy_refined_src = getelementptr inbounds [1 x double], [1 x double]* %0, i64 0, i64 0
  %1 = load double, double* %memcpy_refined_src, align 8
;  @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:318 within `autodiff` @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:333 @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:309
; ┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6067 within `CombinedAdjointThunk`
; │┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6190 within `enzyme_call`
; ││┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6589 within `macro expansion`
     %2 = call [1 x [1 x double]] inttoptr (i64 5353095168 to [1 x [1 x double]] (double, double)*)(double %1, double 1.000000e+00)
     ret [1 x [1 x double]] %2
; └└└
}

julia> @code_llvm Enzyme.autodiff(ReverseMode{false, InlineABI, false}(), sin, Active(3.0))
;  @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:317 within `autodiff`
define [1 x [1 x double]] @julia_autodiff_2934([1 x double]* nocapture noundef nonnull readonly align 8 dereferenceable(8) %0) #0 {
guard_exit5:
  %memcpy_refined_src = getelementptr inbounds [1 x double], [1 x double]* %0, i64 0, i64 0
  %1 = load double, double* %memcpy_refined_src, align 8
;  @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:318 within `autodiff` @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:333 @ /Users/wmoses/git/Enzyme.jl/src/Enzyme.jl:309
; ┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6067 within `CombinedAdjointThunk`
; │┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6190 within `enzyme_call`
; ││┌ @ /Users/wmoses/git/Enzyme.jl/src/compiler.jl:6596 within `macro expansion`
     %2 = call fast double @llvm.cos.f64(double %1)
     %unbox3.fca.0.0.insert = insertvalue [1 x [1 x double]] zeroinitializer, double %2, 0, 0
     ret [1 x [1 x double]] %unbox3.fca.0.0.insert
; └└└
}

@gdalle
Copy link
Contributor Author

gdalle commented Jun 24, 2024

Thanks for the details!

It's somewhat intentionally underdocumented at the moment.

For the record, I don't think that should ever be a thing. I understand the lack of time and hands to write docs, but refusing to document something because someone else might use it is different.
It's more of a problem with Julia where "the docs is the API", but one can still put this stuff in the "private / internals" part of the API reference?

@wsmoses
Copy link
Member

wsmoses commented Sep 28, 2024

there are some (admittedly breif) docs, closing

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

2 participants