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

Method getUserCode

tfjs-backend-webgpu/src/im2col_webgpu.ts:43–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41 }
42
43 getUserCode(): string {
44 const rowDim = this.isChannelsLast ? 1 : 2;
45 const colDim = this.isChannelsLast ? 2 : 3;
46
47 const row = this.isChannelsLast ? 'coords[1]' : 'coords[2]';
48 const col = this.isChannelsLast ? 'coords[2]' : 'coords[1]';
49 const getXSnippet = this.isChannelsLast ? 'getX(batch, xRow, xCol, ch)' :
50 'getX(batch, ch, xRow, xCol)';
51
52 const userCode = `
53 ${main('index')} {
54 let coords = getCoordsFromIndex(index);
55 if(index < uniforms.size) {
56 let batch = coords[0];
57 let row = ${row};
58 let col = ${col};
59 let offsetY = (row / uniforms.outWidth) * uniforms.strides[0] - uniforms.pads[0];
60 let xRow = offsetY + uniforms.dilations[0] * (col / uniforms.itemsPerBlockRow);
61 var value = 0.0;
62 if(xRow < uniforms.xShape[${rowDim}] && xRow >= 0) {
63 let offsetX = (row % uniforms.outWidth) * uniforms.strides[1] -
64 uniforms.pads[1];
65 let xCol = offsetX + uniforms.dilations[1] * ((col %
66 uniforms.itemsPerBlockRow) / uniforms.inChannels);
67 let ch = col % uniforms.inChannels;
68 if(xCol < uniforms.xShape[${colDim}] && xCol >= 0) {
69 value = ${getXSnippet};
70 }
71 }
72 setOutputAtIndex(index, value);
73 }
74 }
75 `;
76 return userCode;
77 }
78}

Callers

nothing calls this directly

Calls 1

mainFunction · 0.50

Tested by

no test coverage detected