| 41 | } |
| 42 | |
| 43 | getUserCode(): string { |
| 44 | const userCode = ` |
| 45 | ${main('index')} { |
| 46 | if (index < uniforms.size) { |
| 47 | let neg_infinity = -3.4e38; |
| 48 | let coords = getOutputCoords(); |
| 49 | let batch = coords.x; |
| 50 | let d1 = coords.w; |
| 51 | let outTopLeftCorner = coords.yz * uniforms.strides - uniforms.pads; |
| 52 | let hBeg = outTopLeftCorner.x; |
| 53 | let wBeg = outTopLeftCorner.y; |
| 54 | |
| 55 | var curVal = neg_infinity; |
| 56 | for (var h = 0; h < uniforms.filterDims[0]; h = h + 1) { |
| 57 | let hIn = hBeg + h * uniforms.dilations[0]; |
| 58 | |
| 59 | if (hIn >= 0 && hIn < uniforms.xShape[1]) { |
| 60 | for (var w = 0; w < uniforms.filterDims[1]; w = w + 1) { |
| 61 | let wIn = wBeg + w * uniforms.dilations[1]; |
| 62 | |
| 63 | if (wIn >= 0 && wIn < uniforms.xShape[2]) { |
| 64 | let val = getX(batch, hIn, wIn, d1) + getW(h, w, d1); |
| 65 | if (val > curVal) { |
| 66 | curVal = val; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | setOutputAtIndex(index, curVal); |
| 74 | } |
| 75 | } |
| 76 | `; |
| 77 | return userCode; |
| 78 | } |
| 79 | } |