From 5c6b539e40287f5f722e228d4236a8e2b62aa377 Mon Sep 17 00:00:00 2001 From: Andrew Snyder Date: Tue, 6 Oct 2026 08:17:54 -0400 Subject: [PATCH] Fix WASM CMake GEMM packing widths --- cmake/prebuild.cmake | 4 +++ utest/CMakeLists.txt | 1 + utest/Makefile | 2 +- utest/test_matrix_packing.c | 71 +++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 utest/test_matrix_packing.c diff --git a/cmake/prebuild.cmake b/cmake/prebuild.cmake index cb02556e3d..35b4ad30e2 100644 --- a/cmake/prebuild.cmake +++ b/cmake/prebuild.cmake @@ -1522,6 +1522,10 @@ endif () "#define DTB_DEFAULT_ENTRIES 128\n" "#define DTB_SIZE 4096\n" "#define L2_ASSOCIATIVE 4\n") + set(SGEMM_UNROLL_M 8) + set(SGEMM_UNROLL_N 4) + set(DGEMM_UNROLL_M 4) + set(DGEMM_UNROLL_N 4) elseif ("${TCORE}" STREQUAL "LA64_GENERIC") file(APPEND ${TARGET_CONF_TEMP} "#define DTB_DEFAULT_ENTRIES 64\n") diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index db7ad167f9..8f63265629 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -21,6 +21,7 @@ else () test_gemv.c test_trmv.c test_gemm.c + test_matrix_packing.c ) endif () diff --git a/utest/Makefile b/utest/Makefile index c6c04a6d4c..563d559f14 100644 --- a/utest/Makefile +++ b/utest/Makefile @@ -14,7 +14,7 @@ UTESTEXTBIN=openblas_utest_ext$(EXE) include $(TOPDIR)/Makefile.system OBJS=utest_main.o test_min.o test_amax.o test_ismin.o test_rotmg.o test_axpy.o test_dotu.o test_dsdot.o test_swap.o test_rot.o test_dnrm2.o test_zscal.o \ - test_amin.o test_axpby.o test_gemv.o test_trmv.o test_gemm.o + test_amin.o test_axpby.o test_gemv.o test_trmv.o test_gemm.o test_matrix_packing.o #test_rot.o test_swap.o test_axpy.o test_dotu.o test_dsdot.o test_fork.o OBJS_EXT=utest_main.o $(DIR_EXT)/xerbla.o $(DIR_EXT)/common.o OBJS_EXT+=$(DIR_EXT)/test_isamin.o $(DIR_EXT)/test_idamin.o $(DIR_EXT)/test_icamin.o $(DIR_EXT)/test_izamin.o diff --git a/utest/test_matrix_packing.c b/utest/test_matrix_packing.c new file mode 100644 index 0000000000..5f897b29e1 --- /dev/null +++ b/utest/test_matrix_packing.c @@ -0,0 +1,71 @@ +#include "openblas_utest.h" +#include + +#ifndef NO_CBLAS + +#define SYMM_PACKING(CBLAS, TYPE) \ + do { \ + TYPE a[64], b[32], c[32] = {0}; \ + int i; \ + for (i = 0; i < 64; ++i) { \ + a[i] = i / 8 == i % 8 ? 2 : 1; \ + } \ + for (i = 0; i < 32; ++i) { \ + b[i] = i + 1; \ + } \ + CBLAS(CblasRowMajor, CblasLeft, CblasLower, 8, 4, 1, a, 8, b, 4, \ + 0, c, 4); \ + for (i = 0; i < 32; ++i) { \ + ASSERT_TRUE(c[i] == i + 1 + 120 + 8 * (i % 4)); \ + } \ + } while (0) + +#define TRMM_PACKING(CBLAS, TYPE) \ + do { \ + TYPE a[64], b[32], expected[32] = {0}; \ + int i, j, k; \ + for (i = 0; i < 64; ++i) { \ + a[i] = i / 8 < i % 8 ? 0 : i / 8 == i % 8 ? 2 : 1; \ + } \ + for (i = 0; i < 32; ++i) { \ + b[i] = i + 1; \ + } \ + for (i = 0; i < 8; ++i) { \ + for (j = 0; j < 4; ++j) { \ + for (k = 0; k <= i; ++k) { \ + expected[i * 4 + j] += a[i * 8 + k] * b[k * 4 + j]; \ + } \ + } \ + } \ + CBLAS(CblasRowMajor, CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, \ + 8, 4, 1, a, 8, b, 4); \ + for (i = 0; i < 32; ++i) { \ + ASSERT_TRUE(b[i] == expected[i]); \ + } \ + } while (0) + +#ifdef BUILD_DOUBLE +CTEST(matrix_packing, dsymm) +{ + SYMM_PACKING(cblas_dsymm, double); +} + +CTEST(matrix_packing, dtrmm) +{ + TRMM_PACKING(cblas_dtrmm, double); +} +#endif + +#ifdef BUILD_SINGLE +CTEST(matrix_packing, ssymm) +{ + SYMM_PACKING(cblas_ssymm, float); +} + +CTEST(matrix_packing, strmm) +{ + TRMM_PACKING(cblas_strmm, float); +} +#endif + +#endif