CRTP base for fixed-arity N-input op kernels.
Inherits AutogradNode\<Derived, N\> so input metadata
(input_shapes_, saved_inputs_, input_tensors_,
saved_impl_inputs_) is stored in compile-time-sized
std::array containers. Also inherits IKernel for
polymorphic invocation.
Unlike UnaryKernel and BinaryKernel, this base does
not provide a forward() trampoline — N-ary ops have too much
op-specific validation to share a single template. Instead, derived
ops own their forward() and call wire_autograd once the
output tensor exists to attach the backward node.
Template Parameters
Derived : class
The concrete CRTP self-type.
N : std::size_t
The fixed input arity. Typically 3 or more (use
BinaryKernel for N == 2).
See Also
UnaryKernel, BinaryKernel, VariadicKernel.
IKernel — the abstract base above the CRTP layer.
Notes
Slot count is exactly N. Derived ops implement apply
(and optionally apply_for_graph) themselves; no
grad_formula contract is enforced because N-ary backward shapes
vary too widely.
Static methods
1wire_autograd
→boolbool wire_autograd(int bwd, const int & inputs, const int & out, bool save_ins)Attach an existing backward node to the autograd graph.
Parameters
bwdstd::shared_ptr<Derived>out.inputsconst std::array<TensorImplPtr, N>&nullptr (e.g. an optional bias).outconst TensorImplPtr&save_insbool, default ``true``true, snapshot each non-null input's storage into saved_inputs_[i] for use during backward.Returns
booltrue when the autograd graph was wired and out had its grad_fn installed; false when grad mode is off or no input requires a gradient (no-op).
Notes
Side effects on success: populates bwd's dtype/device/output
shape from the first non-null input, fills input_shapes_,
input_tensors_, saved_inputs_, saved_impl_inputs_,
records one Edge per input via detail::ensure_grad_fn,
captures per-input versions for in-place mutation detection, and
marks out as a non-leaf, requires_grad tensor.