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

Method getUserCode

tfjs-backend-webgpu/src/cum_webgpu.ts:53–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51 }
52
53 getUserCode(): string {
54 const rank = this.outputShape.length;
55 const initVal = this.op === CumOpType.Prod ? '1.0' : '0.0';
56 const val = this.exclusive ? initVal :
57 `getX(${getCoords(rank, 'coords', this.op)})`;
58 const length = this.outputShape[this.outputShape.length - 1];
59 let condition = '';
60 let idxString = '';
61 // When exclusive is set, the cum op becomes roll op that copies the
62 // value from the previous index based on the direction specified by the
63 // reverse flag.
64 if (this.exclusive) {
65 condition = this.reverse ? `end != ${length - 1}` : 'end != 0';
66 idxString = this.reverse ? 'end + 1' : 'end - 1';
67 } else {
68 condition = this.reverse ? `end + pow2 < ${length}` : 'end >= pow2';
69 idxString = (this.reverse ? 'end + pow2' : 'end - pow2');
70 }
71 return `
72 ${main('index')} {
73 if (index < uniforms.size) {
74 var coords = getCoordsFromIndex(index);
75
76 let end = ${getFinalCoord(rank, 'coords', this.op)};
77 var val = ${val};
78 let pow2 = i32(pow(2.0, uniforms.index));
79 if (${condition}) {
80 let idx = ${idxString};
81 ${getFinalCoord(rank, 'coords', this.op)} = idx;
82 val ${this.op}= getX(${getCoords(rank, 'coords', this.op)});
83 }
84 setOutputAtIndex(index, val);
85 }
86 }
87 `;
88 }
89}
90
91function getCoords(rank: number, name: string, op: CumOpType): string {

Callers 1

makeShaderFunction · 0.45

Calls 3

getCoordsFunction · 0.70
getFinalCoordFunction · 0.70
mainFunction · 0.50

Tested by

no test coverage detected