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

Method getOrCreateReadStagingBuffer

web/src/webgpu.ts:970–981  ·  view source on GitHub ↗

* Get a MAP_READ staging buffer from the pool, or create one if none fits. * Uses first-fit-by-size: returns the first pooled buffer >= nbytes.

(nbytes: number)

Source from the content-addressed store, hash-verified

968 * Uses first-fit-by-size: returns the first pooled buffer >= nbytes.
969 */
970 private getOrCreateReadStagingBuffer(nbytes: number): GPUBuffer {
971 for (let i = 0; i < this.readStagingBufferPool.length; i++) {
972 if (this.readStagingBufferPool[i].size >= nbytes) {
973 const entry = this.readStagingBufferPool.splice(i, 1)[0];
974 return entry.buffer;
975 }
976 }
977 return tryCreateBuffer(this.device, {
978 size: nbytes,
979 usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
980 });
981 }
982
983 /**
984 * Return a MAP_READ staging buffer to the pool for reuse.

Callers 1

deviceCopyFromGPUMethod · 0.95

Calls 1

tryCreateBufferFunction · 0.85

Tested by

no test coverage detected