Expand description
GPU-forge differential oracle: CPU references, the numeric comparator, the
GpuEvaluation evidence bundle, and the per-kernel evaluators that certify
emitted shaders against those references.
Split by concern into submodules ([params], [report], [reference],
[evaluate], [kernels]); the full public surface is re-exported here so every
existing crate::wgsl_forge::oracle::<Item> path resolves exactly as before.
Structs§
- Affine
Params - Comparison
Report - FfnParams
- 16-byte uniform block for the fused-FFN kernel.
- FftParams
- 16-byte uniform block for the radix-2 FFT kernel:
ncomplex elements,log2n = log2(n). The kernel runs one workgroup ofnthreads. - Gemm
Params - 16-byte uniform block for the dense GEMM kernel: row-major
C[M×N] = A[M×K]·B[K×N]. - Gemv
Params - 16-byte uniform block for the dense GEMV kernel: row-major
y[M] = A[M×N]·x[N]. - GpuEvaluation
- Oracle
Case - Oracle
Tolerance - Ternary
Gemv Params - 16-byte uniform block for the ternary-GEMV kernel (
k_words== ceil(k/16)). - TopK
Params - 16-byte uniform block for the top-k kernel (
block_size== workgroup size).
Constants§
- TERNARY_
CODES_ PER_ WORD - Number of 2-bit ternary codes packed into one
u32word.
Functions§
- affine_
cpu - candidate_
evaluation - certify_
builtin - compare_
f32 - dft_cpu
- Naive
O(N²)forward Discrete Fourier Transform, the reference the GPU radix-2 FFT is differentially checked against. Complex data is interleaved f32: elementjis(input[2*j], input[2*j+1]) = (real, imag), so both theinputslice and the returned vector hold2*Nf32. - evaluate_
affine - Cross-backend differential-oracle evaluation of the affine kernel against
affine_cpu(plan §7). Generic overOracleContext, so the same code runs on wgpu (viaWgpuComputeContext) and CUDA (viaCudaComputeContext); the backend only differs insideOracleContext::run_kernel. The CPU-reference vectors, bindings, dispatch sizing and tolerance are identical to what the wgpu-inline andevaluate_affine_cudapaths used before unification. - evaluate_
affine_ cuda - Cross-backend oracle (plan §7/§10): runs the affine kernel through the native CUDA backend (CUDA-C compiled to PTX by NVRTC) and checks it against the same CPU reference vectors used for the wgpu backend. Requires a CUDA device.
- evaluate_
builtin - evaluate_
coopmat_ loadstore - Diagnostic: cooperative-matrix load→store round-trip (no multiply). Loads
aas a role-C fragment and stores it toc;cmust equala. This verifiescoopLoadT/coopStoreTwork on the adapter (they do — thecoopMultiplyAddpath is the one currently blocked on the experimental backend). - evaluate_
ffn - Cross-backend differential-oracle evaluation for the fused FFN against
ffn_cpu(plan §7). Generic overOracleContext— the same code runs on wgpu and CUDA; onlyOracleContext::run_kerneldiffers. One workgroup-thread per output element; the output buffer isoutput_size. Tensors, bindings, dispatch sizing and tolerance are identical to the prior wgpu/evaluate_ffn_cudapaths. - evaluate_
ffn_ cuda - Cross-backend oracle for the fused FFN via the CUDA backend. Thin wrapper over
the generic
evaluate_ffn(warmups = 0, samples = 1, one dispatch as before). - evaluate_
fft - Differential-oracle evaluation of the radix-2 FFT (
out = forward DFT(in)) againstdft_cpu. One workgroup ofn = schedule.workgroup_sizethreads (one complex element per thread;nmust be a power of two), mirroring the single-workgroup dispatch of [evaluate_topk]:element_count = nwithworkgroup_size = nlaunches exactly one workgroup. The input/output buffers hold2*ninterleaved f32. - evaluate_
gemm - Differential-oracle evaluation for the dense GEMM against
gemm_cpu. One workgroup-thread per output element; the output buffer ism * nelements. Row-majorC[M×N] = A[M×K] · B[K×N], all f32. - evaluate_
gemv - Differential-oracle evaluation for the dense GEMV against
gemv_cpu. One workgroup-thread per output ROW; the output buffer ismelements. Row-majory[M] = A[M×N] · x[N], all f32. - evaluate_
matmul_ tc - Differential-oracle evaluation of the cooperative-matrix (tensor-core) 8x8
GEMM tile
C = A * Bagainstmatmul_cpu. All-f32 — the only coopmat configuration wgpu/naga 29 implements (seecrate::wgsl_forge::emit::coopmat). One subgroup (32-lane NVIDIA warp) cooperatively computes the tile; the row-major loads/store reproduce the row-major CPU reference, so agreement is to f32 precision (a tiny tolerance covers tensor-core accumulation order). - evaluate_
matmul_ tc_ cuda - Tensor-core oracle: runs the genuine f16-input WMMA GEMM (
C = A * B, 16x16x16) on the CUDA backend via thenvcuda::wmmafragment API, compiled by NVRTC for the device’s compute capability, and checks it against the row-major CPU reference. This is the reduced-precision tensor-core path (f16 A/B inputs, f32 accumulator) that wgpu/naga 29’s cooperative-matrix backend cannot express — 29 implements only all-f32 8x8x8, and even that multiply is non-functional on the 29.0.3 execution path (no published fix; seecrate::wgsl_forge::emit::coopmat). Requires a CUDA device with compute capability >= 7.0 (Volta+). - evaluate_
p64 - Differential-oracle evaluation for the P64 projection against
p64_project_cpu. - evaluate_
rayprobe - Differential-oracle evaluation of the ray-query (ray-probe) kernel: builds a
BLAS+TLAS for
rayprobe_scene, dispatches the emittedray_probeWGSL overrayprobe_rayson the GPU, and checks the committed hit distances againstrayprobe_cpu. Requires a ray-query-capable adapter (RT cores). - evaluate_
ternary_ gemv - Differential-oracle evaluation for the ternary GEMV against
ternary_gemv_cpu. One workgroup-thread per output row; the output buffer ismelements. - evaluate_
topk - Cross-backend differential-oracle evaluation for the top-k kernel against
topk_cpu(plan §7). Generic overOracleContext— the same code runs on wgpu and CUDA; onlyOracleContext::run_kerneldiffers. - evaluate_
topk_ cuda - Cross-backend oracle for top-k via the CUDA backend (CUDA-C
__shared__). Thin wrapper over the genericevaluate_topk(warmups = 0, samples = 1, one dispatch as before;block_sizeisschedule.workgroup_size, i.e. 64). - ffn_cpu
- CPU reference for the fused FFN, matching the emitted kernel’s op order
exactly (hidden outer, input inner) so GPU/CPU agree within tolerance:
out[o] = sum_h w2[o,h] * gelu(sum_i w1[h,i] * input[i]). - ffn_
tensors - Deterministic FFN test tensors. Weights are scaled by 1/sqrt(fan_in) so the pre-activations stay O(1) and GPU/CPU agree within a modest tolerance.
- fft_
inputs - Deterministic complex test signal as interleaved f32 (
2*nvalues), drawn from the same xorshift stream as every other oracle vector so it is reproducible. Both the real and imaginary parts land in[-1, 1]. - gemm_
cpu - Row-major general dense GEMM reference, the bit-for-bit mirror of the emitted
gemmkernel:C[M×N] = A[M×K] · B[K×N], i.e.C[i][j] = sum_{k<K} A[i*K + k] * B[k*N + j]. The inner-sum order (k ascending) matches the kernel’skkloop so GPU/CPU agree to f32 summation precision. - gemm_
tensors - Deterministic GEMM test tensors: A (M×K) and B (K×N), both drawn from the same
xorshift stream as every other oracle vector and scaled by
1/sqrt(K)so the length-K dot products stay O(1) and GPU/CPU agree within a tight tolerance. - gemv_
cpu - Row-major dense GEMV reference, the bit-for-bit mirror of the emitted
gemvkernel:y[M] = A[M×N] · x[N], i.e.y[i] = sum_{j<N} A[i*N + j] * x[j]. The inner-sum order (j ascending) matches the kernel’sjloop so GPU/CPU agree to f32 summation precision. - gemv_
tensors - Deterministic GEMV test tensors: A (M×N) and x (N), both drawn from the same
xorshift stream as every other oracle vector and scaled by
1/sqrt(N)so the length-N dot products stay O(1) and GPU/CPU agree within a tight tolerance. - matmul_
cpu - Row-major n×n matrix multiply reference:
c[i][j] = sum_k a[i][k] * b[k][j]. - p64_
project_ cpu - CPU reference for the P64 projection:
out[r] = sum_w weights[w] * f32(word_w), reading the 16 packed u32 words in the same lane order as the kernel. - p64_
records - Deterministic P64 descriptors with small (f32-exact) u32 words.
- rayprobe_
cpu - CPU reference for the ray-probe kernel: for each ray, the nearest committed
triangle hit
twithin[t_min, t_max], or-1.0on a miss — matching the emitter’shits[i] = committed.t else -1.0. - rayprobe_
rays - The fixed ray set as the 8-float-per-ray layout the emitter expects
(
origin.xyz, dir.xyz, t_min, t_max). All rays originate atz = -1and point along+z; hit rays target clear triangle interiors (away from edges) so GPU BVH traversal and the CPU reference agree, and miss rays point well outside. - rayprobe_
scene - The fixed ray-probe scene: three world-space triangles as a flat
f32list (9 floats/triangle = 3 verts × xyz). Two coplanar triangles tile the quad[0,2]²atz = 2; a third sits behind them atz = 4, so rays through the lower-left region hit two triangles and must commit the nearer one (t at z=2). - ternary_
gemv_ cpu - CPU reference for the BitNet-style ternary GEMV, the bit-for-bit mirror of the
emitted kernel:
out[o] = scale[o] * sum_{i<K} ternary(w[o,i]) * x[i]. - ternary_
gemv_ tensors - Deterministic ternary-GEMV test tensors: the activation vector
x(length K), the 2-bit-packed ternary weights (M * ceil(K/16)words), and the per-row scales (length M). Codes are drawn from the xorshift stream and reduced into{0,1,2}so the weights only ever decode to{0, +1, -1}(never the unused3), keeping the GPU and CPU paths bit-identical. - topk_
cpu - CPU reference for the per-block top-k: the
klargest values of eachblock_size-element block, in descending order. Blocks shorter thanblock_size(the tail) are padded with the sentinel, mirroring the GPU kernel’s out-of-range loads. - topk_
inputs - Deterministic xorshift test vector in
[-1, 1], matching the affine generator.