Tensara Logo

tensara

All Problems

3D Average Pooling

HARD

Perform 3D average pooling on an input tensor:

output[i,j,k]=1k3m=0k1n=0k1o=0k1input[Si+mP,Sj+nP,Sk+oP]\text{output}[i,j,k] = \frac{1}{k^3}\sum_{m=0}^{k-1}\sum_{n=0}^{k-1}\sum_{o=0}^{k-1} \text{input}[S \cdot i + m - P, S \cdot j + n - P, S \cdot k + o - P]

The average pooling operation slides a window of size k×k×kk \times k \times k over the input tensor with stride SS and padding PP, computing the average value within each window position.

Input:

  • Matrix input of size H×W×D\text{H} \times \text{W} \times \text{D} (input tensor)
  • kernel_size (kk): Size of the pooling window
  • stride (SS): Step size between window positions
  • padding (PP): Number of zero-padding elements added on all sides

Output:

  • Matrix output of size Hout×Wout×Dout\text{H}_{\text{out}} \times \text{W}_{\text{out}} \times \text{D}_{\text{out}} where: Hout=H+2PkS+1\text{H}_{\text{out}} = \left\lfloor\frac{\text{H} + 2P - k}{S} + 1\right\rfloor Wout=W+2PkS+1\text{W}_{\text{out}} = \left\lfloor\frac{\text{W} + 2P - k}{S} + 1\right\rfloor Dout=D+2PkS+1\text{D}_{\text{out}} = \left\lfloor\frac{\text{D} + 2P - k}{S} + 1\right\rfloor

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 zero values in the average computation
  • The denominator (k3k^3) should always be the full kernel size, even when some elements are outside the input boundaries
  • This problem is adapted from KernelBench
Console

Sample Run Results

Hit "Run" to test your code with sample inputs

Loading...

Loading editor...

CUDA C++ environment

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.