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

Method getUserCode

tfjs-backend-webgpu/src/concat_webgpu.ts:50–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48 }
49
50 getUserCode(): string {
51 const snippets: string[] = [];
52 if (this.offsetLength > 0) {
53 snippets.push(
54 `if (yC < uniforms.offset0){ setOutputAtCoords(coords.x, coords.y, getT0(yR, yC)); }`);
55 for (let i = 1; i < this.offsetLength; i++) {
56 snippets.push(
57 `else if (yC < uniforms.offset${[i]}){ ` +
58 `setOutputAtCoords(coords.x, coords.y, getT${
59 i}(yR, yC - uniforms.offset${i - 1})); }`);
60 }
61 const lastIndex = this.offsetLength;
62 const lastShiftIndex = this.offsetLength - 1;
63 snippets.push(`else { setOutputAtCoords(coords.x, coords.y, getT${
64 lastIndex}(yR, yC - uniforms.offset${lastShiftIndex})); }`);
65 } else {
66 snippets.push(`setOutputAtCoords(coords.x, coords.y, getT0(yR, yC));`);
67 }
68
69 const userCode = `
70 ${main('index')} {
71 for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
72 let flatIndex = index * ${this.workPerThread} + i;
73 if(flatIndex < uniforms.size) {
74 let coords = getCoordsFromIndex(flatIndex);
75 let yR = coords.x;
76 let yC = coords.y;
77
78 ${snippets.join('\n ')}
79 }
80 }
81 }
82 `;
83 return userCode;
84 }
85}

Callers

nothing calls this directly

Calls 3

joinMethod · 0.80
mainFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected