/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
56 lines · 2.1 KBCodeBlameHistory
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 { requestShtDevice } from '../src/sht/sht.ts';
12import { installWebGpu, errMsg, NO_ADAPTER_HINT } from './nodeWebGpu.ts';
13import { transformChecks } from '../test/transformChecks.ts';
14import { analyticChecks } from '../test/analyticChecks.ts';
15import { modelChecks } from '../test/modelChecks.ts';
16import { geometryChecks } from '../test/geometryChecks.ts';
18let failures = 0;
19const check = (name: string, ok: boolean, detail: string): void => {
20 console.log(`${ok ? 'PASS' : 'FAIL'} ${name} ${detail}`);
21 if (!ok) failures++;
22};
23const log = (s: string): void => console.log(s);
25/**
26 * These checks compile MATLAB to compute shaders, so unlike the old CPU-solver
27 * suite they need a GPU. `--skip-without-gpu` lets a runner that has none say so
28 * and move on — CI uses it, because the browser suite runs the very same check
29 * modules on SwiftShader. A plain local run still fails loudly, so a missing GPU
30 * is never mistaken for a pass.
31 */
32const skipWithoutGpu = process.argv.includes('--skip-without-gpu');
34let runtime: string;
35let device: GPUDevice;
36try {
37 runtime = await installWebGpu();
38 device = await requestShtDevice();
39} catch (e) {
40 const detail = `${errMsg(e)}\n${NO_ADAPTER_HINT}`;
41 if (skipWithoutGpu) {
42 console.log(`SKIP no WebGPU available here, so these checks did not run.\n${detail}`);
43 process.exit(0);
44 }
45 console.error(`test-node: ${detail}`);
46 process.exit(1);
48console.log(`turing-surface tests — ${runtime}\n`);
50await transformChecks(device, check, log);
51await analyticChecks(device, check, log);
52await modelChecks(device, check, log);
53await geometryChecks(device, check, log);
55console.log(failures === 0 ? '\nAll tests passed.' : `\n${failures} failed.`);
56process.exit(failures === 0 ? 0 : 1);
moveopenescclose