EnzymeCore.ABIType
abstract type ABI

Abstract type for what ABI will be used.

EnzymeCore.ActiveType
Active(x)

Mark a function argument x of autodiff as active, Enzyme will auto-differentiate in respect Active arguments.

Note

Enzyme gradients with respect to integer values are zero. Active will automatically convert plain integers to floating point values, but cannot do so for integer values in tuples and structs.

EnzymeCore.BatchDuplicatedType
BatchDuplicated(x, ∂f_∂xs)

Like Duplicated, except contains several shadows to compute derivatives for all at once. Argument ∂f_∂xs should be a tuple of the several values of type x.

EnzymeCore.BatchDuplicatedNoNeedType
BatchDuplicatedNoNeed(x, ∂f_∂xs)

Like DuplicatedNoNeed, except contains several shadows to compute derivatives for all at once. Argument ∂f_∂xs should be a tuple of the several values of type x.

EnzymeCore.ConstType
Const(x)

Mark a function argument x of autodiff as constant, Enzyme will not auto-differentiate in respect Const arguments.

EnzymeCore.DuplicatedType
Duplicated(x, ∂f_∂x)

Mark a function argument x of autodiff as duplicated, Enzyme will auto-differentiate in respect to such arguments, with dx acting as an accumulator for gradients (so $\partial f / \partial x$ will be added to) ∂f_∂x.

EnzymeCore.DuplicatedNoNeedType
DuplicatedNoNeed(x, ∂f_∂x)

Like Duplicated, except also specifies that Enzyme may avoid computing the original result and only compute the derivative values.

EnzymeCore.FFIABIType
struct FFIABI <: ABI

Foreign function call ABI. JIT the differentiated function, then inttoptr call the address.

EnzymeCore.ModeType
abstract type Mode

Abstract type for what differentiation mode will be used.

EnzymeCore.ReverseModeType
struct ReverseMode{ReturnPrimal,ABI,Holomorphic} <: Mode{ABI}

Reverse mode differentiation.

  • ReturnPrimal: Should Enzyme return the primal return value from the augmented-forward.
  • ABI: What runtime ABI to use
  • Holomorphic: Whether the complex result function is holomorphic and we should compute d/dz
EnzymeCore.ReverseModeSplitType
struct ReverseModeSplit{ReturnPrimal,ReturnShadow,Width,ModifiedBetween,ABI} <: Mode{ABI}

Reverse mode differentiation.

  • ReturnPrimal: Should Enzyme return the primal return value from the augmented-forward.
  • ReturnShadow: Should Enzyme return the shadow return value from the augmented-forward.
  • Width: Batch Size (0 if to be automatically derived)
  • ModifiedBetween: Tuple of each argument's modified between state (true if to be automatically derived).
EnzymeCore.make_zeroFunction
make_zero(::Type{T}, seen::IdDict, prev::T, ::Val{copy_if_inactive}=Val(false))::T

Recursively make a zero'd copy of the value `prev` of type `T`. The argument `copy_if_inactive` specifies
what to do if the type `T` is guaranteed to be inactive, use the primal (the default) or still copy the value.
EnzymeCore.EnzymeRules.AugmentedReturnType
AugmentedReturn(primal, shadow, tape)

Augment the primal return value of a function with its shadow, as well as any additional information needed to correctly compute the reverse pass, stored in tape.

Unless specified by the config that a variable is not overwritten, rules must assume any arrays/data structures/etc are overwritten between the forward and the reverse pass. Any floats or variables passed by value are always preserved as is (as are the arrays themselves, just not necessarily the values in the array).

See also augmented_primal.

EnzymeCore.EnzymeRules.ConfigType
Config{NeedsPrimal, NeedsShadow, Width, Overwritten}
ConfigWidth{Width} = Config{<:Any,<:Any, Width}

Configuration type to dispatch on in custom reverse rules (see augmented_primal and reverse).

  • NeedsPrimal and NeedsShadow: boolean values specifying whether the primal and shadow (resp.) should be returned.
  • Width: an integer that specifies the number of adjoints/shadows simultaneously being propagated.
  • Overwritten: a tuple of booleans of whether each argument (including the function itself) is modified between the forward and reverse pass (true if potentially modified between).

Getters for the four type parameters are provided by needs_primal, needs_shadow, width, and overwritten.

EnzymeCore.EnzymeRules.augmented_primalFunction
augmented_primal(::Config, func::Annotation{typeof(f)}, RT::Type{<:Annotation}, args::Annotation...)

Must return an AugmentedReturn type.

  • The primal must be the same type of the original return if needs_primal(config), otherwise nothing.
  • The shadow must be nothing if needs_shadow(config) is false. If width is 1, the shadow should be the same type of the original return. If the width is greater than 1, the shadow should be NTuple{original return, width}.
  • The tape can be any type (including Nothing) and is preserved for the reverse call.
EnzymeCore.EnzymeRules.forwardFunction
forward(func::Annotation{typeof(f)}, RT::Type{<:Annotation}, args::Annotation...)

Calculate the forward derivative. The first argument func is the callable for which the rule applies to. Either wrapped in a Const), or a Duplicated if it is a closure. The second argument is the return type annotation, and all other arguments are the annotated function arguments.

EnzymeCore.EnzymeRules.inactiveFunction
inactive(func::typeof(f), args...)

Mark a particular function as always being inactive in both its return result and the function call itself.

EnzymeCore.EnzymeRules.inactive_noinlFunction
inactive_noinl(func::typeof(f), args...)

Mark a particular function as always being inactive in both its return result and the function call itself, but do not prevent inlining of the function.

EnzymeCore.EnzymeRules.reverseFunction
reverse(::Config, func::Annotation{typeof(f)}, dret::Active, tape, args::Annotation...)
reverse(::Config, func::Annotation{typeof(f)}, ::Type{<:Annotation), tape, args::Annotation...)

Takes gradient of derivative, activity annotation, and tape. If there is an active return dret is passed as Active{T} with the derivative of the active return val. Otherwise dret is passed as Type{Duplicated{T}}, etc.