MCPcopy Index your code
hub / github.com/tensorflow/tfjs / getBufferData

Method getBufferData

tfjs-backend-webgpu/src/backend_webgpu.ts:338–370  ·  view source on GitHub ↗
(buffer: GPUBuffer)

Source from the content-addressed store, hash-verified

336 }
337
338 public async getBufferData(buffer: GPUBuffer): Promise<ArrayBuffer> {
339 if (env().getBool('WEBGPU_ENGINE_COMPILE_ONLY')) {
340 console.warn(
341 'The data may be invalid since WEBGPU_ENGINE_COMPILE_ONLY is true, this can only be called when WEBGPU_ENGINE_COMPILE_ONLY is false');
342 return null;
343 }
344 const size = buffer.size;
345 const stagingBuffer = this.bufferManager.acquireBuffer(
346 size, GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ);
347 this.ensureCommandEncoderReady();
348 this.endComputePassEncoder();
349 this.commandEncoder.copyBufferToBuffer(buffer, 0, stagingBuffer, 0, size);
350 this.submitQueue();
351
352 await stagingBuffer.mapAsync(GPUMapMode.READ);
353 const values = stagingBuffer.getMappedRange().slice(0);
354
355 stagingBuffer.unmap();
356 if (stagingBuffer != null) {
357 this.bufferManager.releaseBuffer(stagingBuffer);
358 }
359
360 // Need to get texture from swapChain to enable profiling tool
361 // to capture a frame
362 if (env().getBool('WEBGPU_USE_PROFILE_TOOL')) {
363 util.assert(
364 this.dummyContext !== undefined,
365 () => `Fail to get context for profiling tool`);
366 this.dummyContext.getCurrentTexture();
367 }
368
369 return values;
370 }
371
372 private convertAndCacheOnCPU(dataId: DataId, data: BackendValues):
373 BackendValues {

Callers 2

readMethod · 0.95

Calls 8

endComputePassEncoderMethod · 0.95
submitQueueMethod · 0.95
envFunction · 0.90
getBoolMethod · 0.80
acquireBufferMethod · 0.80
releaseBufferMethod · 0.80
sliceMethod · 0.65

Tested by

no test coverage detected