TIL that Apple's documentation for BLAS has bugs
Today I faced a problem of making portable C code using matrices multiplication. Target - use same C code on preprocessing before Neural net on iOS and on training in Python on Ubuntu. On iOS vDSP was used for matrices multiplication which is not available on Ubuntu. But iOS have BLAS port where matrix operations also available. BLAS exists nearly on every platform. Here I faced a problem with making cblas_dgemm
working properly. Assert inside fired saying that parameter 9 was incorrect on entry to cblas_dgemm
. But call was so simple and documentation so straightforward… An hour of googling have shown that Apple documentation was wrong. Apple documentation clearly says:
ldb
The size of the first dimension of matrixB
; if you are passing a matrixB[m][n]
, the value should bem
.
So it looks like ldb
should match with the first dimension of matrix B
. No.
Example Multiplying Matrices Using dgemm from documentation on Intel’s port of BLAS is much clear in this regard:
Leading dimension of array
B
, or the number of elements between successive rows (for row major storage) in memory. In the case of this exercise the leading dimension is the same as the number of columns.
Because I use C-arrays where rows go first ldb
parameter should be second dimension of matrix B
, not this first! And this worked for me. Shame on Apple!
Filed a bug for this on 13 of April 2023. Feedback id for this bugreport is FB12116665.
TODO: give answers on stackoverflow.