Kernel: matmul (Level 1, category: matmul)
Input shapes: [[1024, 1024], [1024, 1024]]
Target hardware: NVIDIA A100 80GB PCIe
Status: pass (correct: yes, max diff vs baseline: 0)
Pallas runtime: 699.1011 ms; JAX XLA compiled runtime: 0.1664 ms; speedup vs compiled baseline: 0.0002

JAX reference implementation:
@jax.jit
def jax_matmul(x: jax.Array, y: jax.Array) -> jax.Array:
    return x @ y

Original Pallas kernel (TPU-oriented): """Level 1: Tiled matrix multiplication via Pallas.

Demonstrates: 2D grid, BlockSpec with K-dimension accumulation,
multi-block tiling pattern from the Pallas quickstart.
"""

from pallasbench.provenance import describe_task as _describe_task

__doc__ = _describe_task("L1/matmul", __doc__)

import jax
import jax.numpy as jnp
from jax.experimental import pallas as pl


def _matmul_kernel(x_ref, y_ref, o_ref):
    o_ref[...] = x_ref[...] @ y_ref[...]


def pallas_matmul(x: jax.Array, y: jax.Array) -> jax.Array:
    m, k = x.shape
    _, n = y.shape
    bm = min(512, m)
    bn = min(512, n)
    grid = (m // bm, n // bn)

    return pl.pallas_call(
        _matmul_kernel,
        out_shape=jax.ShapeDtypeStruct((m, n), x.dtype),
        grid=grid,
        in_specs=[
            pl.BlockSpec((bm, k), lambda i, j: (i, 0)),
            pl.BlockSpec((k, bn), lambda i, j: (0, j)),
        ],
        out_specs=pl.BlockSpec((bm, bn), lambda i, j: (i, j)),
    )(x, y)


pallas_kernel = pallas_matmul
task_name = "matmul"
input_shapes = [(1024, 1024), (1024, 1024)]
category = "matmul"
level = 1

Fixed Pallas kernel (GPU-compatible): """Level 1: Tiled matrix multiplication via Pallas.

Demonstrates: 2D grid, BlockSpec with K-dimension accumulation,
multi-block tiling pattern from the Pallas quickstart.
"""

from pallasbench.provenance import describe_task as _describe_task

__doc__ = _describe_task("L1/matmul", __doc__)

import jax
import jax.numpy as jnp
from jax.experimental import pallas as pl


def _matmul_kernel(x_ref, y_ref, o_ref):
    o_ref[...] = x_ref[...] @ y_ref[...]


def pallas_matmul(x: jax.Array, y: jax.Array) -> jax.Array:
    m, k = x.shape
    _, n = y.shape
    bm = min(16, m)
    bn = min(16, n)
    grid = (m // bm, n // bn)

    return pl.pallas_call(
        _matmul_kernel,
        out_shape=jax.ShapeDtypeStruct((m, n), x.dtype),
        grid=grid,
        in_specs=[
            pl.BlockSpec((bm, k), lambda i, j: (i, 0)),
            pl.BlockSpec((k, bn), lambda i, j: (0, j)),
        ],
        out_specs=pl.BlockSpec((bm, bn), lambda i, j: (i, j)),
    )(x, y)


pallas_kernel = pallas_matmul
task_name = "matmul"
input_shapes = [(1024, 1024), (1024, 1024)]
category = "matmul"
level = 1

Diff of GPU fix: --- a/matmul.py
+++ b/matmul.py
@@ -20,8 +20,8 @@
 def pallas_matmul(x: jax.Array, y: jax.Array) -> jax.Array:
     m, k = x.shape
     _, n = y.shape
-    bm = min(512, m)
-    bn = min(512, n)
+    bm = min(16, m)
+    bn = min(16, n)
     grid = (m // bm, n // bn)
 
     return pl.pallas_call(

Jaxpr IR: { lambda ; a:f32[1024,1024] b:f32[1024,1024]. let
    c:f32[1024,1024] = pallas_call[
      compiler_params=None
      cost_estimate=None
      debug=False
      grid_mapping=GridMapping(grid=(64, 64), block_mappings=(BlockMapping(block_shape=(Blocked(block_size=16), Blocked(block_size=1024))), BlockMapping(block_shape=(Blocked(block_size=1024), Blocked(block_size=16))), BlockMapping(block_shape=(Blocked(block_size=16), Blocked(block_size=16)))))
      input_output_aliases=()
      interpret=False
      jaxpr={ lambda ; d:Ref<default>{f32[16,1024]} e:Ref<default>{f32[1024,16]}
          f:Ref<default>{f32[16,16]}. let
          g:f32[16,1024] <- d[...]
          h:f32[1024,16] <- e[...]
          i:f32[16,16] = dot_general[
            dimension_numbers=(([1], [0]), ([], []))
            preferred_element_type=float32
          ] g h
          j:f32[16,16], f[...] <- f[...], i
        in () }
      mesh=None
      metadata=None
      name=None
      out_avals=(ShapedArray(float32[1024,1024]),)
    ] a b
  in (c,) }