Skip to content

Generic map mechanism and the standard elementwise op set #5

Closed

Description

@feitreim

ThunderKittens factors elementwise ops into op structs in common/base_ops.cuh:

zero one pos_infty neg_infty exp exp2 log log2 abs relu neg sqrt rsqrt
copy copy2 sum sub mul div min fma_AxBtC fma_AxCtB

applied through generic unary_map / bin_map / row_map / col_map, then instantiated for register tiles, register vectors, shared tiles, and shared vectors. One op struct, four type families, free.

What we have. Hand-written, on RegVec / RegTile only: exp2, max, sub, add_assign, mul_assign, splat, zero, plus free exp2_approx / exp2_hw / log2_approx / fmax / fmin.

Missing: div sqrt rsqrt abs relu neg log log2 min one pos_infty neg_infty copy, both fma forms, and every broadcast-operand form (add_row add_col sub_row sub_col mul_row mul_col div_row div_col broadcast_row broadcast_col). No generic entry point at all, so each new op is hand-written against the fragment map.

Highest ops-per-line item in the backlog — the mechanism collapses ~30 missing functions into a trait plus small impls.

Shape

  • trait UnaryOp { fn apply(x: f32) -> f32; } and trait BinaryOp { fn apply(a: f32, b: f32) -> f32; }.
  • unary_map / bin_map / row_map / col_map over RegTile, driven by the layout from Generalize RegTile to a logical shape with a layout parameter #1 so the row/col forms know which logical coordinate a register holds.
  • The standard op set as unit structs, plus named wrappers so t.exp2() still reads as it does today.
  • Keep exp2_approx and exp2_hw as distinct ops. They have different rounding, and picking between them is a numerics decision, not an implementation detail.

Depends on #1. Shared-tile instantiation is #13's problem; register types only here.

Activity

  1. added
    enhancement
    area:compute
    on Jul 26, 2026
  2. feitreim commented on Jul 27, 2026

    @feitreim
    OwnerAuthor

    Acceptance: update examples/ as part of closing this.

    All three aspirational kernels (flash_forward, softmax, layernorm) call into this. None of them is unblocked by it alone, but each should lose several entries from its gap list.

    The examples crate (#18) exists so that "done" is checkable in the terms a kernel author cares about, rather than as a claim about a primitive nobody has tried to hold. Concretely, on closing this:

    • Delete any workaround or GAP fence in examples/src/ that this issue removes the need for, and replace it with the real API.
    • If a kernel becomes fully unblocked, move it from aspirational to compiles: flip its header, take it out of its feature gate, and confirm modal run modal_app.py::build builds it for sm_100a.
    • Update the status table and the blocked-on lists in examples/README.md.

    If the example still does not compile afterwards, that is a finding worth writing down — say what is still missing rather than leaving the README stale.

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:computeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions