// WGSL's integer semantics vectors (wai/wgsl-conformance/integer.jsonl) against the // reference compiled to wasm32, under Node, with no GPU: every committed result must be // the one `wai_ops_gpu::semantics::reference` gives in WebAssembly. // // Build the page's module first (run.mjs's header says how), then: // // node wai/wai-ops-gpu/browser/semantics_reference.mjs // // Prints `wasm reference: target=wasm32 ... cases=N equal` and exits 0, or prints the // first difference and exits 1. import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const pkg = path.join(HERE, "pkg"); if (!fs.existsSync(path.join(pkg, "wai_ops_gpu_browser.js"))) { console.error("no pkg/wai_ops_gpu_browser.js; build it as run.mjs's header says"); process.exit(2); } const mod = await import(path.join(pkg, "wai_ops_gpu_browser.js")); mod.initSync({ module: fs.readFileSync(path.join(pkg, "wai_ops_gpu_browser_bg.wasm")) }); const vectors = fs.readFileSync(path.resolve(HERE, "../../wgsl-conformance/integer.jsonl"), "utf8"); const out = mod.semantics_reference(vectors); console.log(`node ${process.version}: ${out}`); if (!/^wasm reference: target=wasm32 .* cases=[1-9][0-9]* equal$/.test(out)) process.exit(1);