Documentation
¶
Overview ¶
Package backend defines how `luxfi/math` selects between CPU and GPU implementations of the same primitive.
LP-107 §"Backend dispatch" — the canonical motivation. Backends are interchangeable performance realizations of one canonical contract; KATs prove byte-equality across them; the choice of backend MUST NEVER alter transcript bytes for consensus paths.
Policy enum:
BackendPureGo — pure-Go reference implementation. Always works. BackendNativeCPU — native CPU implementation (cgo + C++/SIMD). BackendGPUPreferred — try GPU; fall back to CPU on unavailability. BackendGPURequired — GPU MUST be available; error if not.
Registry: each substrate package (math/ntt, math/poly, math/sample, math/codec, math/rns) exposes its own backend interface and a process-wide registry of registered backends. This package owns the shared Policy enum + lookup helper; per-primitive interfaces live in the consuming package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrUnavailable signals that a required backend is not present in the process. Returned by ResolveOrError when PolicyGPURequired is set but no GPU backend is registered.
Functions ¶
func Resolve ¶
Resolve returns the appropriate BackendID for the given policy and the set of registered backends. The order of preference is:
PolicyGPURequired: GPU only — error if no GPU registered PolicyGPUPreferred: GPU > native-cpu > pure-go PolicyNativeCPU: native-cpu > pure-go PolicyPureGo: pure-go only
This function is the single decision point for dispatch ordering. Per-primitive packages (math/ntt, math/poly, etc.) consult it before invoking a backend.
Types ¶
type Policy ¶
type Policy uint8
Policy selects a backend at dispatch time.
const ( // PolicyPureGo forces the pure-Go reference path. Used for // debugging, incident response, and consensus-critical paths // where determinism trumps speed. PolicyPureGo Policy = 0 // PolicyNativeCPU prefers the native-cpu (cgo / SIMD) backend if // available; falls back to pure-Go otherwise. PolicyNativeCPU Policy = 1 // PolicyGPUPreferred prefers GPU if available, falls back to native- // CPU, then pure-Go. Used when the workload amortizes GPU dispatch. PolicyGPUPreferred Policy = 2 // PolicyGPURequired demands GPU; the call errors out if no GPU // backend is registered. PolicyGPURequired Policy = 3 )