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

Function createGPUBufferFromData

tfjs-backend-webgpu/src/backend_webgpu_test.ts:510–528  ·  view source on GitHub ↗
(
    device: GPUDevice, data: number[], dtype: tf.DataType,
    bufferUsage = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE |
        GPUBufferUsage.COPY_SRC)

Source from the content-addressed store, hash-verified

508}
509
510function createGPUBufferFromData(
511 device: GPUDevice, data: number[], dtype: tf.DataType,
512 bufferUsage = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE |
513 GPUBufferUsage.COPY_SRC) {
514 const bytesPerElement = 4;
515 const sizeInBytes = data.length * bytesPerElement;
516
517 const gpuWriteBuffer = createStagingGPUBufferFromData(device, data, dtype);
518 const gpuReadBuffer = device.createBuffer(
519 {mappedAtCreation: false, size: sizeInBytes, usage: bufferUsage});
520
521 const copyEncoder = device.createCommandEncoder();
522 copyEncoder.copyBufferToBuffer(
523 gpuWriteBuffer, 0, gpuReadBuffer, 0, sizeInBytes);
524 const copyCommands = copyEncoder.finish();
525 device.queue.submit([copyCommands]);
526 gpuWriteBuffer.destroy();
527 return gpuReadBuffer;
528}
529
530async function testCreateTensorFromGPUBuffer(
531 dtype: tf.DataType, useDefaultShapeAndType = false, zeroCopy = false) {

Callers 2

createTensorFromGPUTestFunction · 0.85

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…