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

Function symbolicallyComputeStrides

tfjs-backend-webgpu/src/shader_util.ts:19–35  ·  view source on GitHub ↗
(
    indicesArr: number[], variableName: string)

Source from the content-addressed store, hash-verified

17
18// Generates WGSL that computes strides.
19export function symbolicallyComputeStrides(
20 indicesArr: number[], variableName: string): string[] {
21 if (Math.max(...indicesArr) > 5) {
22 throw new Error('Cannot symbolically compute strides for rank > 6 tensor.');
23 }
24
25 const numCoords = indicesArr.length;
26 const indicesStr = 'xyzwuv';
27 const shape = indicesArr.map(d => `${variableName}.${indicesStr[d]}`);
28 const strides = new Array(numCoords - 1);
29 strides[numCoords - 2] = shape[numCoords - 1];
30 for (let i = numCoords - 3; i >= 0; --i) {
31 strides[i] = `(${strides[i + 1]} * ${shape[i + 1]})`;
32 }
33
34 return strides;
35}
36
37export const atomicAddSnippet =
38 (ptr: string, v: string, type: 'int32'|'float32') => {

Callers 2

getOutputCoordsSnippetFunction · 0.90

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…