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