Context
Section 10 types handle f(args) with reverseMode as a nested pair
(primal, (grads…)) and builds that pair in IR. The emitter then prints
func.func @main() with no results, because infer_type only accepts
tensors. Section 11 therefore takes g as an explicit argument.
MLIR tuple<> types do not bufferize on the existing
one-shot-bufferize + LLVM C-wrapper path. The bootstrap surface also
cannot write a one-element tuple type (T), so a nested
(primal, (g)) cannot be used as a fn annotation.
Decision
Specify the ABI in
12-reversemode-result-abi.md:
- Language type is the flat tuple
(primal, g₀, …, gₙ₋₁). - Lowering is MLIR multi-result
func.func, nottuple<>. - Host
.soloads use an existingllvm.emit_c_interfacefnwhose body ishandle f(x) with reverseMode. - Do not add tuple projection,
@mainarguments, or a new operator.
Consequences
ad_neg/ad_nll/ other reverse-mode goldens gain@mainresults.- A wrapper example can return Kina-executed gradients from a
.so. - Loss → VJP → SGD in one
@mainstill waits on naming those results inside.kina.