/ concept-collection / turing-sphere-2
concept-collection / turing-sphere-2
turing-sphere-2 / scripts / test-node.ts
54 lines · 2.0 KBCodeBlameHistory
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 2 * The whole suite on desktop WebGPU (Google Dawn), against the real pipeline:
3 * MATLAB source -> numbl lowering -> generated WGSL -> GPU.
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 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:
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 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;
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 18const check = (name: string, ok: boolean, detail: string): void => {
2dedc35turing-sphere: reaction-diffusion on the sphere, spectral solver on WebGPUJeremy Magland 19 console.log(`${ok ? 'PASS' : 'FAIL'} ${name} ${detail}`);
20 if (!ok) failures++;
22const log = (s: string): void => console.log(s);
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);
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 44 console.error(`test-node: ${detail}`);
45 process.exit(1);
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 47console.log(`turing-sphere tests — ${runtime}\n`);
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 49await transformChecks(device, check, log);
50await analyticChecks(device, check, log);
51await modelChecks(device, check, log);
35d91faDelete the TypeScript solver; the .m models are the only implementationJeremy Magland 53console.log(failures === 0 ? '\nAll tests passed.' : `\n${failures} failed.`);
2dedc35turing-sphere: reaction-diffusion on the sphere, spectral solver on WebGPUJeremy Magland 54process.exit(failures === 0 ? 0 : 1);