Skip to content

Commit

Permalink
CMake: allow USE_SMM=auto (#889)
Browse files Browse the repository at this point in the history
- Requesting LIBXSMM uses PkgConfig, which tests and resolves it.
- Hence: run this test prior instead of concluding with BLAS.
- BLAS is needed always and "auto" is no significant burden.
  • Loading branch information
hfp authored Feb 13, 2025
1 parent 19f32e8 commit 84e557b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
44 changes: 24 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ set(TEST_OMP_THREADS
CACHE STRING "Number of OpenMP threads for testing")

set(USE_SMM
"blas"
"auto"
CACHE STRING
"Small Matrix Multiplication implementation to use (default: blas)")
set_property(CACHE USE_SMM PROPERTY STRINGS blas libxsmm)
"Small Matrix Multiplication implementation to use (default: auto)")
set_property(CACHE USE_SMM PROPERTY STRINGS auto blas libxsmm)

set(USE_ACCEL
""
Expand Down Expand Up @@ -138,36 +138,40 @@ if (USE_OPENMP)
find_package(OpenMP REQUIRED)
endif ()

if ((USE_ACCEL MATCHES "opencl") AND (NOT USE_SMM MATCHES "libxsmm"))
message(FATAL_ERROR "OpenCL requires USE_SMM=libxsmm")
endif ()

# =================================== SMM (Small Matrix-Matrix multiplication)
if (USE_SMM MATCHES "blas")
message(STATUS "Using BLAS for Small Matrix Multiplication")
elseif (USE_SMM MATCHES "libxsmm")
message(STATUS "Using libxsmm for Small Matrix Multiplication")
else ()
message(FATAL_ERROR "Unknown SMM library specified")
endif ()

# =================================== LIBXSMM (rely on pkg-config)
if (USE_SMM MATCHES "libxsmm")
find_package(PkgConfig REQUIRED)
if (USE_SMM MATCHES "libxsmm" OR USE_SMM MATCHES "auto")
if (USE_SMM MATCHES "libxsmm")
set(LIBXSMM_REQUIRED "REQUIRED")
endif ()
find_package(PkgConfig ${LIBXSMM_REQUIRED})
if (USE_OPENMP)
if (NOT USE_SMM MATCHES "libxsmm-shared")
pkg_check_modules(LIBXSMMEXT IMPORTED_TARGET GLOBAL libxsmmext-static)
endif ()
if (NOT LIBXSMMEXT_FOUND)
pkg_check_modules(LIBXSMMEXT REQUIRED IMPORTED_TARGET GLOBAL libxsmmext)
pkg_check_modules(LIBXSMMEXT ${LIBXSMM_REQUIRED} IMPORTED_TARGET GLOBAL
libxsmmext)
endif ()
endif ()
if (NOT USE_SMM MATCHES "libxsmm-shared")
pkg_check_modules(LIBXSMM IMPORTED_TARGET GLOBAL libxsmmf-static)
endif ()
if (NOT LIBXSMM_FOUND)
pkg_check_modules(LIBXSMM REQUIRED IMPORTED_TARGET GLOBAL libxsmmf)
pkg_check_modules(LIBXSMM ${LIBXSMM_REQUIRED} IMPORTED_TARGET GLOBAL
libxsmmf)
endif ()
endif ()

# =================================== SMM (Small Matrix-Matrix multiplication)
if (USE_SMM MATCHES "blas" OR (USE_SMM MATCHES "auto" AND NOT LIBXSMM_FOUND))
if (USE_ACCEL MATCHES "opencl")
message(FATAL_ERROR "OpenCL requires USE_SMM=libxsmm")
endif ()
message(STATUS "Using BLAS for Small Matrix Multiplication")
elseif (USE_SMM MATCHES "libxsmm" OR USE_SMM MATCHES "auto")
message(STATUS "Using libxsmm for Small Matrix Multiplication")
else ()
message(FATAL_ERROR "Unknown SMM library specified")
endif ()

# =================================== BLAS & LAPACK, PkgConfig
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ elseif (USE_ACCEL MATCHES "cuda")
"${ACC_ARCH_NUMBER}")
endif ()

if (USE_SMM MATCHES "libxsmm")
if (USE_SMM MATCHES "libxsmm" OR (USE_SMM MATCHES "auto" AND LIBXSMM_FOUND))
target_compile_definitions(dbcsr PRIVATE __LIBXSMM)
target_link_directories(dbcsr PUBLIC ${LIBXSMM_LIBRARY_DIRS})
if (USE_OPENMP)
Expand Down

0 comments on commit 84e557b

Please sign in to comment.