jax.experimental.pallas.mosaic_gpu.alloc_semaphore

jax.experimental.pallas.mosaic_gpu.alloc_semaphore#

jax.experimental.pallas.mosaic_gpu.alloc_semaphore(shape=())[source]#

Returns a zero-initialized GMEM semaphore Ref.

This function can only be used outside of a kernel; for semaphores scoped to a single kernel, use scratch_types instead. It is the only way to create semaphores that outlive a single kernel invocation. It performs no cross-device synchronization: the caller is responsible for the initial sync, e.g. by running a kernel that is data dependent on the returned refs with skip_device_barrier=False.

Example:

sem = plgpu.alloc_semaphore((num_devices,))
# The first kernel consuming ``sem`` must not skip the device barrier, so
# that all devices observe the zero-initialized semaphores before use.
out = plgpu.kernel(body, out_type=out_type, grid=grid, grid_names=names)(
    sem, x
)
Parameters:

shape (tuple[int, ...]) – The shape of the semaphore array.

Return type:

jax.Ref