This is an automated email from the ASF dual-hosted git repository.
guan404ming pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 27406a911c [Web] Destroy GPUDevice once on buffer creation error
(#19790)
27406a911c is described below
commit 27406a911cbcba40828ff6fba665e2f0b34ed44d
Author: Guan-Ming (Wesley) Chiu <[email protected]>
AuthorDate: Tue Jun 16 22:44:45 2026 +0800
[Web] Destroy GPUDevice once on buffer creation error (#19790)
## Why
In `tryCreateBuffer`, each of the three popped error scopes
independently called `device.destroy()` and `console.error`, so a buffer
that triggers more than one error type destroyed the device repeatedly
and logged duplicate errors.
## How
- Collect all three `popErrorScope()` results via `Promise.all` and call
`device.destroy()` at most once
- Log every captured error instead of relying on per-scope handlers
---------
Signed-off-by: Guan-Ming (Wesley) Chiu
<[email protected]>
Co-authored-by: gemini-code-assist[bot]
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
---
web/src/webgpu.ts | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/web/src/webgpu.ts b/web/src/webgpu.ts
index 199fa14235..5a25833d1a 100644
--- a/web/src/webgpu.ts
+++ b/web/src/webgpu.ts
@@ -169,9 +169,20 @@ function tryCreateBuffer(device: GPUDevice, descriptor:
GPUBufferDescriptor) {
const buffer = device.createBuffer(descriptor);
- device.popErrorScope().then((error) => {if (error) {device.destroy();
console.error(error);}});
- device.popErrorScope().then((error) => {if (error) {device.destroy();
console.error(error);}});
- device.popErrorScope().then((error) => {if (error) {device.destroy();
console.error(error);}});
+ // Destroy at most once even if multiple error types fire.
+ Promise.all([
+ device.popErrorScope(),
+ device.popErrorScope(),
+ device.popErrorScope(),
+ ]).then((errors) => {
+ const captured = errors.filter((error): error is GPUError => error !==
null);
+ if (captured.length > 0) {
+ device.destroy();
+ captured.forEach((error) => console.error(error));
+ }
+ }).catch((err) => {
+ console.error("Failed to pop error scopes:", err);
+ });
return buffer;
}