mitiskuma commented on code in PR #18871:
URL: https://github.com/apache/tvm/pull/18871#discussion_r2890801647


##########
web/src/webgpu.ts:
##########
@@ -903,11 +973,15 @@ export class WebGPUContext {
     const copyCommands = copyEncoder.finish();
     this.device.queue.submit([copyCommands]);
 
-    gpuTemp.mapAsync(GPUMapMode.READ).then(() => {
-      const data = gpuTemp.getMappedRange();
+    const readPromise = gpuTemp.mapAsync(GPUMapMode.READ).then(() => {
+      const data = gpuTemp.getMappedRange(0, nbytes);
       this.memory.storeRawBytes(to, new Uint8Array(data));
-      gpuTemp.destroy();
+      this.returnReadStagingBuffer(gpuTemp);
     });
+    // Chain with any existing pending read so sync() awaits all of them.
+    this.pendingRead = this.pendingRead
+      ? this.pendingRead.then(() => readPromise)
+      : readPromise;
   }

Review Comment:
   1. Out-of-order writes to same address: Not a real concern, TVM never issues 
overlapping readbacks to the same Wasm address concurrently. Each 
deviceCopyFromGPU targets a different destination.
   2. Rejected promise breaking the chain: This is valid. If mapAsync rejects 
(device loss), the chain breaks. However, device loss is already fatal, 
device.lost triggers shutdown. So this is a theoretical concern that doesn't 
manifest in practice.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to