← All problems
#11 3D Convolution Medium

Implement a program that performs a 3D convolution operation. Given a 3D input volume and a 3D kernel (filter), compute the convolved output. The convolution should use a "valid" boundary condition (no padding).

For a 3D convolution, the output at position \((i,j,k)\) is given by:

\[ output(i,j,k) = \sum_{d=0}^{K_d-1} \sum_{r=0}^{K_r-1} \sum_{c=0}^{K_c-1} input(i+d,j+r,k+c) \cdot kernel(d,r,c) \]

The input consists of:

Output: Output dimensions:

Implementation Requirements

Examples

Example 1:

Input volume \(V \in \mathbb{R}^{3 \times 3 \times 3}\): \[ \begin{aligned} V_{d=0} &= \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \\ V_{d=1} &= \begin{bmatrix} 10 & 11 & 12 \\ 13 & 14 & 15 \\ 16 & 17 & 18 \end{bmatrix} \\ V_{d=2} &= \begin{bmatrix} 19 & 20 & 21 \\ 22 & 23 & 24 \\ 25 & 26 & 27 \end{bmatrix} \end{aligned} \] Kernel \(K \in \mathbb{R}^{2 \times 3 \times 3}\): \[ \begin{aligned} K_{d=0} &= \begin{bmatrix} 1 & 0 & 0 \\ 1 & 1 & 1 \\ 0 & 0 & 0 \end{bmatrix} \\ K_{d=1} &= \begin{bmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \end{aligned} \] Output \(O \in \mathbb{R}^{2 \times 1 \times 1}\): \[ [82, 163] \]

Example 2:

Input volume \(V \in \mathbb{R}^{2 \times 2 \times 2}\): \[ \begin{aligned} V_{d=0} &= \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \\ V_{d=1} &= \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} \end{aligned} \] Kernel \(K \in \mathbb{R}^{2 \times 2 \times 2}\): \[ \begin{aligned} K_{d=0} &= \begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix} \\ K_{d=1} &= \begin{bmatrix} 1 & 1 \\ 1 & 1 \end{bmatrix} \end{aligned} \] Output \(O \in \mathbb{R}^{1 \times 1 \times 1}\): \[ [36] \]

Constraints

Guided walkthrough coming soon. Below is the official starter signature in each language; the clickable line-by-line explanation hasn't been authored yet.
Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.