(args: {
inputs: MaxPoolGradInputs,
backend: WebGPUBackend,
attrs: MaxPoolGradAttrs
})
| 23 | import {assertNotComplex} from '../webgpu_util'; |
| 24 | |
| 25 | export function maxPoolGrad(args: { |
| 26 | inputs: MaxPoolGradInputs, |
| 27 | backend: WebGPUBackend, |
| 28 | attrs: MaxPoolGradAttrs |
| 29 | }): TensorInfo { |
| 30 | const {inputs, backend, attrs} = args; |
| 31 | const {dy, input, output} = inputs; |
| 32 | const x = input; |
| 33 | assertNotComplex([input, output], 'maxPoolGrad'); |
| 34 | const {filterSize, strides, pad, dimRoundingMode} = attrs; |
| 35 | |
| 36 | const convInfo = backend_util.computePool2DInfo( |
| 37 | x.shape as [number, number, number, number], filterSize, strides, |
| 38 | 1 /* dilations */, pad, dimRoundingMode); |
| 39 | |
| 40 | const maxPoolPositionsProgram = new Pool2DProgram(convInfo, 'max', true); |
| 41 | let uniformData = [ |
| 42 | {type: 'int32', data: [convInfo.strideHeight, convInfo.strideWidth]}, |
| 43 | {type: 'int32', data: [convInfo.padInfo.top, convInfo.padInfo.left]}, |
| 44 | {type: 'int32', data: [convInfo.dilationHeight, convInfo.dilationWidth]}, |
| 45 | {type: 'int32', data: [convInfo.inHeight, convInfo.inWidth]}, { |
| 46 | type: 'int32', |
| 47 | data: [convInfo.effectiveFilterHeight, convInfo.effectiveFilterWidth] |
| 48 | } |
| 49 | ]; |
| 50 | const maxPoolPositions = backend.runWebGPUProgram( |
| 51 | maxPoolPositionsProgram, [x], 'int32', uniformData); |
| 52 | |
| 53 | const maxPoolBackpropProgram = new MaxPool2DBackpropProgram(convInfo); |
| 54 | uniformData = [ |
| 55 | {type: 'int32', data: [convInfo.strideHeight, convInfo.strideWidth]}, { |
| 56 | type: 'int32', |
| 57 | data: [ |
| 58 | convInfo.effectiveFilterHeight - 1 - convInfo.padInfo.top, |
| 59 | convInfo.effectiveFilterWidth - 1 - convInfo.padInfo.left |
| 60 | ] |
| 61 | }, |
| 62 | {type: 'int32', data: [convInfo.dilationHeight, convInfo.dilationWidth]}, { |
| 63 | type: 'int32', |
| 64 | data: [convInfo.effectiveFilterHeight, convInfo.effectiveFilterWidth] |
| 65 | }, |
| 66 | {type: 'int32', data: [convInfo.outHeight]}, |
| 67 | {type: 'int32', data: [convInfo.outWidth]} |
| 68 | ]; |
| 69 | const result = backend.runWebGPUProgram( |
| 70 | maxPoolBackpropProgram, [dy, maxPoolPositions], x.dtype, uniformData); |
| 71 | backend.disposeData(maxPoolPositions.dataId); |
| 72 | |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | export const maxPoolGradConfig: KernelConfig = { |
| 77 | kernelName: MaxPoolGrad, |
nothing calls this directly
no test coverage detected
searching dependent graphs…