This is an automated email from the ASF dual-hosted git repository.
junrushao pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new 7892af0d46 [Unity][WebGPU] Allow lower max storage buffer binding size
(#16108)
7892af0d46 is described below
commit 7892af0d46f38c031aea61b1ffbc4e0e21041df5
Author: Charlie Ruan <[email protected]>
AuthorDate: Sat Nov 11 16:03:59 2023 -0500
[Unity][WebGPU] Allow lower max storage buffer binding size (#16108)
This PR lowers the required `maxStorageBufferBindingSize` from 1GB to 128MB
when necessary.
Previously, we required 1GB, which led to errors when running on some
devices (e.g. Android's Chrome, since Android has 128MB as its limit).
Now, if the device does not allow 1GB, we lower it to 128MB. We only throw
an error when 128MB still exceeds the limit.
---
web/src/webgpu.ts | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/web/src/webgpu.ts b/web/src/webgpu.ts
index 5ffed62cf9..fb4d868f45 100644
--- a/web/src/webgpu.ts
+++ b/web/src/webgpu.ts
@@ -55,13 +55,25 @@ export async function detectGPUDevice():
Promise<GPUDeviceDetectOutput | undefin
);
}
- const requiredMaxStorageBufferBindingSize = 1 << 30;
+ let requiredMaxStorageBufferBindingSize = 1 << 30; // 1GB
if (requiredMaxStorageBufferBindingSize >
adapter.limits.maxStorageBufferBindingSize) {
- throw Error(
- `Cannot initialize runtime because of requested
maxStorageBufferBindingSize ` +
- `exceeds limit.
requested=${computeMB(requiredMaxStorageBufferBindingSize)}, ` +
- `limit=${computeMB(adapter.limits.maxStorageBufferBindingSize)}. `
+ // If 1GB is too large, try 128MB (default size for Android)
+ const backupRequiredMaxStorageBufferBindingSize = 1 << 27; // 128MB
+ console.log(
+ `Requested maxStorageBufferBindingSize exceeds limit. \n` +
+ `requested=${computeMB(requiredMaxStorageBufferBindingSize)}, \n` +
+ `limit=${computeMB(adapter.limits.maxStorageBufferBindingSize)}. \n` +
+ `WARNING: Falling back to
${computeMB(backupRequiredMaxStorageBufferBindingSize)}...`
);
+ requiredMaxStorageBufferBindingSize =
backupRequiredMaxStorageBufferBindingSize;
+ if (backupRequiredMaxStorageBufferBindingSize >
adapter.limits.maxStorageBufferBindingSize) {
+ // Fail if 128MB is still too big
+ throw Error(
+ `Cannot initialize runtime because of requested
maxStorageBufferBindingSize ` +
+ `exceeds limit.
requested=${computeMB(backupRequiredMaxStorageBufferBindingSize)}, ` +
+ `limit=${computeMB(adapter.limits.maxStorageBufferBindingSize)}. `
+ );
+ }
}
const requiredMaxComputeWorkgroupStorageSize = 32 << 10;