Spaces:
Running
Running
Update gpu.js
Browse files
gpu.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
| 1 |
-
export async function initGPU(
|
| 2 |
-
if (!navigator.gpu) {
|
| 3 |
-
return { mode: "cpu" };
|
| 4 |
-
}
|
| 5 |
-
|
| 6 |
-
const adapter = await navigator.gpu.requestAdapter();
|
| 7 |
-
if (!adapter) return { mode: "cpu" };
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
-
export async function createCompute(device,
|
| 15 |
-
const module = device.createShaderModule({ code
|
| 16 |
|
| 17 |
-
|
| 18 |
layout: "auto",
|
| 19 |
compute: {
|
| 20 |
module,
|
| 21 |
entryPoint: "main"
|
| 22 |
}
|
| 23 |
});
|
| 24 |
-
|
| 25 |
-
return pipeline;
|
| 26 |
}
|
|
|
|
| 1 |
+
export async function initGPU() {
|
| 2 |
+
if (!navigator.gpu) return { mode: "cpu" };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
try {
|
| 5 |
+
const adapter = await navigator.gpu.requestAdapter();
|
| 6 |
+
if (!adapter) return { mode: "cpu" };
|
| 7 |
|
| 8 |
+
const device = await adapter.requestDevice();
|
| 9 |
+
return { mode: "gpu", device };
|
| 10 |
+
} catch {
|
| 11 |
+
return { mode: "cpu" };
|
| 12 |
+
}
|
| 13 |
}
|
| 14 |
|
| 15 |
+
export async function createCompute(device, code) {
|
| 16 |
+
const module = device.createShaderModule({ code });
|
| 17 |
|
| 18 |
+
return device.createComputePipeline({
|
| 19 |
layout: "auto",
|
| 20 |
compute: {
|
| 21 |
module,
|
| 22 |
entryPoint: "main"
|
| 23 |
}
|
| 24 |
});
|
|
|
|
|
|
|
| 25 |
}
|