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

Method deviceCopyToGPU

web/src/webgpu.ts:938–964  ·  view source on GitHub ↗
(
    from: Pointer,
    to: GPUPointer,
    toOffset: number,
    nbytes: number
  )

Source from the content-addressed store, hash-verified

936 }
937
938 private deviceCopyToGPU(
939 from: Pointer,
940 to: GPUPointer,
941 toOffset: number,
942 nbytes: number
943 ): void {
944 // Flush batched compute passes before writing to a GPU buffer,
945 // otherwise the write may be reordered before pending dispatches
946 // that read from the same buffer.
947 this.flushCommands();
948 let rawBytes = this.memory.loadRawBytes(from, nbytes);
949 if (rawBytes.length % 4 !== 0) {
950 // writeBuffer requires length to be multiples of 4, so we pad here
951 const toPad = 4 - rawBytes.length % 4;
952 const padded = new Uint8Array(rawBytes.length + toPad);
953 padded.set(rawBytes);
954 rawBytes = padded;
955 nbytes = nbytes + toPad;
956 }
957 this.device.queue.writeBuffer(
958 this.gpuBufferFromPtr(to),
959 toOffset,
960 rawBytes as GPUAllowSharedBufferSource,
961 0,
962 nbytes
963 );
964 }
965
966 /**
967 * Get a MAP_READ staging buffer from the pool, or create one if none fits.

Callers 1

getDeviceAPIMethod · 0.95

Calls 3

flushCommandsMethod · 0.95
gpuBufferFromPtrMethod · 0.95
loadRawBytesMethod · 0.80

Tested by

no test coverage detected