(
program: GPGPUProgram, inputs: TensorInfo[], outputDtype: DataType,
customUniformValues?: number[][], preventEagerUnpackingOfOutput = false,
customTexShape?: [number, number])
| 872 | } |
| 873 | |
| 874 | runWebGLProgram( |
| 875 | program: GPGPUProgram, inputs: TensorInfo[], outputDtype: DataType, |
| 876 | customUniformValues?: number[][], preventEagerUnpackingOfOutput = false, |
| 877 | customTexShape?: [number, number]): TensorInfo { |
| 878 | const output = this.makeTensorInfo(program.outputShape, outputDtype); |
| 879 | const outData = this.texData.get(output.dataId); |
| 880 | if (program.packedOutput) { |
| 881 | outData.isPacked = true; |
| 882 | } |
| 883 | if (program.outPackingScheme === tex_util.PackingScheme.DENSE) { |
| 884 | const texelShape = customTexShape != null ? |
| 885 | customTexShape : |
| 886 | tex_util.getDenseTexShape(program.outputShape); |
| 887 | // For a densely packed output, we explicitly set texShape |
| 888 | // so it doesn't get assigned later according to our typical packing |
| 889 | // scheme wherein a single texel can only contain values from adjacent |
| 890 | // rows/cols. |
| 891 | outData.texShape = texelShape.map(d => d * 2) as [number, number]; |
| 892 | } |
| 893 | if (program.outTexUsage != null) { |
| 894 | outData.usage = program.outTexUsage; |
| 895 | } |
| 896 | |
| 897 | if (util.sizeFromShape(output.shape) === 0) { |
| 898 | // Short-circuit the computation since the result is empty (has 0 in its |
| 899 | // shape). |
| 900 | outData.values = |
| 901 | util.getTypedArrayFromDType(output.dtype as 'float32', 0); |
| 902 | return output; |
| 903 | } |
| 904 | |
| 905 | const dataToDispose: TensorInfo[] = []; |
| 906 | const inputsData: TensorData[] = inputs.map(input => { |
| 907 | if (input.dtype === 'complex64') { |
| 908 | throw new Error( |
| 909 | `GPGPUProgram does not support complex64 input. For complex64 ` + |
| 910 | `dtypes, please separate the program into real and imaginary ` + |
| 911 | `parts.`); |
| 912 | } |
| 913 | |
| 914 | let texData = this.texData.get(input.dataId); |
| 915 | |
| 916 | if (texData.texture == null) { |
| 917 | if (!program.packedInputs && |
| 918 | util.sizeFromShape(input.shape) <= |
| 919 | env().getNumber('WEBGL_SIZE_UPLOAD_UNIFORM')) { |
| 920 | // Upload small tensors that live on the CPU as uniforms, not as |
| 921 | // textures. Do this only when the environment supports 32bit floats |
| 922 | // due to problems when comparing 16bit floats with 32bit floats. |
| 923 | // TODO(https://github.com/tensorflow/tfjs/issues/821): Make it |
| 924 | // possible for packed shaders to sample from uniforms. |
| 925 | return { |
| 926 | shape: input.shape, |
| 927 | texData: null, |
| 928 | isUniform: true, |
| 929 | uniformValues: texData.values as TypedArray |
| 930 | }; |
| 931 | } |
no test coverage detected