You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "guan404ming (via GitHub)" <gi...@apache.org> on 2026/06/16 13:03:46 UTC

[PR] Destroy GPUDevice once on buffer creation error [tvm]

guan404ming opened a new pull request, #19790:
URL: https://github.com/apache/tvm/pull/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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Web] Destroy GPUDevice once on buffer creation error [tvm]

Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming merged PR #19790:
URL: https://github.com/apache/tvm/pull/19790


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Web] Destroy GPUDevice once on buffer creation error [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19790:
URL: https://github.com/apache/tvm/pull/19790#discussion_r3420914613


##########
web/src/webgpu.ts:
##########
@@ -169,9 +169,18 @@ 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 !== null);
+    if (captured.length > 0) {
+      device.destroy();
+      captured.forEach((error) => console.error(error));
+    }
+  });

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   1. **Unhandled Promise Rejection**: If `popErrorScope()` rejects (e.g., if the device is already lost), the `Promise.all` promise will reject. Without a `.catch()` block, this results in an unhandled promise rejection.
   2. **TypeScript Type Guard**: Using `errors.filter(error => error !== null)` does not narrow the type of `captured` to `GPUError[]` in TypeScript. Adding an explicit type guard `(error): error is GPUError => error !== null` ensures proper type safety.
   
   ```suggestion
     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);
     });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org