MCPcopy Create free account
hub / github.com/tensorflow/tfjs / runProgram

Function runProgram

tfjs-backend-webgl/src/gpgpu_math.ts:239–403  ·  view source on GitHub ↗
(
    gpgpu: GPGPUContext, binary: GPGPUBinary, inputs: TensorData[],
    output: TensorData, customUniformValues?: number[][])

Source from the content-addressed store, hash-verified

237}
238
239export function runProgram<T extends Tensor, K extends Tensor>(
240 gpgpu: GPGPUContext, binary: GPGPUBinary, inputs: TensorData[],
241 output: TensorData, customUniformValues?: number[][]): void {
242 if (!binary.program.enableShapeUniforms) {
243 validateBinaryAndProgram(binary.inShapeInfos, inputs);
244 validateBinaryAndProgram([binary.outShapeInfo], [output]);
245 }
246
247 const outTex = output.texData.texture;
248 const outTexShape = output.texData.texShape;
249 if (output.texData.isPacked) {
250 gpgpu.setOutputPackedMatrixTexture(
251 outTex.texture, outTexShape[0], outTexShape[1]);
252 } else {
253 gpgpu.setOutputMatrixTexture(
254 outTex.texture, outTexShape[0], outTexShape[1]);
255 }
256 gpgpu.setProgram(binary.webGLProgram);
257 gpgpu.bindVertexArray(binary.webGLProgram.vao);
258
259 // Set special uniforms (NAN, INFINITY)
260 if (env().getNumber('WEBGL_VERSION') === 1) {
261 if (binary.infLoc !== null) {
262 gpgpu.gl.uniform1f(binary.infLoc, Infinity);
263 }
264 }
265 if (binary.nanLoc !== null) {
266 gpgpu.gl.uniform1f(binary.nanLoc, NaN);
267 }
268
269 // Set user-defined inputs
270 for (let i = 0; i < inputs.length; ++i) {
271 const input = inputs[i];
272 const {
273 uniform: varLoc,
274 offset: varOffsetLoc,
275 shape: varShapeLoc,
276 texShape: varTexShapeLoc,
277 } = binary.variablesLocations[i];
278
279 if (varShapeLoc) {
280 const {uniformShape} = shader_compiler.getUniformInfoFromShape(
281 binary.program.packedInputs, input.shape, input.texData.texShape);
282 switch (uniformShape.length) {
283 case 1:
284 gpgpu.gl.uniform1iv(varShapeLoc, new Int32Array(uniformShape));
285 break;
286 case 2:
287 gpgpu.gl.uniform2iv(varShapeLoc, new Int32Array(uniformShape));
288 break;
289 case 3:
290 gpgpu.gl.uniform3iv(varShapeLoc, new Int32Array(uniformShape));
291 break;
292 case 4:
293 gpgpu.gl.uniform4iv(varShapeLoc, new Int32Array(uniformShape));
294 break;
295 default:
296 break;

Callers

nothing calls this directly

Calls 9

envFunction · 0.90
validateBinaryAndProgramFunction · 0.85
ErrorFunction · 0.85
setProgramMethod · 0.80
getNumberMethod · 0.80
setInputMatrixTextureMethod · 0.80
executeProgramMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…