Test suite for wgblas — all 49 BLAS Level 1, 2, and 3 routines (24 single
precision, 24 double precision, and cscal), each covered by four kinds of
test, plus init() and the internal utilities.
Layout
tests/ <routine>/ src/test.<routine>.js — validation, fixturesandedgecases src/gpustorage.<routine>.js — GPU-residentcoverage edge-cases.json — deterministicedgecases edge-cases-column-major.json — thesameforcolumn-majorstorage (matrixroutines) helpers.js — theroutine's error metric (most routines) init/src/test.init*.js — init(), deviceoptions, cleanup(), andsimulated browser / no-WebGPUenvironments utils/test.<module>.js — onefilepersrc/util/ module, plustheclassesandrandom helpers/ — shared: fixtures, validation, ulp, stdlibreferences, device validation/params/*.json — the param specs validation and fixtures read kaggle/kernel.py — the CI kernel that runs the suite on a Kaggle GPU
Test Types
The first three live in test.<routine>.js; the fourth is a separate file:
validation — rejects every class of bad input defined in
tests/validation/params/*.json: wrong type, wrong size, out-of-range
value. Catches guard-clause bugs before any GPU work begins.
fixtures — 100 property-based random runs via fast-check, comparing
the GPU result against @stdlib (or a hand-written reference, for
routines @stdlib doesn't cover) as the CPU oracle, using a
routine-specific error metric — see below. Inputs avoid subnormals to
stay safe under WGSL's flush-to-zero (FTZ) rule.
edge cases — deterministic checks for routine-specific behaviour:
ties, strides, identity parameters, exact Pythagorean results, per-flag
srotm paths. The 22 routines with a layout parameter (matrix
routines that accept row-major or column-major storage — 14 single, 8
double precision) get a second edge-cases pass —
edge-cases-column-major.json — run as its own test.
GPU-resident coverage (gpustorage.<routine>.js) — the same
fixtures inputs and stdlib oracle as test 2 and 3, but run through the
GpuVector/GpuMatrix-resident overload instead of the plain-array
one. Runs via make test-gpu/make test-gpu-<routine>, a separate
invocation from make test — and not part of the Kaggle CI kernel,
which runs the same test.*.js files as make test (under c8, for
coverage).
Error Metrics
Four metric families, chosen per routine by what kind of floating-point
error the operation can legitimately produce:
exact match — the operation has no rounding to tolerate (a copy, a
swap, a single multiply, an index) so GPU and CPU must agree bit-for-bit
(or index-for-index); threshold 0.
reduction ULP (ulpDiff/ulpDiff64) — GPU sum/norm routines use a
tree reduction while the CPU reference sums sequentially; different
summation order gives a different (still correct) rounding, bounded in
ULPs rather than required to match exactly.
forward-error factor (forwardFactor) — normalizes the raw error by
a routine-derived rounding-error bound instead of counting ULPs, so a
legal FMA fusion or a cancellation-shrunk result doesn't read as a
failure:
$$\text{factor} = \max_i \frac{|\text{err}_i|}{\varepsilon \cdot \text{bound}_i}, \qquad \varepsilon = 2^{-23} \text{ (f32)}, ; 2^{-48} \text{ (double-double)}$$
err_i = |gpu_i - ref_i| at each output index i (or i,j for a
matrix output) — bound_i is routine-specific; every routine's is in
the Equation column of the table below.
backward-residual factor (backwardResidualFactor) — for
triangular solves, forward-comparing to a computed "true" x is the
wrong question (a solve can be ill-conditioned without being wrong).
Plugs the GPU's answer back into the original equation and checks the
residual instead, LAPACK-style — same shape as forward-error factor
above, but err_i is now a residual, not a gpu-vs-ref difference:
$$\text{factor} = \max_i \frac{|\text{err}_i|}{\varepsilon \cdot \text{bound}_i}, \qquad \text{err}_i = \left|(\operatorname{op}(A)x_{\text{gpu}})_i - b_i\right|$$
(strsm's right-hand side is \alpha B_{ij}, indexed i,j — a matrix,
not a vector b). bound_i is again routine-specific — strsv's and
strsm's are in the table below, and differ for the reason given there.
The double-precision routines use the same metric shapes with
$\varepsilon = 2^{-48}$: double-double carries about 48 significand bits,
not IEEE double's 53. Even dcopy and dswap, which do no arithmetic,
get a forward-error factor rather than an exact match — the split into
hi/lo halves and the merge back at the JS boundary is itself a rounding.
Their thresholds are looser than the f32 ones (mostly 5), calibrated on
real hardware; each test file says why.
n/k below are each routine's own reduction length; r = aOrder, the
shared dimension A is read over (m for side="left", n for
side="right", in ssymm/strmm/strsm).
$(k{+}2)|\alpha|\sum_p|A_{ip}||B_{pj}|+2|\beta||C_{ij}|$ — sgemm's, widened for the hi/lo split of A, B and C
dtrsm
3
backwardResidualFactor
5
$(r{+}2)\sum_k|A_{ik}||X_{kj}|$ — strsm's, widened for the hi/lo split of A and B
idamax and dasum, the first two f64 routines, sit in the Level 1 block
of the table above.
Make Commands
Command
What it does
make test
Runs every test.*.js — all 49 routines' validation + fixtures + edge cases, plus init and the utility tests
make test-<routine>
Runs one routine's test.<routine>.js, e.g. make test-saxpy (also make test-init)
make test-gpu
Runs GPU-resident coverage for all 49 routines (gpustorage.*.js)
make test-gpu-<routine>
Runs one routine's gpustorage.<routine>.js
make test-utils
Runs every tests/utils/test.*.js
make test-util-<module>
Runs one, e.g. make test-util-buffer
Pass ARGS=low-power to prefer the integrated GPU on dual-GPU machines:
make test-saxpy ARGS=low-power. Node's test runner doesn't forward
trailing CLI args the way a plain node script.js invocation does, so
this goes through the WGBLAS_POWER_PREFERENCE env var instead — see
tests/helpers/device.js.
Test suite for wgblas — all 49 BLAS Level 1, 2, and 3 routines (24 single precision, 24 double precision, and
cscal), each covered by four kinds of test, plusinit()and the internal utilities.Layout
Test Types
The first three live in
test.<routine>.js; the fourth is a separate file:tests/validation/params/*.json: wrong type, wrong size, out-of-range value. Catches guard-clause bugs before any GPU work begins.@stdlib(or a hand-written reference, for routines@stdlibdoesn't cover) as the CPU oracle, using a routine-specific error metric — see below. Inputs avoid subnormals to stay safe under WGSL's flush-to-zero (FTZ) rule.layoutparameter (matrix routines that accept row-major or column-major storage — 14 single, 8 double precision) get a second edge-cases pass —edge-cases-column-major.json— run as its own test.gpustorage.<routine>.js) — the same fixtures inputs and stdlib oracle as test 2 and 3, but run through theGpuVector/GpuMatrix-resident overload instead of the plain-array one. Runs viamake test-gpu/make test-gpu-<routine>, a separate invocation frommake test— and not part of the Kaggle CI kernel, which runs the sametest.*.jsfiles asmake test(under c8, for coverage).Error Metrics
Four metric families, chosen per routine by what kind of floating-point error the operation can legitimately produce:
0.ulpDiff/ulpDiff64) — GPU sum/norm routines use a tree reduction while the CPU reference sums sequentially; different summation order gives a different (still correct) rounding, bounded in ULPs rather than required to match exactly.forwardFactor) — normalizes the raw error by a routine-derived rounding-error bound instead of counting ULPs, so a legal FMA fusion or a cancellation-shrunk result doesn't read as a failure: $$\text{factor} = \max_i \frac{|\text{err}_i|}{\varepsilon \cdot \text{bound}_i}, \qquad \varepsilon = 2^{-23} \text{ (f32)}, ; 2^{-48} \text{ (double-double)}$$err_i = |gpu_i - ref_i|at each output indexi(ori,jfor a matrix output) —bound_iis routine-specific; every routine's is in the Equation column of the table below.backwardResidualFactor) — for triangular solves, forward-comparing to a computed "true"xis the wrong question (a solve can be ill-conditioned without being wrong). Plugs the GPU's answer back into the original equation and checks the residual instead, LAPACK-style — same shape as forward-error factor above, buterr_iis now a residual, not agpu-vs-refdifference: $$\text{factor} = \max_i \frac{|\text{err}_i|}{\varepsilon \cdot \text{bound}_i}, \qquad \text{err}_i = \left|(\operatorname{op}(A)x_{\text{gpu}})_i - b_i\right|$$ (strsm's right-hand side is\alpha B_{ij}, indexedi,j— a matrix, not a vectorb).bound_iis again routine-specific —strsv's andstrsm's are in the table below, and differ for the reason given there.The double-precision routines use the same metric shapes with $\varepsilon = 2^{-48}$: double-double carries about 48 significand bits, not IEEE double's 53. Even
dcopyanddswap, which do no arithmetic, get a forward-error factor rather than an exact match — the split into hi/lo halves and the merge back at the JS boundary is itself a rounding. Their thresholds are looser than the f32 ones (mostly 5), calibrated on real hardware; each test file says why.n/kbelow are each routine's own reduction length;r=aOrder, the shared dimensionAis read over (mforside="left",nforside="right", in ssymm/strmm/strsm).idamaxanddasum, the first two f64 routines, sit in the Level 1 block of the table above.Make Commands
make testtest.*.js— all 49 routines' validation + fixtures + edge cases, plusinitand the utility testsmake test-<routine>test.<routine>.js, e.g.make test-saxpy(alsomake test-init)make test-gpugpustorage.*.js)make test-gpu-<routine>gpustorage.<routine>.jsmake test-utilstests/utils/test.*.jsmake test-util-<module>make test-util-bufferPass
ARGS=low-powerto prefer the integrated GPU on dual-GPU machines:make test-saxpy ARGS=low-power. Node's test runner doesn't forward trailing CLI args the way a plainnode script.jsinvocation does, so this goes through theWGBLAS_POWER_PREFERENCEenv var instead — seetests/helpers/device.js.