Skip to content

initWebAssembly

Summary

initWebAssembly initializes the built-in WasmGPU WebAssembly driver. Use it before accessing the standalone CPU ndarray, heap or pointer APIs without creating a GPU runtime. WasmGPU.create() initializes the driver as part of startup.

Syntax

initWebAssembly(baseURL?: string): Promise<void>
await initWebAssembly();

Parameters

Name Type Required Description
baseURL string No Absolute base URL from which wasm.wasm and wasm.js are resolved. The default uses the bundle's location. For a directory override, include the trailing slash.

Returns

Promise<void> - Resolves when the driver and frame arena are ready. Concurrent startup calls share the same load.

Example

import { CPUndarray, initWebAssembly } from "@zushah/wasmgpu";

await initWebAssembly();
const samples = CPUndarray.fromArray("f32", [3], [1, 2, 3]);
console.log(samples.data());
samples.destroy();

Notes

Initialization first fetches wasm.wasm. It uses streaming instantiation when available and the response has the application/wasm content type. Otherwise it reads the binary as bytes. If binary loading fails, it imports wasm.js, which contains the fallback module. Serve both companions alongside the bundle or under the same custom base. If both paths fail, the bundle instance caches that rejection. Reload the page to retry after fixing the URLs.

See Also