jax.experimental.pallas.mosaic_gpu.inline_mgpu

Contents

jax.experimental.pallas.mosaic_gpu.inline_mgpu#

jax.experimental.pallas.mosaic_gpu.inline_mgpu(*, arg_types=(), return_type=None)[source]#

Returns a decorator that inlines Mosaic GPU code.

This allows using lower-level Mosaic GPU abstractions and operations, which are otherwise not directly exposed in Pallas.

Example:

layout = plgpu.Layout.WG_STRIDED(x_ref.shape, vec_size=4)

@plgpu.inline_mgpu(
    arg_types=(plgpu.RefType(write=False),),
    return_type=plgpu.ShapeDtypeStruct(
        (128, 128), dtype, layout=layout
    ),
)
def add_one(ctx, smem_ref):
  x = mgpu.FragmentedArray.load_tiled(smem_ref)
  y = mgpu.FragmentedArray.splat(
      mgpu.c(1, x.mlir_dtype), shape=x.shape, layout=x.layout
  )
  return x + y
Parameters:
  • arg_types – A sequence of pytrees where the leaves are RefTypes or Layouts for reference or array arguments respectively.

  • return_type – A pytree where the leaves are ShapeDtypeStructs representing the arrays returned by the decorated function.