Perform 1D max pooling on an input tensor:
output[i]=m=0maxk−1input[S⋅i+D⋅m−P]
The max pooling operation slides a window of size k×k over the input tensor with stride S, dilation D, and padding P, computing the maximum value within each window position.
Input:
- Matrix
input of size H (input tensor)
kernel_size (k): Size of the pooling window
stride (S): Step size between window positions
padding (P): Number of zero-padding elements added on all sides
dilation (D): Spacing between kernel elements
Output:
- Matrix
output of size Hout where:
Hout=⌊SH+2P−D(k−1)−1⌋+1
Notes:
- All tensors are stored in row-major order
- Zero padding is applied when specified by the padding parameter
- For values outside the input boundaries (after padding), use negative infinity
- Dilation controls the spacing between kernel elements, creating an effective kernel size of D(k−1)+1
- This problem is adapted from KernelBench
Test Case Sizes
- H=2097152, K=7, S=4, P=3, d=1
- H=4194304, K=2, S=1, P=0, d=1
- H=8388608, K=3, S=2, P=1, d=1
- H=16777216, K=4, S=2, P=1, d=2
- H=33554432, K=3, S=1, P=1, d=1
- H=67108864, K=5, S=3, P=2, d=1