Repository navigation
Freebuff/rdna2 native extension optimization a36e947c 679f 48b5 8290 8a6f1c09ab4f - #6233
Closed
Maxritz wants to merge 16 commits into
Conversation
…P kernels - Implement from-scratch HIP kernels for sgemm/dgemm/gemv/dot with f32/int8 support - Keep quantized weights byte-exact (no f32 dequant of stored quants), epilogue applies scales/zp - Add int8 kernels with dp4a row sums, tiled/lds/wmma variants - Integrate into OpenBLAS build system with RDNA targets and HIP support - All tests pass on gfx1201 (RX 9070 XT): 141/0 checks Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
Port the rdna2_oblas_sgemm_cm pattern to a shared column-major GEMM core (rdna2_gemm_cm_core) and bridge sgemm, ssymm, strmm, and strsm: - sgemm: direct core call (gated by OPENBLAS_RDNA2_GPU_DEBUG/size) - ssymm: expand symmetric triangle to dense, then GEMM - strmm: expand triangular A to dense (beta implicit 0), then GEMM - strsm: blocked triangular solve (NB=128) with host diagonal-block substitution and GPU GEMM rank-nb updates; side=right solved via the transposed system op(A)^T X^T = alpha B^T. Fixes the tri (triangle of op(A)) mapping for side/trans/uplo combinations. Hook dispatch into interface/symm.c and interface/trsm.c (f32 real hooks, matching sgemm in gemm.c). Remove the strmm stride guard so the bridge handles general lda/ldb/ldc; fix test_oblas_l3.c sgemm lda (k -> m). Add KERNEL.GFX1030/1031/1200/1201 and verification probes/harness (strsm MATCH ~2e-7 across all side/uplo/trans/diag). Note: CPU generic trmmkernel_4x4.c (used by GFX1030-1201 for STRMM/DTRMM) remains the pre-existing broken implementation for right-side (and affected) triangular multiply; a corrected rewrite is in progress but not yet verified end-to-end.
Materialize TransA/TransB operands into contiguous column-major temporaries and pass them through rdna2_gemm_cm_core, removing the CPU fallback for transposed layouts (handled=1, MATCH vs naive ref for TN/NT/TT incl. non-unit alpha/beta).
…ases) Rewrite the 4x4 TRMM micro-kernel mirroring trmmkernel_2x2.c's proven LEFT/TRANSA offset/temp/post-advance logic over the 4/2/1 tiling of gemmkernel_4x4.c (matching ncopy_4/tcopy_4, SGEMM/DGEMM unroll 4). TRMM overwrites C (alpha*dot), not accumulate. Verified: full cblas_strmm/dtrmm driver path 32/32 ok (M=137,N=113, odd remainders) vs naive ref; test_oblas_l3 (gfx1200/gfx1201) strmm 10/10 MATCH handled=1 (ALL CASES MATCH).
USE_HIP/GPU_ARCH mirror the CUDA knobs, so a normal TARGET still selects the CPU kernels while USE_HIP=1 adds the device side to the same library; a stamp file makes a GPU_ARCH change rebuild the device object, which make could not otherwise notice. The bridge test gains a `make level3-test` entry point and a CI workflow. It links against a CPU-only archive without ROCm (the HIP runtime is only added when the archive actually contains the device objects), and its failure output is capped per case because a clobbered triangle used to print one line per element and bury the log. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
The first run flagged that v4 still targets Node.js 20, which the runners now force onto Node.js 24. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
The test only reached SGEMM and SYRK/SYR2K, so three of the six bridged routines could break without anything noticing. Each new op runs over its full layout range and is compared against a double-precision reference that shares none of the bridge's triangle logic (TRSM's reference solves a dense copy with a pivoting LU). The checks also cover what the bridges must not do: the unstored triangle of a symmetric or triangular factor and the stored diagonal of a unit-diagonal one hold a value no correct result can produce, so reading them fails loudly rather than silently, and the ldb/ldc padding must be untouched. Breaking the ssymm triangle read, the unit-diagonal handling and the strsm triangle each made the test fail with only the affected op failing. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
Every level-3 case used alpha=1 or a small negative value and beta=0 or -0.25, so a bridge that mishandled a scalar edge went unnoticed. Each op now also runs alpha and beta at zero, negative and large values, and the test asserts what a zero means: alpha==0 leaves beta*C and nothing else, beta==0 drops the old C, and both zero means exact zeros. TRMM and TRSM have no beta and sweep alpha. Making the TRSM cases reliable took two changes. Its factor was loosely conditioned: ||A^-1|| reached 2e8 at 1300 rows, so the verdict depended on the order the substitution happened to sum its terms, and a mutant that could not change the alpha=1 result still flipped that case by 0.86 relative. The factor is now row-wise diagonally dominant, and the tolerance follows the row count, because a float solve over 1300 rows is only good to about a percent whatever the build. The gate case says so and is a dispatch check; the layout and scalar cases keep the tight tolerances. Verified against three mutants of the bridges, each failing only where it should: an alpha==0 early-out that forgets beta*C fails 96 cases, dropping alpha from the signed and scaled paths fails 400, and ignoring the trans/side triangle fails 64 of the 160 TRSM cases. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
A tolerance test cannot detect one: every comparison against NaN is false, so a bridge that answered 0.0 for a NaN input, or produced a NaN where a number was due, passed silently. Results are now compared against NaN and the infinities explicitly, and the level-3 case helpers take a planted value so an operand can carry one. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
…ive-extension-optimization-a36e947c-679f-48b5-8290-8a6f1c09ab4f
Freebuff/rdna2 level3 ci
The header still advertised SGEMM and SYRK/SYR2K only, so a reader could not tell that SYMM, TRMM and TRSM are covered too, nor that the cases sweep every layout with zero, negative and large alpha/beta. It also leaves the two known gaps on record: nothing feeds a NaN or infinity into an input yet, and the path filters miss interface/symm.c, interface/trsm.c and gemm.c. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
… goes The README still described the port as never having run on hardware. Add the Windows/ROCm build and DLL-resolution steps that made it run, the level-3 and int8 results, and per-shape GEMM timings: the device wins 4.5x over the CPU end to end, but the bridge's per-call column-major to row-major pass over A costs more than the kernel and leaves 1.2-1.6x at the library. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
The Makefile has had bench and bench-run targets pointing at gpu/rdna2/bench_rdna2.cpp while the source itself was never in the tree, so neither target could run. Add it, now that its two reporting defects are fixed: the throughput column prints TF/s rather than a second copy of the GFLOPS figure, and the program refuses to time the CPU fallback by asking the library for its own device view and checking every launcher return code. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Maxritz
marked this pull request as draft
November 6, 2026 11:47
Maxritz
deleted the
freebuff/rdna2-native-extension-optimization-a36e947c-679f-48b5-8290-8a6f1c09ab4f
branch
November 6, 2026 11:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.