jax.experimental.pallas.mosaic_gpu.copy_gmem_to_smem#
- jax.experimental.pallas.mosaic_gpu.copy_gmem_to_smem(src, dst, barrier=None, *, collective_axes=None, leader_tracked=None, oob_mode=None, predicate=None)[source]#
Asynchronously copies a GMEM reference to a SMEM reference.
The underlying copy implementation is selected automatically based on the target architecture: TMA on Hopper and newer, and
cp.asyncon older architectures.When
collective_axesis specified, the copy involves multiple CUDA blocks in the cluster. The value ofleader_trackeddetermines the behavior:None(multicast): all CUDA blocks sharing the same index along the collective axes receive the same data fromsrc.CopyPartition.PARTITIONED(axis): each CUDA block in the cluster receives atransfer_size // cluster_sizetile ofsrc. E.g. forsrcof shape(256, 256)with cluster size 2 along axis 0: block 0 getssrc[0:128, :], block 1 getssrc[128:256, :].CopyPartition.REPLICATED: all CUDA blocks in the cluster load the same data, but only the first block tracks progress via barrier arrivals.
Note
For leader-tracked copies, only the first CUDA block in the cluster arrives on the barrier. If other blocks need to consume the copied data, an additional cluster barrier is necessary to ensure all blocks have finished the copy.
- Parameters:
src (_Ref) – The source Ref. Must be in GMEM.
dst (_Ref) – The destination Ref. Must be in SMEM.
barrier (_Ref | None) – The barrier to use for tracking completion of the copy. Must be omitted on pre-Hopper GPUs, which use the
cp.asyncimplementation. When omitted, completion of the copy has to be awaited withjax.experimental.pallas.mosaic_gpu.wait_gmem_to_smem()instead ofjax.experimental.pallas.mosaic_gpu.barrier_wait().collective_axes (str | tuple[str, ...] | None) – The collective axes to use for the copy. Only a single collective axis is supported when
leader_trackedis specified (but the axis can be composite). Only supported with the TMA implementation (Hopper and newer).leader_tracked (CopyPartition | None) – If specified, only the leader block in the cluster will observe the completion of the copy. If
CopyPartition.PARTITIONED(axis), performs a partitioned collective copy along the given axis. IfCopyPartition.REPLICATED, all blocks load the same data. Only supported with the TMA implementation (Hopper and newer).oob_mode (OOBFillMode | None) – The optional out-of-bounds fill mode. Can be
OOBFillMode.UNDEFINED,OOBFillMode.PROMISE_IN_BOUNDSorOOBFillMode.ZEROSfor the TMA implementation, and onlyOOBFillMode.PROMISE_IN_BOUNDSfor thecp.asyncone.predicate (jax.Array | None) – A boolean indicating whether the copy should be performed. If
None, the copy is always performed.
- Return type:
None
See also
jax.experimental.pallas.mosaic_gpu.barrier_arrive()jax.experimental.pallas.mosaic_gpu.barrier_wait()jax.experimental.pallas.mosaic_gpu.wait_gmem_to_smem()