* Read tensor to a new texture that is densely packed for ease of use. * @param dataId The source tensor. * @param options * customTexShape: Optional. If set, will use the user defined texture * shape to create the texture.
(dataId: DataId, options: DataToGPUWebGLOption = {})
| 427 | * shape to create the texture. |
| 428 | */ |
| 429 | override readToGPU(dataId: DataId, options: DataToGPUWebGLOption = {}): |
| 430 | GPUData { |
| 431 | const texData = this.texData.get(dataId); |
| 432 | const {values, shape, slice, dtype, isPacked, texture} = texData; |
| 433 | |
| 434 | if (dtype === 'complex64') { |
| 435 | throw new Error('Does not support reading texture for complex64 dtype.'); |
| 436 | } |
| 437 | |
| 438 | // The presence of `slice` indicates this tensor is a shallow slice of a |
| 439 | // different tensor, and is using that original tensor's texture. Run |
| 440 | // `clone` in order to copy that texture and read from it. |
| 441 | if (slice != null) { |
| 442 | let program; |
| 443 | if (isPacked) { |
| 444 | program = new UnaryOpPackedProgram(shape, unary_op.CLONE); |
| 445 | } else { |
| 446 | program = new UnaryOpProgram(shape, unary_op.CLONE); |
| 447 | } |
| 448 | const res = |
| 449 | this.runWebGLProgram(program, [{dataId, shape, dtype}], dtype); |
| 450 | const gpuResouorce = this.readToGPU(res, options); |
| 451 | this.disposeIntermediateTensorInfo(res); |
| 452 | return gpuResouorce; |
| 453 | } |
| 454 | |
| 455 | if (texture == null) { |
| 456 | if (values != null) { |
| 457 | throw new Error('Data is not on GPU but on CPU.'); |
| 458 | } else { |
| 459 | throw new Error('There is no data on GPU or CPU.'); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // Decode the texture so that it is stored densely (using four channels). |
| 464 | const tmpTarget = this.decode(dataId, options.customTexShape); |
| 465 | |
| 466 | // Make engine track this tensor, so that we can dispose it later. |
| 467 | const tensorRef = engine().makeTensorFromTensorInfo(tmpTarget); |
| 468 | |
| 469 | const tmpData = this.texData.get(tmpTarget.dataId); |
| 470 | return {tensorRef, ...tmpData.texture}; |
| 471 | } |
| 472 | |
| 473 | bufferSync<R extends Rank, D extends DataType>(t: TensorInfo): |
| 474 | TensorBuffer<R, D> { |
nothing calls this directly
no test coverage detected