MCPcopy Index your code
hub / github.com/apache/tvm / deviceCopyFromGPU

Method deviceCopyFromGPU

web/src/webgpu.ts:1002–1032  ·  view source on GitHub ↗
(
    from: GPUPointer,
    fromOffset: number,
    to: Pointer,
    nbytes: number
  )

Source from the content-addressed store, hash-verified

1000 }
1001
1002 private deviceCopyFromGPU(
1003 from: GPUPointer,
1004 fromOffset: number,
1005 to: Pointer,
1006 nbytes: number
1007 ): void {
1008 // Flush batched compute passes before the readback copy.
1009 this.flushCommands();
1010 const gpuTemp = this.getOrCreateReadStagingBuffer(nbytes);
1011
1012 const copyEncoder = this.device.createCommandEncoder();
1013 copyEncoder.copyBufferToBuffer(
1014 this.gpuBufferFromPtr(from),
1015 fromOffset,
1016 gpuTemp,
1017 0,
1018 nbytes
1019 );
1020 const copyCommands = copyEncoder.finish();
1021 this.device.queue.submit([copyCommands]);
1022
1023 const readPromise = gpuTemp.mapAsync(GPUMapMode.READ).then(() => {
1024 const data = gpuTemp.getMappedRange(0, nbytes);
1025 this.memory.storeRawBytes(to, new Uint8Array(data));
1026 this.recycleReadStagingBuffer(gpuTemp);
1027 });
1028 // Chain with any existing pending read so sync() awaits all of them.
1029 this.pendingGPUToCPUCopy = this.pendingGPUToCPUCopy
1030 ? this.pendingGPUToCPUCopy.then(() => readPromise)
1031 : readPromise;
1032 }
1033
1034 private deviceCopyWithinGPU(
1035 from: GPUPointer,

Callers 1

getDeviceAPIMethod · 0.95

Calls 7

flushCommandsMethod · 0.95
gpuBufferFromPtrMethod · 0.95
finishMethod · 0.80
submitMethod · 0.80
storeRawBytesMethod · 0.45

Tested by

no test coverage detected