/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
70 lines · 2.6 KBBlameHistoryRaw
1/**
2 * The whole suite on desktop WebGPU (Google Dawn), against the real pipeline:
3 * MATLAB source -> numbl lowering -> generated WGSL -> GPU.
4 *
5 * The same four check modules run in the browser (test.html), so both GPU
6 * stacks get the same guarantees. Run through vite-node, which is what resolves
7 * numbl's compiler sources and the `?raw` model imports:
8 *
9 * npm run test:node
10 */
11import { tmpdir } from 'node:os';
12import { join } from 'node:path';
13import * as h5wasm from 'h5wasm/node';
14import { requestShtDevice } from '../src/sht/sht.ts';
15import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts';
16import { transformChecks } from '../test/transformChecks.ts';
17import { analyticChecks } from '../test/analyticChecks.ts';
18import { modelChecks } from '../test/modelChecks.ts';
19import { geometryChecks } from '../test/geometryChecks.ts';
20import { fluxChecks } from '../test/fluxChecks.ts';
21import { compareChecks } from '../test/compareChecks.ts';
22import { referenceChecks, type H5Rt } from '../test/referenceChecks.ts';
24let failures = 0;
25const check = (name: string, ok: boolean, detail: string): void => {
26 console.log(`${ok ? 'PASS' : 'FAIL'} ${name} ${detail}`);
27 if (!ok) failures++;
28};
29const log = (s: string): void => console.log(s);
31/**
32 * These checks compile MATLAB to compute shaders, so unlike the old CPU-solver
33 * suite they need a GPU. `--skip-without-gpu` lets a runner that has none say so
34 * and move on — CI uses it, because the browser suite runs the very same check
35 * modules on SwiftShader. A plain local run still fails loudly, so a missing GPU
36 * is never mistaken for a pass.
37 */
38const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
40let runtime: string;
41let device: GPUDevice;
42try {
43 runtime = await installWebGpu();
44 device = await requestShtDevice();
45} catch (e) {
46 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
47 if (skipWithoutGpu) {
48 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
49 process.exit(0);
50 }
51 console.error(`test-node: ${detail}`);
52 process.exit(1);
54console.log(`turing-surface tests — ${runtime}\n`);
56await transformChecks(device, check, log);
57await analyticChecks(device, check, log);
58await modelChecks(device, check, log);
59await geometryChecks(device, check, log);
60await fluxChecks(device, check, log);
61await compareChecks(device, check, log);
62await referenceChecks(
63 h5wasm as unknown as H5Rt,
64 (name) => join(tmpdir(), `turing-surface-${process.pid}-${name}`),
65 check,
66 log,
67);
69console.log(failures === 0 ? '\nAll tests passed.' : `\n${failures} failed.`);
70process.exit(failures === 0 ? 0 : 1);
moveopenescclose