Humuhumu33 commited on
Commit
df29783
·
verified ·
1 Parent(s): 139e306

Upload holo-gpu-device.mjs with huggingface_hub

Browse files
Files changed (1) hide show
  1. holo-gpu-device.mjs +27 -0
holo-gpu-device.mjs ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // holo-gpu-device.mjs — ONE WebGPU device for the whole app (the engine, BLAKE3 verify, Bao streaming).
2
+ // Memoized: exactly one requestDevice() per page. Created with the ADAPTER'S MAX limits so a 145 MB block
3
+ // binds as a storage buffer (the default cap is 128 MB — a separate default-limits device silently produced a
4
+ // wrong hash on the embed → κ mismatch → the two-device clash). timestamp-query is requested when available.
5
+ // Sharing ONE device is what lets fetch→verify→decode coexist without contending.
6
+ let _p = null;
7
+ export function getDevice() {
8
+ if (_p) return _p;
9
+ _p = (async () => {
10
+ if (typeof navigator === "undefined" || !navigator.gpu) throw new Error("no WebGPU");
11
+ const adapter = await navigator.gpu.requestAdapter();
12
+ const L = adapter.limits;
13
+ const canTs = adapter.features.has("timestamp-query");
14
+ const dev = await adapter.requestDevice({
15
+ requiredFeatures: canTs ? ["timestamp-query"] : [],
16
+ requiredLimits: {
17
+ maxStorageBufferBindingSize: L.maxStorageBufferBindingSize,
18
+ maxBufferSize: L.maxBufferSize,
19
+ maxComputeWorkgroupsPerDimension: L.maxComputeWorkgroupsPerDimension,
20
+ },
21
+ });
22
+ try { if (typeof globalThis !== "undefined") globalThis.__gpuDeviceCount = (globalThis.__gpuDeviceCount || 0) + 1; } catch (e) {}
23
+ return { dev, adapter, canTs };
24
+ })().catch((e) => { _p = null; throw e; });
25
+ return _p;
26
+ }
27
+ export default { getDevice };