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

Function maxPoolWithArgmax

tfjs-backend-webgpu/src/kernels/MaxPoolWithArgmax.ts:24–64  ·  view source on GitHub ↗
(args: {
  inputs: MaxPoolWithArgmaxInputs,
  attrs: MaxPoolWithArgmaxAttrs,
  backend: WebGPUBackend
})

Source from the content-addressed store, hash-verified

22import {Pool2DProgram} from '../pool_webgpu';
23
24export 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
66export const maxPoolWithArgmaxConfig: KernelConfig = {
67 kernelName: MaxPoolWithArgmax,

Callers

nothing calls this directly

Calls 1

runWebGPUProgramMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…