jax.experimental.pallas.mosaic_gpu.im2col_ref

Contents

jax.experimental.pallas.mosaic_gpu.im2col_ref#

jax.experimental.pallas.mosaic_gpu.im2col_ref(ref, *, window_shape, padding=None)[source]#

Returns an im2col view of a GMEM reference for TMA copies.

For ref of shape (N, *spatial_in, C) with 1, 2 or 3 spatial dimensions, the view has shape (N * math.prod(spatial_out), *window_shape, C), where spatial_out[i] = spatial_in[i] + sum(padding[i]) - window_shape[i] + 1 is the number of window positions along spatial dimension i. Each row view[r] is one window of the zero-padded input, padded. With 2 spatial dimensions, for example:

n, h, w = np.unravel_index(r, (N, *spatial_out))
view[r, dh, dw, c] == padded[n, h + dh, w + dw, c]

The view can only be read by jax.experimental.pallas.mosaic_gpu.copy_gmem_to_smem(), and must be indexed as view.at[rows, *window_offsets, channels], where:

  • rows is a unit-stride slice selecting up to 1024 windows;

  • window_offsets are scalars, one per spatial dimension, selecting the pixel to load from each window;

  • channels is a unit-stride slice selecting up to 256 channels of that pixel.

The destination must be a 2D SMEM reference with one row per selected window and one column per selected channel. If it is tiled, its tiles must span all columns. Rows and channels past the end of the view read as zeros.

Parameters:
  • ref (_Ref) – A channels-last GMEM reference of shape (N, *spatial_in, C). Sliced or otherwise transformed references and sub-byte dtypes are not supported.

  • window_shape (Sequence[int]) – The window size along each spatial dimension.

  • padding (Sequence[tuple[int, int]] | None) – The (lo, hi) zero padding along each spatial dimension. Must be non-negative. Defaults to no padding.

Return type:

pallas_core.TransformedRef