Kernel: reduce_max (Level 1, category: reduce)
Input shapes: [[4096, 2048]]
Target hardware: NVIDIA A100 80GB PCIe
Status: pass (correct: yes, max diff vs baseline: 0)
Pallas runtime: 95.0869 ms; JAX XLA compiled runtime: 0.127 ms; speedup vs compiled baseline: 0.0013

JAX reference implementation:
@jax.jit
def jax_reduce_max(x: jax.Array) -> jax.Array:
    return jnp.max(x, axis=-1)

Original Pallas kernel (TPU-oriented): """Level 1: Row-wise max reduction via Pallas.

Provenance: jnp.max reduction, used in softmax numerics and argmax patterns
"""


from pallasbench.provenance import describe_task as _describe_task

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

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


def _reduce_max_kernel(x_ref, o_ref):
    o_ref[...] = jnp.max(x_ref[...], axis=-1)


def pallas_reduce_max(x: jax.Array) -> jax.Array:
    n_rows = x.shape[0]
    n_cols = x.shape[1]
    block_rows = min(256, n_rows)
    grid_size = n_rows // block_rows

    return pl.pallas_call(
        _reduce_max_kernel,
        out_shape=jax.ShapeDtypeStruct((n_rows,), x.dtype),
        grid=(grid_size,),
        in_specs=[pl.BlockSpec((block_rows, n_cols), lambda i: (i, 0))],
        out_specs=pl.BlockSpec((block_rows,), lambda i: (i,)),
    )(x)


pallas_kernel = pallas_reduce_max
task_name = "reduce_max"
input_shapes = [(4096, 2048)]
category = "reduce"
level = 1

Fixed Pallas kernel (GPU-compatible): """Level 1: Row-wise max reduction via Pallas.

Provenance: jnp.max reduction, used in softmax numerics and argmax patterns
"""


from pallasbench.provenance import describe_task as _describe_task

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

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


def _reduce_max_kernel(x_ref, o_ref):
    o_ref[...] = jnp.max(x_ref[...], axis=-1)


def pallas_reduce_max(x: jax.Array) -> jax.Array:
    n_rows = x.shape[0]
    n_cols = x.shape[1]
    block_rows = min(256, n_rows)
    while block_rows * n_cols > 16384 and block_rows > 1:
        block_rows //= 2
    grid_size = n_rows // block_rows

    return pl.pallas_call(
        _reduce_max_kernel,
        out_shape=jax.ShapeDtypeStruct((n_rows,), x.dtype),
        grid=(grid_size,),
        in_specs=[pl.BlockSpec((block_rows, n_cols), lambda i: (i, 0))],
        out_specs=pl.BlockSpec((block_rows,), lambda i: (i,)),
    )(x)


pallas_kernel = pallas_reduce_max
task_name = "reduce_max"
input_shapes = [(4096, 2048)]
category = "reduce"
level = 1

Diff of GPU fix: --- a/reduce_max.py
+++ b/reduce_max.py
@@ -21,6 +21,8 @@
     n_rows = x.shape[0]
     n_cols = x.shape[1]
     block_rows = min(256, n_rows)
+    while block_rows * n_cols > 16384 and block_rows > 1:
+        block_rows //= 2
     grid_size = n_rows // block_rows
 
     return pl.pallas_call(

Jaxpr IR: { lambda ; a:f32[4096,2048]. let
    b:f32[4096] = pallas_call[
      compiler_params=None
      cost_estimate=None
      debug=False
      grid_mapping=GridMapping(grid=(512,), block_mappings=(BlockMapping(block_shape=(Blocked(block_size=8), Blocked(block_size=2048))), BlockMapping(block_shape=(Blocked(block_size=8),))))
      input_output_aliases=()
      interpret=False
      jaxpr={ lambda ; c:Ref<default>{f32[8,2048]} d:Ref<default>{f32[8]}. let
          e:f32[8,2048] <- c[...]
          f:f32[8] = reduce_max[axes=(1,)] e
          g:f32[8], d[...] <- d[...], f
        in () }
      mesh=None
      metadata=None
      name=None
      out_avals=(ShapedArray(float32[4096]),)
    ] a
  in (b,) }