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

Method getUserCode

tfjs-backend-webgpu/src/lrn_grad_webgpu.ts:39–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37 }
38
39 getUserCode(): string {
40 const userCode = `
41 ${main('index')} {
42 if (index < uniforms.size) {
43 let coords = getOutputCoords();
44 let b = coords[0];
45 let r = coords[1];
46 let c = coords[2];
47
48 let MIN_DEPTH_BEGIN = 0;
49 let MAX_DEPTH_END = uniforms.outShape[3];
50 var result = 0.0;
51 for (var d = MIN_DEPTH_BEGIN; d < MAX_DEPTH_END; d++) {
52 let depthBegin = max(MIN_DEPTH_BEGIN, d - uniforms.depthRadius);
53 let depthEnd = min(MAX_DEPTH_END, d + uniforms.depthRadius + 1);
54
55 var norm = 0.0;
56 for (var k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; k++) {
57 if (k < depthBegin) {
58 continue;
59 } else if (k >= depthBegin && k < depthEnd) {
60 norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);
61 } else {
62 break;
63 }
64 }
65
66 norm = uniforms.alpha * norm + uniforms.bias;
67
68 for (var k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; k++) {
69 if (k < depthBegin) {
70 continue;
71 } else if (k >= depthBegin && k < depthEnd) {
72 var dyi = -2.0 * uniforms.alpha * uniforms.beta
73 * getInputImage(b, r, c, k) * getOutputImage(b, r, c, d) / norm;
74 if (k == d) {
75 dyi += pow(norm, -1.0 * uniforms.beta);
76 }
77 if (k == coords[3]) {
78 dyi *= getDy(b, r, c, d);
79 result += dyi;
80 }
81 } else {
82 break;
83 }
84 }
85 }
86
87 setOutputAtIndex(index, result);
88 }
89 }
90 `;
91 return userCode;
92 }
93}

Callers

nothing calls this directly

Calls 1

mainFunction · 0.50

Tested by

no test coverage detected