(args: {
inputs: MaxPoolWithArgmaxInputs,
attrs: MaxPoolWithArgmaxAttrs,
backend: WebGPUBackend
})
| 22 | import {Pool2DProgram} from '../pool_webgpu'; |
| 23 | |
| 24 | export function maxPoolWithArgmax(args: { |
| 25 | inputs: MaxPoolWithArgmaxInputs, |
| 26 | attrs: MaxPoolWithArgmaxAttrs, |
| 27 | backend: WebGPUBackend |
| 28 | }): TensorInfo[] { |
| 29 | const {inputs, backend, attrs} = args; |
| 30 | const {filterSize, strides, pad, includeBatchInIndex} = attrs; |
| 31 | const {x} = inputs; |
| 32 | |
| 33 | util.assert( |
| 34 | x.shape.length === 4, |
| 35 | () => `Error in maxPool: input must be rank 4 but got rank ${ |
| 36 | x.shape.length}.`); |
| 37 | const dilations: [number, number] = [1, 1]; |
| 38 | util.assert( |
| 39 | backend_util.eitherStridesOrDilationsAreOne(strides, dilations), |
| 40 | () => 'Error in maxPool: Either strides or dilations must be 1. ' + |
| 41 | `Got strides ${strides} and dilations '${dilations}'`); |
| 42 | |
| 43 | const convInfo = backend_util.computePool2DInfo( |
| 44 | x.shape as [number, number, number, number], filterSize, strides, |
| 45 | dilations, pad); |
| 46 | |
| 47 | const uniformData = [ |
| 48 | {type: 'int32', data: [convInfo.strideHeight, convInfo.strideWidth]}, |
| 49 | {type: 'int32', data: [convInfo.padInfo.top, convInfo.padInfo.left]}, |
| 50 | {type: 'int32', data: [convInfo.dilationHeight, convInfo.dilationWidth]}, |
| 51 | {type: 'int32', data: [convInfo.inHeight, convInfo.inWidth]}, { |
| 52 | type: 'int32', |
| 53 | data: [convInfo.effectiveFilterHeight, convInfo.effectiveFilterWidth] |
| 54 | } |
| 55 | ]; |
| 56 | let program = new Pool2DProgram(convInfo, 'max', false); |
| 57 | const poolOutput = |
| 58 | backend.runWebGPUProgram(program, [x], x.dtype, uniformData); |
| 59 | |
| 60 | program = new Pool2DProgram(convInfo, 'max', true, true, includeBatchInIndex); |
| 61 | const indexOutput = |
| 62 | backend.runWebGPUProgram(program, [x], 'int32', uniformData); |
| 63 | return [poolOutput, indexOutput]; |
| 64 | } |
| 65 | |
| 66 | export const maxPoolWithArgmaxConfig: KernelConfig = { |
| 67 | kernelName: MaxPoolWithArgmax, |
nothing calls this directly
no test coverage detected
searching dependent graphs…