Repository navigation
Conversation
Fix three bugs in bfloat16 BLAS routines: 1. In interface/sbgemmt.c, CblasRowMajor maps A*B^T by transposing C, which swaps upper and lower triangles. Flip uplo for CblasRowMajor (CblasUpper -> 1, CblasLower -> 0) to match interface/gemmt.c. 2. In interface/sbgemmt.c, sbgemv_n and sbgemv_t return immediately when k == 0 and read A and B when alpha == ZERO. Handle k == 0 and alpha == ZERO prior to the gemv loop by scaling or zeroing the target triangle of C via SCAL_K when beta != ONE. 3. In interface/scal.c, multithreaded bscal and cblas_bscal set mode to BLAS_SINGLE | BLAS_REAL, causing blas_level1_thread to advance by 4-byte strides across 2-byte bfloat16 arrays and legacy_exec to read 4 bytes from a 2-byte alpha scalar. Set mode to BLAS_BFLOAT16 | BLAS_REAL under BGEMM. Add regression tests for all three cases in test_bgemm.c and register test_bgemm.c in utest/CMakeLists.txt to match utest/Makefile.
This branch has not been deployed
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.
Summary
This change resolves three defects in
bfloat16routines. First,cblas_sbgemmtwithCblasRowMajorassignsuplo = 0forCblasUpperanduplo = 1forCblasLowerininterface/sbgemmt.c, which writes the transposed triangle ofCbecause row-major layout swapsAandB(C^T = B^T * A^T). Second,sbgemmtdelegatesbetascaling tosbgemv_nandsbgemv_t, which return immediately whenk == 0without scalingCand still readAandBwhenalpha == 0. Third,interface/scal.csetsmode = BLAS_SINGLE | BLAS_REALin the#ifdef SMPpath when compiled withBGEMM(bscalandcblas_bscal), soblas_level1_threadpartitions thebfloat16vector with 4-byte strides (overflowing the array by 2x whenn > 1048576on multiple threads) andlegacy_execreads 4 bytes from the 2-bytebfloat16alphascalar.Changes
uplounderorder == CblasRowMajor(CblasUpper -> 1,CblasLower -> 0) ininterface/sbgemmt.c, matchinginterface/gemmt.c.k == 0 || alpha == ZEROprior to thesbgemvloop ininterface/sbgemmt.cby scaling or zeroing each column slice of the active triangle ofCwithSCAL_Kwhenbeta != ONE.mode = BLAS_BFLOAT16 | BLAS_REALunder#ifdef BGEMMininterface/scal.c.utestregression tests (sbgemmt_rowmajor_uplo,sbgemmt_k0_and_alpha0_beta_scaling, andbscal_multithreaded) inutest/test_extensions/test_bgemm.cand registertest_bgemm.cinutest/CMakeLists.txtto matchutest/Makefile.Verification
-DBUILD_BFLOAT16=ONon Windowsx86_64(HASWELL, MinGW-w64 GCC 14.3.0, 22 threads) and verified that all three newbgemmregression tests fail prior to the fix and pass (26/26) with the fix applied, alongside the fullopenblas_utestandopenblas_utest_extsuites.