Skip to main content

Mojo function

im2col

im2col[dtype: DType](output: NDBuffer[dtype, 2, output.origin, output.shape, output.strides, alignment2=output.alignment2, address_space=output.address_space, exclusive=output.exclusive], activation: NDBuffer[dtype, 4, activation.origin, activation.shape, activation.strides, alignment2=activation.alignment2, address_space=activation.address_space, exclusive=activation.exclusive], problem: Conv2dProblemShape)

Explicit im2col transformation for convolution.

Transforms a 4D activation tensor [N, H, W, C] into a 2D matrix [M, K] for GEMM-based convolution.

M = batch * out_h * out_w K = in_channels * filter_h * filter_w

Note: This is a CPU reference implementation. For production use, the implicit im2col in the kernel is preferred.

Args:

  • โ€‹output (NDBuffer): Output 2D buffer [M, K].
  • โ€‹activation (NDBuffer): Input 4D buffer [N, H, W, C].
  • โ€‹problem (Conv2dProblemShape): Convolution problem shape.

Was this page helpful?