Spaces:
Running
Running
GitHub Actions commited on
Commit Β·
1b7cc6e
1
Parent(s): 43a358a
sync from abhijitramesh/webgpu-bench@4f567a5d06
Browse files- js/run/device.js +30 -12
js/run/device.js
CHANGED
|
@@ -227,11 +227,20 @@ async function _computeBudget() {
|
|
| 227 |
|
| 228 |
const isMobile = isMobileDevice();
|
| 229 |
|
| 230 |
-
//
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
// ββ Heap budget ββ
|
| 237 |
let heapBudgetMB;
|
|
@@ -255,13 +264,22 @@ async function _computeBudget() {
|
|
| 255 |
}
|
| 256 |
|
| 257 |
// ββ GPU budget ββ
|
| 258 |
-
let gpuBudgetMB
|
| 259 |
-
let gpuSource
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
}
|
| 266 |
|
| 267 |
return {
|
|
|
|
| 227 |
|
| 228 |
const isMobile = isMobileDevice();
|
| 229 |
|
| 230 |
+
// The heap probe is always safe β it runs inside a dedicated worker so
|
| 231 |
+
// a runaway grow() kills the worker, not the tab.
|
| 232 |
+
//
|
| 233 |
+
// The GPU probe is NOT safe on mobile. It allocates real WebGPU buffers
|
| 234 |
+
// in the GPU process, which is shared with the main tab. On phones,
|
| 235 |
+
// pushing 1β2 GB of GPU buffers triggers OOM behavior in iOS Safari
|
| 236 |
+
// that reaps the tab β which then reloads, reprobes, and reaps again,
|
| 237 |
+
// an infinite refresh loop. Skip the probe on mobile and substitute a
|
| 238 |
+
// heuristic based on navigator.deviceMemory; on desktop the GPU process
|
| 239 |
+
// has enough headroom for the probe to be useful.
|
| 240 |
+
const heapProbe = await probeHeapBudgetMB();
|
| 241 |
+
const gpuProbe = isMobile
|
| 242 |
+
? { probedMB: 0, error: 'skipped on mobile (would OOM the tab)' }
|
| 243 |
+
: await probeGpuBudgetMB();
|
| 244 |
|
| 245 |
// ββ Heap budget ββ
|
| 246 |
let heapBudgetMB;
|
|
|
|
| 264 |
}
|
| 265 |
|
| 266 |
// ββ GPU budget ββ
|
| 267 |
+
let gpuBudgetMB;
|
| 268 |
+
let gpuSource;
|
| 269 |
+
if (isMobile) {
|
| 270 |
+
// Heuristic since the probe would OOM the tab. Quarter of the
|
| 271 |
+
// device's reported RAM, clamped to a sensible range. iPhone WebGPU
|
| 272 |
+
// typically gives a tab 1.5β2 GB of usable GPU memory before things
|
| 273 |
+
// start failing; this estimate undershoots slightly to leave margin.
|
| 274 |
+
const memMB = (memGB || 4) * 1024;
|
| 275 |
+
gpuBudgetMB = Math.max(512, Math.min(memMB * 0.25, MOBILE_GPU_CEILING_MB));
|
| 276 |
+
gpuSource = `mobile heuristic (deviceMemory ${memGB ?? '?'} GB Γ 0.25, clamped 512 MBβ${MOBILE_GPU_CEILING_MB} MB)`;
|
| 277 |
+
} else if (gpuProbe.probedMB > 0) {
|
| 278 |
+
gpuBudgetMB = gpuProbe.probedMB;
|
| 279 |
+
gpuSource = `probe (WebGPU buffers, ${gpuProbe.probedMB} MB allocated)`;
|
| 280 |
+
} else {
|
| 281 |
+
gpuBudgetMB = 0;
|
| 282 |
+
gpuSource = `probe failed: ${gpuProbe.error || 'unknown'}`;
|
| 283 |
}
|
| 284 |
|
| 285 |
return {
|