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

Method getUserCode

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

Source from the content-addressed store, hash-verified

48 }
49
50 getUserCode(): string {
51 const rank = this.xShape.length;
52 // The length of paddings are same with the rank of the input tensor.
53 const start = this.xShape.map((_, i) => `uniforms.pad${i}[0]`).join(',');
54 const end = this.xShape
55 .map(
56 (_, i) => `uniforms.pad${i}[0] + uniforms.xShape${
57 rank > 1 ? `[${i}]` : ''}`)
58 .join(',');
59
60 const shaderStart = rank === 1 ? 'start' : 'start[i]';
61 const shaderEnd = rank === 1 ? 'end' : 'end[i]';
62 const shaderOutC = rank === 1 ? 'outC' : 'outC[i]';
63 const dtype = getCoordsDataType(rank);
64 const unpackedCoords = rank > 1 ?
65 ['coords[0]', 'coords[1]', 'coords[2]', 'coords[3]'].slice(0, rank) :
66 'coords';
67
68 return `
69 ${main('index')} {
70 if (index < uniforms.size) {
71 let start = ${dtype}(${start});
72 let end = ${dtype}(${end});
73 var outC = getCoordsFromIndex(index);
74 for (var i = 0; i < ${rank}; i = i + 1) {
75 if (${shaderOutC} < ${shaderStart}) {
76 ${shaderOutC} = ${shaderStart} * 2 - ${shaderOutC} - ${
77 this.offset};
78 } else if(${shaderOutC} >= ${shaderEnd}) {
79 ${shaderOutC} = (${shaderEnd} - 1) * 2 - ${shaderOutC} + ${
80 this.offset};
81 }
82 }
83 let coords = outC - start;
84 setOutputAtIndex(index, getX(${unpackedCoords}));
85 }
86 }
87 `;
88 }
89}

Callers

nothing calls this directly

Calls 4

getCoordsDataTypeFunction · 0.90
joinMethod · 0.80
sliceMethod · 0.65
mainFunction · 0.50

Tested by

no test coverage detected