Skip to content

gemm's exact check cannot catch a wrong K index: b_value ignores its depth argument #48

Closed

Description

@feitreim

Found while building #40's benchmark harness.

examples/src/gemm.rs's reference generator b_value takes a depth
argument and then computes depth * 5 % 5, which is identically zero. So
B is constant along K.

That makes the check weaker than it looks: pass gemm 512x256x256 exact is
currently consistent with a kernel that indexes B wrongly along K — reading
the same plane every step, reversing the walk, or skipping chunks — because
every K-plane of B holds the same values. The A operand does vary along its
own axis, so the check is not vacuous; but the K walk of B, which is precisely
what mma_walk_cg2's chunk arithmetic computes, is unconstrained.

Not fixed in #40 because changing the generator changes what
modal_app.py::examples asserts, and that check is currently one of only two
numerical results this project has. It should be tightened deliberately, with
the run re-verified, rather than as a side effect of a benchmark PR.

What to do

Make b_value actually depend on depth, keeping the property that made the
check exact: every operand an integer small enough to be exact in bf16, every
product and sum exact in fp32 (below 2^24). The existing A generator and
device-tests' probe_a/probe_b are the models — the latter deliberately
constructs D[m,n] = 1*n + m*128 so that a drained value inverts to exactly one
coordinate.

Then re-run modal run modal_app.py::examples and confirm it still passes
exact. If it does not, that is a genuine bug this check was hiding, and the more
valuable outcome.

Worth checking the softmax reference for the same class of weakness while here —
its input is a stride-11 permutation per row, which is strong, but the plane
axis deserves the same scrutiny.

Activity

  1. added
    area:scaffolding
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:scaffolding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions