MCPcopy
hub / github.com/tensorflow/tfjs / runWebGLProgram

Method runWebGLProgram

tfjs-backend-webgl/src/backend_webgl.ts:874–1015  ·  view source on GitHub ↗
(
      program: GPGPUProgram, inputs: TensorInfo[], outputDtype: DataType,
      customUniformValues?: number[][], preventEagerUnpackingOfOutput = false,
      customTexShape?: [number, number])

Source from the content-addressed store, hash-verified

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 }

Callers 15

writeTextureMethod · 0.95
readSyncMethod · 0.95
readMethod · 0.95
readToGPUMethod · 0.95
getValuesFromTextureMethod · 0.95
unpackTensorMethod · 0.95
packTensorMethod · 0.95
packedReshapeMethod · 0.95
decodeMethod · 0.95
compileAndRunMethod · 0.95
uploadToGPUMethod · 0.95
reduceFunction · 0.80

Calls 15

makeTensorInfoMethod · 0.95
uploadToGPUMethod · 0.95
unpackTensorMethod · 0.95
packTensorMethod · 0.95
packedReshapeMethod · 0.95
getAndSaveBinaryMethod · 0.95
startTimerMethod · 0.95
endTimerMethod · 0.95
getQueryTimeMethod · 0.95
envFunction · 0.90
getNumberMethod · 0.80

Tested by

no test coverage detected