(
device: GPUDevice, data: number[], dtype: tf.DataType,
bufferUsage = GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE |
GPUBufferUsage.COPY_SRC)
| 508 | } |
| 509 | |
| 510 | function 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 | |
| 530 | async function testCreateTensorFromGPUBuffer( |
| 531 | dtype: tf.DataType, useDefaultShapeAndType = false, zeroCopy = false) { |
no test coverage detected
searching dependent graphs…