Backend Capsules #
A backend capsule is TorchLean's unit of delegation to fast code.
The capsule does not prove the foreign implementation. It records the contract TorchLean expects from that implementation: which op it implements, which spec it refines, what layout and shape conventions are assumed, how the value/VJP claims are justified, and what trust level the planner must account for.
A source file inside the TorchLean checkout that supports a backend contract.
- path : String
Instances For
Instances For
Reference to a native/FFI symbol used by a backend capsule.
The linter checks that path exists, that symbol occurs in that source file, and that
buildTarget?, when present, names a Lake target in lakefile.lean.
Instances For
Instances For
Instances For
Whether a selected capsule is wired to an executable runtime path.
- eager : RuntimeSupport
The capsule can be selected by an eager runtime path.
- testOnly : RuntimeSupport
The capsule has a direct bridge/check, but is not selected by the eager runtime yet.
- plannerOnly : RuntimeSupport
The capsule is useful for planning/auditing only.
- notWired : RuntimeSupport
The capsule is intentionally registered before runtime wiring exists.
Instances For
Source-level provenance for a contract descriptor. Provenance is not correctness evidence.
- sourceFile (ref : SourceRef) : ContractProvenance
- nativeSymbol (ref : NativeSymbolRef) : ContractProvenance
- note (text : String) : ContractProvenance
Instances For
Instances For
Instances For
Instances For
Concrete tensor-layout convention named by a backend contract.
- canonicalTensor : TensorLayout
TorchLean's ordinary typed tensor representation.
- flatRowMajor : TensorLayout
Contiguous flat storage with the last axis varying fastest.
- libTorchCudaView : TensorLayout
A contiguous CUDA tensor view owned by LibTorch.
Instances For
A structured backend obligation, independent of how evidence for it is obtained.
- shapeSafety
(op : BackendOp)
: ContractClaim
Inputs and outputs satisfy the shape rule associated with an operation.
- layoutCompatibility
(op : BackendOp)
(layout : TensorLayout)
: ContractClaim
Runtime buffers use the declared layout for an operation.
- valueRefinement
(op : BackendOp)
(specName : String)
: ContractClaim
Forward execution refines the named mathematical specification.
- vjpRefinement
(op : BackendOp)
(specName : String)
(mode : VJPMode)
: ContractClaim
Local backward execution refines the named VJP specification.
Instances For
Instances For
How a capsule justifies one part of its contract.
runtimeGuard and testSuite record useful engineering assurance but do not discharge a theorem.
Only theorem and checker contain proof terms.
- theorem (theoremName : String) (statement : Prop) (proof : statement) : ContractEvidence
- checker (checkerName : String) (statement : Prop) (accepted : Bool) (sound : accepted = true → statement) (acceptanceProof : accepted = true) : ContractEvidence
- runtimeGuard (name : String) : ContractEvidence
- testSuite (name : String) : ContractEvidence
- fuzzOracle (name : String) : ContractEvidence
- trustedBoundary (reason : String) : ContractEvidence
- notProvided : ContractEvidence
Instances For
A structured contract claim together with its evidence and human-readable explanation.
- claim : ContractClaim
- summary : String
- evidence : ContractEvidence
- provenance : List ContractProvenance
Instances For
A contract claim enforced by a named runtime guard.
Instances For
A contract claim covered by a named regression suite.
Instances For
A contract claim delegated to an explicitly named trusted boundary.
Instances For
The four contract fields carried by every kernel capsule.
- shape : ContractObligationKind
- layout : ContractObligationKind
- value : ContractObligationKind
- vjp : ContractObligationKind
Instances For
Instances For
Whether a claim has the expected kind and operation for a capsule contract field.
Instances For
A contract-carrying fast kernel or reference implementation.
- name : String
- op : BackendOp
- provider : Provider
- device : Device
- specName : String
- trustLevel : TrustLevel
- supportsForward : Bool
- vjpMode : VJPMode
- runtimeSupport : RuntimeSupport
- shapeContract : ContractDescriptor
- layoutContract : ContractDescriptor
- valueContract : ContractDescriptor
- vjpContract : ContractDescriptor
- notes : String
Instances For
Whether each descriptor states the obligation advertised by its field.
Evidence is useful only when it proves or checks the right claim. This guard prevents, for example, a value-refinement theorem from being placed in the shape field and then accepted as shape evidence.
Instances For
Stable identity used when adjacent graph nodes select the same registered capsule.
Instances For
Whether the trust policy admits this capsule.
Instances For
Whether the backend preference admits this capsule's provider.
Instances For
Whether this capsule is available on the selected device.
Instances For
Whether the capsule's gradient boundary is compatible with the requested execution config.
none is inference mode, so any forward-capable capsule is suitable even when it also advertises a
VJP. externalAutograd is intentionally opt-in. A native backend VJP is still compatible with the
normal TorchLean tape mode: the TorchLean tape owns the node and calls the backend for the local VJP.
Instances For
Planner-side admissibility predicate for a single capsule.
Instances For
Pick the first admissible capsule for a typed operation.