Skip to content

HIP: rocBLAS BF16 projections with FP32 sums - #1930

Merged
ashhart merged 2 commits into
ashhart:mainfrom
laudney:pr-ocr-hip-blas
Nov 2, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
laudney:pr-ocr-hip-blas

Conversation

@laudney

@laudney laudney commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1927.

The OCR checkpoints in #1927 ship BF16 weights, and their image towers and decoders need many dense BF16 projections. The HF references compute these with FP32 accumulation and one BF16 rounding of each output, and some add a bias inside that one rounding. This PR adds that one operation on HIP through rocBLAS, as an optional runtime library like the existing ones, so later family PRs share one tested path. They do not each bring their own GEMM.

Before (main) After (this PR)
HIP dense BF16 projection, FP32 sums, one BF16 rounding none shared hip.Blas.project (rocBLAS)
Bias added inside that one rounding none hip.Blas.projectAdd
rocBLAS as an optional runtime library not listed listed, with its own failure and install hint, and in packaging/RUNTIME.md
Device checks on Radeon AI PRO R9700 (gfx1201) none 3/3 (bias order, FP32 accumulation, exact sums at served widths)
Existing models none call it unchanged

Changes

  • zig/src/hip/blas.zig: Blas.open(stream) loads rocBLAS, resolves its symbols and binds a handle to the caller's device context and nonblocking stream.
    • project computes BF16 x[M,K] times BF16 w[N,K] transposed into BF16 out[M,N], with an FP32 scalar and accumulator.
    • projectAdd adds the existing BF16 out to the FP32 dot before its one BF16 rounding. A bias row uses this epilogue.
    • Shape.of refuses zero sizes and sizes past rocBLAS's int arguments, and byte extents are checked for overflow, before any call.
  • platform/optional_libraries.zig: a rocblas entry (librocblas.so.5, then librocblas.so, then /opt/rocm/lib/librocblas.so) with its own RocblasUnavailable failure and install hint. packaging/RUNTIME.md lists it.
  • Build: test-hip-blas-host (shape and admission checks, no device) and build-hip-blas-test (device checks, zig/tests/hip/blas_test.zig). The device checks need exactly one visible device.

Gates

  • zig build test-hip-blas-host -Dhip=true: 2/2.
  • tf-hip-blas-test on a Radeon AI PRO R9700 (gfx1201), 3/3:
    • Bias: the bias is added before the output rounding. A case gives different BF16 bits if the bias is added after the rounding.
    • Accumulation: cancellation dots tell FP32 accumulation apart from FP16 and BF16 accumulation.
    • Served widths: the inputs and guard bytes stay unchanged, and every output equals an exact FP32 sum over a set of served widths.
  • zig build test -Dhip=true with this PR and the prompt-cache PR: 492/492 steps, 6,187/6,234 tests (47 skipped).
  • Lean checker: zero new problems over the 425 baseline.
  • No existing model calls this module yet. Their arithmetic does not change.

laudney and others added 2 commits November 2, 2026 15:51
OCR families on HIP need dense BF16 projections that accumulate in
FP32 and round to BF16 only once. A new hip.blas module loads rocBLAS
as an optional runtime library, binds a handle to the caller's
stream, and offers project and projectAdd; projectAdd adds the
existing output, such as a bias row, before that single rounding.
Both refuse impossible geometry and aliased outputs before any
library call. The build adds test-hip-blas-host for those refusals
and build-hip-blas-test for device checks against exact integer dots,
and RUNTIME.md lists the new optional rocBLAS dependency.
@ashhart
ashhart merged commit 4de3944 into ashhart:main Nov 2, 2026
10 of 11 checks passed
@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants