Expand description
Elementwise vector add — the demonstrator op that proves the cascade.
out[i] = a[i] + b[i]. Trivial arithmetic on purpose: the point of this op
is not the maths but to exercise the whole GPU->CPU machinery end to end —
host data into storage buffers, a WGSL compute dispatch, readback through a
staging buffer, and a pure-Rust twin that gives the identical answer when
there is no GPU.
Both paths return Vec<f32> of the same length as the inputs, and for
elementwise f32 addition the GPU and CPU results are bit-for-bit equal
(IEEE-754 addition is exact and deterministic here — no reordering, no
fused-multiply-add), which is why the tests can assert plain equality when a
GPU is present.
Structs§
- Vector
Add - Elementwise vector addition. Zero-sized: it carries no state, it just names
the operation so the
ComputeOpimpl and its two kernels hang off a type. - Vector
AddInput - The two input vectors, borrowed. Equal length is a precondition (checked in both paths); mismatched lengths are a caller bug, not something to paper over.
Functions§
- vector_
add_ cpu - The pure-Rust floor of the cascade. Infallible and correct.
- vector_
add_ gpu - The wgpu compute path. Fallible: any wgpu-level problem returns
Errso thecrate::Executorcan fall back tovector_add_cpu.