Route Flat/RCQ sgemm_ through cblas_sgemm to reach OpenBLAS SME (opt-in) - #5617
adit4443ya wants to merge 1 commit into
Conversation
Summary:
Adds a compile-time-guarded path (`FAISS_SME_CBLAS_SGEMM`) that redirects
FAISS's Fortran `sgemm_("Transpose", "Not transpose", ...)` calls at the two
BLAS-dominated hot sites through OpenBLAS's `cblas_sgemm` entry point. Only
the CBLAS entry reaches OpenBLAS's SME direct-sgemm dispatch gate
(`interface/gemm.c`); the Fortran `sgemm_` entry never does. This lets FAISS's
matrix multiplies land on the Arm SME matrix engine (fmopa) on SME-capable
hardware, with zero OpenBLAS source edits.
The macro is opt-in and a strict no-op when undefined: the `#else` branch is
byte-identical to the previous Fortran `sgemm_` call, so builds without the
flag (and all non-SME hardware) are unaffected.
|
Hi @adit4443ya! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary:
Adds a compile-time-guarded path (
FAISS_SME_CBLAS_SGEMM) that redirectsFAISS's Fortran
sgemm_("Transpose", "Not transpose", ...)calls at the twoBLAS-dominated hot sites through OpenBLAS's
cblas_sgemmentry point. Onlythe CBLAS entry reaches OpenBLAS's SME direct-sgemm dispatch gate
(
interface/gemm.c); the Fortransgemm_entry never does. This lets FAISS'smatrix multiplies land on the Arm SME matrix engine (fmopa) on SME-capable
hardware, with zero OpenBLAS source edits.
The macro is opt-in and a strict no-op when undefined: the
#elsebranch isbyte-identical to the previous Fortran
sgemm_call, so builds without theflag (and all non-SME hardware) are unaffected.
Measured on Arm Oryon-class SME hardware, single-thread
BLAS, both NDK-clang-21 and clang-24, correctness-gated:
IndexFlat::search): 1.4x-2.8x, growing with GEMMsize (2.0-2.2x at d=128/nb=16384; 2.8x at d>=512).
Implementation:
faiss/utils/distances.cpp: declarescblas_sgemmin the existing extern-Cblock (blasint is int in the linked OpenBLAS; CBLAS enums are ints, so no
vendor header is needed, matching how
sgemm_is already hand-declared);adds an anonymous-namespace helper
sme_cblas_sgemm_tnthat performs theFortran-column-major -> row-major translation (transpose-pack A into a tight
[K][M] scratch; B is already the row-major left operand); and guards the
exhaustive_inner_product_blascall site (drives the Flat win).faiss/utils/simd_impl/distances_arm_sve.cpp: same declaration + helper, andguards the
exhaustive_L2sqr_blas_cmax<ARM_SVE>call site (drives the RCQtraining win). Adds the
<vector>include the helper needs.Only these two call sites are converted -- the two sites shown to drive the
confirmed wins. Other
sgemm_sites are left on the unchanged Fortran path.