Skip to content
fn

sgemm

void sgemm(bool transA, bool transB, int M, int N, int K, float alpha, const float * A, int lda, const float * B, int ldb, float beta, float * C, int ldc)

Single-precision general matrix multiply (GEMM).

Computes C←α(AB)+βCC \leftarrow \alpha (A B) + \beta C in row-major layout using Accelerate's cblas_sgemm. Each transpose flag is mapped to the corresponding CBLAS_TRANSPOSE enum (CblasNoTrans / CblasTrans) at zero copy cost — the BLAS kernel selects an alternate inner loop for transposed operands.

Math

Cij←α∑k=0K−1AikBkj+βCijC_{ij} \leftarrow \alpha \sum_{k=0}^{K-1} A_{ik} B_{kj} + \beta C_{ij}

References

BLAS Reference (Netlib), Accelerate.framework cblas_sgemm.

Parameters

transA, transBbool
Whether AA or BB should be transposed before the multiply.
M, N, Kint
Output is M×NM \times N; the contracted dimension is KK, so A∈RM×KA \in \mathbb{R}^{M \times K} and B∈RK×NB \in \mathbb{R}^{K \times N} (before optional transposition).
alpha, betafloat
Linear-combination coefficients. Use α=1,β=0\alpha = 1, \beta = 0 for a pure multiply; nonzero β\beta enables fused accumulate-into-C.
A, Bconst float*
Row-major operand buffers.
Cfloat*
Row-major output buffer; updated in place when β≠0\beta \neq 0.
lda, ldb, ldcint
Leading dimensions (row stride in elements) of AA, BB, CC.

Notes

Single-threaded on Apple Silicon for small/medium sizes; Accelerate dispatches to AMX (matrix coprocessor) for large GEMMs automatically.