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

Method read

tfjs-backend-webgpu/src/backend_webgpu.ts:508–538  ·  view source on GitHub ↗
(dataId: object)

Source from the content-addressed store, hash-verified

506 }
507
508 override async read(dataId: object): Promise<BackendValues> {
509 if (!this.tensorMap.has(dataId)) {
510 throw new Error(`Tensor ${dataId} was not registered!`);
511 }
512 const tensorData = this.tensorMap.get(dataId);
513
514 const {values} = tensorData;
515
516 if (values != null) {
517 return values;
518 }
519
520 // Download the values from the GPU.
521 let vals: BackendValues;
522 if (tensorData.dtype === 'complex64') {
523 const ps = await Promise.all([
524 this.read(tensorData.complexTensorInfos.real.dataId),
525 this.read(tensorData.complexTensorInfos.imag.dataId)
526 ]);
527
528 const realValues = ps[0];
529 const imagValues = ps[1];
530 vals = backend_util.mergeRealAndImagArrays(
531 realValues as Float32Array, imagValues as Float32Array);
532 } else {
533 const data = await this.getBufferData(tensorData.resource as GPUBuffer);
534 vals = util.convertBackendValuesAndArrayBuffer(data, tensorData.dtype);
535 }
536 this.convertAndCacheOnCPU(dataId, vals);
537 return vals;
538 }
539
540 // The source GPUBuffer and destination GPUBuffer have the same size and
541 // usage.

Callers

nothing calls this directly

Calls 5

getBufferDataMethod · 0.95
convertAndCacheOnCPUMethod · 0.95
hasMethod · 0.80
allMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected