/ proof-of-concept / steelsim21
Sign in
proof-of-concept / steelsim21
CLI: import the optional Dawn binding by name so the type check passes without it
Jeremy Magland <jmagland@flatironinstitute.org> committed commit f8f7491f3eca parent 34bff74 Browse files
1 changed file+8−3
src/cli/run.tsmodified+8−3View file
@@ -8,14 +8,19 @@ let devicePromise: Promise<GPUDevice> | null = null;
88 export function getDevice(): Promise<GPUDevice> {
99 if (!devicePromise) {
1010 devicePromise = (async () => {
11- // Loaded lazily: the prebuilt binding needs a recent glibc and is only used by --engine dawn.
12- const { create, globals } = await import("webgpu");
11+ // Loaded lazily and by name: the prebuilt binding is an optional dependency
12+ // (it needs a recent glibc) and is only used by --engine dawn.
13+ const moduleName = "webgpu";
14+ const { create, globals } = (await import(moduleName)) as {
15+ create: (args: string[]) => { requestAdapter(): Promise<GPUAdapter | null> };
16+ globals: Record<string, unknown>;
17+ };
1318 Object.assign(globalThis, globals);
1419 const gpu = create([]);
1520 const adapter = await gpu.requestAdapter();
1621 if (!adapter) throw new Error("No WebGPU adapter");
1722 const device = await adapter.requestDevice();
18- device.addEventListener("uncapturederror", (ev) => {
23+ device.addEventListener("uncapturederror", (ev: Event) => {
1924 console.error("WebGPU error:", (ev as GPUUncapturedErrorEvent).error.message);
2025 });
2126 return device;
↑↓ move↵openescclose