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
refof shape(N, *spatial_in, C)with 1, 2 or 3 spatial dimensions, the view has shape(N * math.prod(spatial_out), *window_shape, C), wherespatial_out[i] = spatial_in[i] + sum(padding[i]) - window_shape[i] + 1is the number of window positions along spatial dimensioni. Each rowview[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 asview.at[rows, *window_offsets, channels], where:rowsis a unit-stride slice selecting up to 1024 windows;window_offsetsare scalars, one per spatial dimension, selecting the pixel to load from each window;channelsis 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