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

Method getUserCode

tfjs-backend-webgpu/src/reverse_webgpu.ts:40–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38 }
39
40 getUserCode(): string {
41 const reverseCoordsSnippet = `
42 // Using uniform variables as judging conditions, so the function has
43 // coherent execution within all threads.
44 fn getReverseCoords(coords : vec4<i32>) -> vec4<i32> {
45 var reverseCoords = coords;
46 if (uniforms.axis[0] == 1) {
47 reverseCoords[0] = uniforms.xShape[0] - coords[0] - 1;
48 }
49 if (uniforms.axis[1] == 1) {
50 reverseCoords[1] = uniforms.xShape[1] - coords[1] - 1;
51 }
52 if (uniforms.axis[2] == 1) {
53 reverseCoords[2] = uniforms.xShape[2] - coords[2] - 1;
54 }
55 if (uniforms.axis[3] == 1) {
56 reverseCoords[3] = uniforms.xShape[3] - coords[3] - 1;
57 }
58
59 return reverseCoords;
60 }
61 `;
62 const userCode = `
63 ${reverseCoordsSnippet}
64 ${main('index')} {
65 if (index < uniforms.size) {
66 let coords = getCoordsFromIndex(index);
67 let reverseCoords = getReverseCoords(coords);
68 setOutputAtIndex(index, getX(reverseCoords[0],
69 reverseCoords[1], reverseCoords[2], reverseCoords[3]));
70 }
71 }
72 `;
73 return userCode;
74 }
75}

Callers

nothing calls this directly

Calls 1

mainFunction · 0.50

Tested by

no test coverage detected