Skip to content

Preserve binary16 rounding in OpenGL software subgroup sums #2241

Open

Description

@NripeshN

Summary

OpenGL software subgroup sums lose intermediate binary16 rounding. Generated shaders compile and validate but return different answers from the original Metal source. The GLSL helper selects its arithmetic from the mapped float type and therefore reduces half inputs using binary32 scratch and arithmetic.

Reproduction and Results

Translate a 32-thread Metal compute entry with a typed half sum_value(half value) { return simd_sum(value); } helper, using software_subgroup_width = 32. Upload binary16 inputs as integer words, decode them in the shader, and write the result's half bits back as unsigned words.

  • [2048, 1, -2048, 1] repeated eight times: original Metal and round-trip Metal return 0x4800 (8); the generated OpenGL shader returns 0x4c00 (16).
  • Thirty-two maximum finite half values (65504): original Metal returns positive infinity (0x7c00); generated OpenGL produces 0x8fff after the unrounded value reaches a half-bit conversion helper.
  • The same run checks decimal fractions, positive and negative zero, subnormals, infinities and NaNs. Input observations and output guards are retained.

Reproduced at 60141b95a4dd15f62a60605fd432b8a292cafea7 plus the pending pointer-provenance change in PR #1974, before adding any half-subgroup correction. The failure was native execution on software OpenGL, not only a source inspection.

Required Behavior

Preserve logical half precision when choosing the software sum helper and round each arithmetic stage. Half and float sums must remain distinct even when their physical storage uses the same GLSL type. Preserve partial subgroup boundaries, scratch reuse, barriers, single evaluation and exceptional-value behavior. Add strict compiler validation and native regression controls against the original source, without weakening output checks.

This affects any half-precision source reduction. It was found while qualifying MLX column-reduction kernels at 9c3d35571ac450a8ecf5c17b4d0e3fac52c08bc8; the initial small exact-integer demo inputs did not expose it. DirectX's separate unsupported half-sum diagnostic is tracked in #2240.

Activity

  1. NripeshN commented on Oct 13, 2026

    @NripeshN
    MemberAuthor

    Implemented the scalar binary16 software-sum change in commit a592cd40 on PR #1974. Each adjacent-pair combine rounds to binary16; full and partial groups retain barriers and separate logical-half scratch/helper identity. Narrow products/scans are not enabled by this change, and unproven conditional half participation remains diagnostic (#2242).

    The native controls cover six workgroup shapes and twelve numerical patterns, including cancellation, signed zeros, subnormals, overflow, infinities and NaN classification, with repeated helper calls, single-evaluation counters and guards. Native Metal and software OpenGL selections pass 480 tests each; Metal compares the unchanged original source. The pinned half/float first-pass column cases also execute on both platforms. Strict DXC compiles both real column packages.

    The full local suite passes 44,988 tests with 47,709 skips, and all-file pre-commit passes. Required Windows numerical execution is still pending new-head CI; compiler success alone is not evidence to close that requirement. No release or complete MLX port is claimed.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions