/* * Thin matmul wrapper over libflame's LAPACK-compat dgemm_ (backed by BLIS), * built to WASM by build-blis-wasm.sh against the prebuilt libraries in * ../../libflame2wasm. Two builds: single-threaded (st) and pthreads (mt). * * The rest of matmul-bench works in row-major; dgemm_ is column-major * (Fortran). Row-major C = A*B is obtained from a column-major GEMM by * swapping the operands: passing (B, A) computes C^T = B^T * A^T in * column-major, which is exactly row-major C = A*B in the same flat buffer. * So c[0] matches the other (row-major) methods bit-for-bit-ish. */ #include extern int dgemm_( char* transa, char* transb, int* m, int* n, int* k, double* alpha, double* a, int* lda, double* b, int* ldb, double* beta, double* c, int* ldc ); #ifdef BLIS_MT /* dim_t is int32 in this BLIS build (--int-size=32). */ extern void bli_thread_set_num_threads( int n_threads ); #endif EMSCRIPTEN_KEEPALIVE void matmul_blis( double* a, double* b, double* c, int n, int nthreads ) { #ifdef BLIS_MT if ( nthreads > 0 ) bli_thread_set_num_threads( nthreads ); #else (void) nthreads; #endif char tr = 'N'; double alpha = 1.0, beta = 0.0; /* Operand swap: (B, A) column-major => row-major C = A*B. */ dgemm_( &tr, &tr, &n, &n, &n, &alpha, b, &n, a, &n, &beta, c, &n ); }