18 KiB
Fixed CUDA f32 vector-add requirements
Bounded STRA-102 requirements for plan
05e21fde-510e-4d63-8aa1-442e67339961, written before implementation on
base 0383253c6011ec795aa395b613405263f63378ee.
This unit supplies one opt-in, typed operation over owned CUDA buffers:
out[i] = add.rn.f32(a[i], b[i]). A successful return must mean the attempted
launch completed and the caller's previous context was restored. Validation
errs toward refusal before native mutation; uncertain completion or restoration
errs toward poisoning and retaining resources. These properties can support
bounded wrapper/ABI claims after their respective gates; they cannot establish
model support or numerical execution merely from a mock or compilation.
The historical bootstrap contract and its actual 12-symbol qualification receipts remain unchanged. This document owns only the extension below. The charter remains the project goal and quality authority; this unit advances the independent Rust NVIDIA execution foundation without changing production serving or the imported Strata engine.
Scope and caller outcome
An internal engine developer can explicitly enable the cuda-driver feature,
load the driver, create a private context, allocate/upload two input buffers and
an output buffer, invoke the fixed add operation and read the completed output.
The safe interface accepts owned buffer references and returns structured errors;
it accepts no PTX, module image, entry name, stream, launch geometry, raw pointer,
foreign context or callback from a caller.
The existing default feature remains off. No new HTTP endpoint, worker switch, backend/model admission, scheduler, tensor loader, inference implementation or production deployment integration is included. Deployment of this foundation must continue to require only the installed NVIDIA driver rather than Strata, Python, a C compiler or CUDA Toolkit; offline verification tools are separate.
Requirements and acceptance conditions
FR-VADD-1 — validate owned shapes before mutation
- Accept two immutable input buffers and one mutable output buffer belonging to
the exact same owned
Contextinstance. Equal device ordinals or separate contexts on the same GPU do not establish ownership equality. - All three byte lengths must be equal, nonzero and divisible by four; interpret
them as f32 elements. The element count must fit
u32, byte bounds must retain the bootstrap's checked budget/isizeconstraints, and grid arithmetic must be checked without truncation or overflow. - Preserve safe aliasing: inputs may refer to the same immutable allocation; output must not alias an input. The public borrow contract must enforce this, with defensive identity refusal wherever implementation structure permits otherwise. No unsafe bypass is exposed publicly.
- Reject invalid ownership, shape/count/geometry, unavailable capability and poisoned contexts before push, module load, lookup or launch. Do not mutate output or allocation accounting on validation refusal. Do not allocate new device buffers implicitly for this operation.
FR-VADD-2 — one trusted module and function
- Embed a bounded, NUL-terminated PTX byte sequence in the crate. It contains
exactly the fixed entry
leleka_vector_add_f32with parameters in this order: input A u64 device address, input B u64 device address, output u64 device address, element count u32. Treat pointers as private ABI values, never public Rust handles. Record the exact embedded bytes' SHA256 for verification. - The entry checks
i < nbefore any element access; address arithmetic must not wrap. Every in-range thread reads the corresponding A/B elements and writes exactly one output element. No input writes, external symbols, indirect calls, atomics, shared-memory state or out-of-range writes. - Use explicit
add.rn.f32without.ftz, saturation, approximate arithmetic or floating-point contraction. Nofma/madsubstitutes for the add. The selected fixed image uses PTX 7.0,sm_75, and.address_size 64; unsupported driver/target combinations fail explicitly, not by selecting another kernel. - Cache at most one successfully loaded module/function per context, lazily after validation. Repeated successful calls reuse it. Publish a cache entry only after both load and function lookup succeeded with valid non-null handles. Failed initialization must not create a usable partial cache.
The arithmetic spelling is grounded in NVIDIA's archived PTX floating-point add specification. This is the required arithmetic, not evidence that real hardware has executed it. Signed zeros, subnormal handling, overflow, infinities, NaNs and NaN payload behavior still require explicit installed-driver numerical qualification.
FR-VADD-3 — fixed 16-symbol loader and launch ABI
Extend the bootstrap's fixed twelve symbols by precisely these four:
| Symbol | Private C ABI parameters | Return |
|---|---|---|
cuModuleLoadData |
CUmodule*, const void* |
CUresult |
cuModuleGetFunction |
CUfunction*, CUmodule, const char* |
CUresult |
cuModuleUnload |
CUmodule |
CUresult |
cuLaunchKernel |
CUfunction, six unsigned int grid/block dimensions, unsigned int shared bytes, CUstream, void** kernelParams, void** extra |
CUresult |
All sixteen resolve before cuInit; each missing extension symbol must fail
before initialization. Keep the legacy bootstrap _v2 signatures, soname,
library lifetime and platform guards. Opaque module/function/stream pointers
remain inside audited private FFI. The ABI references are NVIDIA's archived
module management
and execution control
documentation. Independent advisory verification checked the official pinned
cudart 13.0.88 archive (1,491,604 bytes, SHA256
bc44226f069402ab327bcf9e754660621aa6bc61fb7fc6afe03b794dfaaab658)
and cuda.h SHA256
64025f81a9d6d2b10e9e11654f3523e5b046d01b883f0b9ca474e463274b80d4.
Header lines 7365/7476/7532 identify load/unload/function lookup; lines
17537–17547 identify launch with seven unsigned-int arguments including shared
bytes. This is header evidence, not an execution result.
Launch one dimension with fixed block size 128, grid.x = ceil(n / 128);
grid/block y and z are one, shared memory is zero, stream is null, extra is
null. kernelParams is a private four-entry array of pointers to the typed
argument values above. Own the scalar/device-address parameter storage and
pointer table, keeping their addresses stable through launch and synchronization.
If the table references fields of its own storage object, establish those pointers
only after stable heap placement; moving an inline self-referential object must
not invalidate them. NVIDIA's documentation describes copying parameter values
from the supplied regions, but this contract does not infer a stronger
before-return timing guarantee from that wording;
if completion is uncertain, retain any storage the driver could still reference
and poison future work. No caller host pointer or arbitrary argument escapes
into this interface. Compute the grid in a wider
integer and require grid.x <= i32::MAX. Kernel index/address arithmetic must
cover the final partial block without u32 overflow or reading beyond n.
No caller can alter this launch shape. The driver may still reject this fixed
shape on unsupported hardware; that is a reported operation failure.
FR-VADD-4 — completion and context restoration
- Push the owned context for module/launch operations and pop it on all paths after a successful push, checking that the popped handle is the owned one. Successful operations and handled failures restore the prior caller context; a failed or mismatched pop reports the failure and poisons this context.
- After every attempted
cuLaunchKernel, synchronize even when launch returns an error. Retain the launch error and subsequent synchronization/pop errors in their operation order; cleanup must not replace the original error. A lookup/load failure before launch is not a launch attempt. - Return success only after launch, synchronization and restoration all succeed. Inputs stay immutable; output contents after a native execution failure are unspecified and must not be reported as a successfully computed vector.
- Synchronization failure means completion is uncertain: poison the context, reject future allocation/copy/sync/kernel work without further native work, and keep possibly referenced buffers/module alive until safe context teardown. Do not free or unload them merely because a failed launch was observed.
- Continue the bootstrap's staged-copy rule, including keeping ambiguous host DMA staging alive. A fixed kernel must not weaken existing copy/borrow safety.
FR-VADD-5 — module ownership and failure cleanup
- Module/function cache lifetime is inside its owner context and dynamic-library
lifetime. No public module or function can outlive that context or cross a
thread; retain the existing
!Send/!Syncresource guarantees. - On function lookup failure after module load, attempt unload in the owned current context. Consume the module's usable-handle slot before calling unload, regardless of its return value; unload at most once per handle. A failed unload poisons the context. Retain only context-owned residual/accounting for final destruction: never retry unload, reuse the handle or reinitialize a healthy cache after that failure. If restoration is uncertain, likewise report all relevant errors and forbid treating the module as a valid kernel.
- Healthy teardown unloads the cached module after completed work, in the owned context, before destroying the context. Pending/uncertain work must not be followed by explicit module unload or buffer free. Context destruction is the final containment attempt; permanent driver failures cannot be called cleaned.
- Explicit fallible close reports unload/restoration/destruction failures; destruction should still be attempted when safe. Drop remains best effort and nonpanicking. Failed destroy retains the library as required by the bootstrap rather than permitting calls through an unloaded library.
- No automatic retries of a failed launch. Repeated poisoned contexts can retain resources; this unit supplies no process-wide recovery or cumulative resource bound and must not advertise a leak-free serving guarantee.
Security and non-functional contract
| Dimension | Metric / threshold | Planned verification |
|---|---|---|
| Critical usability | One typed add action; structured errors, no raw pointer/module interface | Public API review and synthetic caller |
| Reliability | Success requires launch + completion + restoration; zero silent launch retries | Fault matrix and trace order |
| Performance | No speed/SLO assertion; one launch and one mandatory completion sync per valid call | ABI trace, separate future paired benchmark |
| Capacity | One cached module/context; fixed block128; checked count/grid and existing byte budget | Boundary/refusal and repeated-call tests |
| Security / isolation | Exact context ownership, private fixed PTX/entry, no safe arbitrary execution surface | Cross-context/alias/ABI review and compile refusals |
| Audit / retention | Only owned synthetic traces; no model/request/credentials in Git; private evidence outside source | Harness output and cleanup review |
| Observability | Fixed operation names, driver codes, ordered primary/cleanup errors; no pointers or PTX dumps in error text | Fault assertions and error-text inspection |
| Accessibility / i18n | No UI is introduced; existing user interfaces/locales remain unchanged | Changed-surface review |
| Rate / admission | One synchronous call on the creating thread; existing per-context memory budget; no new network/tenant admission | Thread/lifetime gates and budget refusals |
| Deploy / rollback | Default feature off, no serving consumer, no deployment-tool dependency added; disable opt-in to return to existing path | Feature/default/dependency/consumer review |
| Support | Load/lookup/launch/completion/cleanup failures remain diagnosable; no production support SLA is claimed | Error matrix and documented residuals |
| AI dependence | This fixed arithmetic operation performs no model call; no AI output or quality gate substituted by it | Consumer/source review |
| Integrity | Inputs unchanged; output published as success only for completed add; no hidden persistent state except bounded cache | Synthetic data/canaries and cache traces |
| Backup / recovery | No durable data introduced; failed driver teardown is reported/retained, not treated as recovery | Fault/ownership review |
| Privacy | Only sanitized synthetic vectors permitted in this unit's verification | Fixture and artifact review |
| Maintainability | Four additional exact symbols, one embedded module/entry, no new normal dependency | Source/ABI/dependency review |
| Compatibility | Linux 64-bit opt-in only; legacy12 bindings and existing33 mock/10 compile guards preserved | Default/platform and regression gates |
| Cost / efficiency | CPU mock/tooling work only for this delivery; no GPU/probe/model access, no duplicated CI | Recorded commands and container guards |
Verification plan — outcomes not yet measured
The planned instruments derive from the requirements and official ABI, rather than obtaining expected outputs from the wrapper implementation. A synthetic mock can witness argument/context/cleanup behavior and expected fixture data; it does not execute or establish correctness of the embedded PTX instructions.
| Gate | Required checks / predicted refusal | Claim licensed by a pass |
|---|---|---|
| Existing regression | Retain all 33 bootstrap mock cases and 10 compile refusals, default-denial units, enabled FFI format/Clippy | Existing contract still holds against changed source |
| Missing extension symbols | Independently omit each of four new symbols; zero cuInit and resource mutation |
Fixed16 pre-initialization admission |
| Typed validation | Different contexts on same device; unequal/nonmultiple4/empty shapes; count/grid overflow; invalid output alias; poisoned context. All refuse before push/load/launch | Bounded safe wrapper admission |
| ABI and synthetic data | Verify exact trusted PTX/entry identity, parameter order/width/value and live owned device allocations, fixed dimensions/null stream/null extra, context sentinel, input immutability/output/canaries | Mocked host ABI/dataflow only |
| Launch bounds | Counts 1,127,128,129 and a bounded larger nonmultiple128 vector; checked maximum/count-overflow tests without giant allocations | Shape/tail guard contract, not real GPU memory safety |
| Cache/lifetime | First valid call loads/looks up once; next call reuses; independent contexts own separate caches; zero unload with pending work; healthy unload before destroy | Bounded cache and resource ordering |
| Faults | Load/lookup/null-success handles/push/launch/sync/pop/wrong-pop/unload/destroy, plus launch+sync and lookup+unload errors; failed unload consumed once, no retry/reuse/cache reinitialization | Original errors retained, cleanup attempts, poison/refusal behavior |
| Delayed completion | Mock defers add completion to sync, including dereferencing retained parameter storage; failed sync leaves work pending until containment; no early argument release/buffer free/module unload; caller output never presented as successful after failure | Declared containment behavior alongside source review |
| Ownership compile gates | Existing driver/context/buffer borrow and thread refusals remain; no safe arbitrary module/function/pointer escape | Rust safe API lifetime/thread surface |
| Offline PTX assembly | GPU-hidden Linux CPU Docker with pinned ptxas; exact PTX SHA, tool/version/container target and flags; no devices, installed driver calls or user data |
PTX assembler acceptance for the recorded target only |
| Installed-driver numerical execution | Separate authorized real-GPU gate: independent f32 reference; declare finite tolerance before execution (target exact finite bits), signed zeros/subnormal/overflow/Inf/NaN cases with NaN classification/payload limits | Only the executed hardware/driver numerical scope |
| Model / protocol / throughput | Separate Qwen and two named MoE integration, real quality/protocol gates, same-workload paired distributions/provenance | Whole-engine claims only after their own evidence |
Record actual argv, source/commit and embedded PTX hashes, toolchain, architecture, image/ELF identity, environment/guards, exact test counts, failures and exit codes. Keep generated evidence private outside Git, remove owned disposable resources, and report cleanup failures. No number in the planned matrix is a measured pass.
Remaining platform and qualification boundaries
GNU/Linux 64-bit CPU mock/assembly results do not qualify the existing static
musl executable for dlopen(libcuda.so.1). Its loader integration remains open,
as described in the historical bootstrap contract. PTX loading may require the
installed driver to JIT the fixed image; driver/JIT compatibility is unqualified
until a separate real-driver gate. No Toolkit becomes a deployment prerequisite
merely because offline assembly is used for validation.
No real GPU allocation, kernel execution, model support, quality, protocol completion, rollback or performance is established by this requirements unit. The autonomous engine parent and its dependent intake/delivery items remain open under root coordination. No admission/closure flags are changed here.
No active host-local .leasevibe.yaml pointer was supplied; it was absent in
the worktree and canonical repository. Task-relevant host settings are therefore
unavailable, not inferred. The explicit session restrictions remain binding:
Gitea only for future publication/CI, no merge, no active Qwen/runtime changes,
no GPU/model/user-data probes. This BA unit changes only this requirements file.