2019-11-26 19:16:12 +01:00
|
|
|
option (ENABLE_BLAS "Enable openblas for fast neural network processing [default: OFF]" OFF)
|
2019-11-18 15:19:43 +01:00
|
|
|
|
|
|
|
IF(ENABLE_BLAS MATCHES "ON")
|
|
|
|
ProcessPackage(BLAS OPTIONAL_INCLUDE LIBRARY openblas blas
|
|
|
|
INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas
|
|
|
|
include/blas
|
|
|
|
ROOT ${BLAS_ROOT_DIR}
|
|
|
|
LIB_OUTPUT BLAS_REQUIRED_LIBRARIES)
|
2020-08-19 16:32:23 +02:00
|
|
|
ProcessPackage(BLAS_LAPACK OPTIONAL_INCLUDE LIBRARY lapack
|
|
|
|
INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas
|
|
|
|
include/blas
|
|
|
|
ROOT ${BLAS_ROOT_DIR}
|
|
|
|
LIB_OUTPUT BLAS_REQUIRED_LIBRARIES)
|
2019-11-18 15:19:43 +01:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(WITH_BLAS)
|
|
|
|
MESSAGE(STATUS "Use openblas to accelerate kann")
|
|
|
|
IF(NOT BLAS_INCLUDE)
|
|
|
|
FIND_FILE(HAVE_CBLAS_H HINTS "${RSPAMD_SEARCH_PATH}"
|
|
|
|
NAMES cblas.h
|
|
|
|
DOC "Path to cblas.h header")
|
|
|
|
IF(NOT HAVE_CBLAS_H)
|
|
|
|
MESSAGE(STATUS "Blas header cblas.h has not been found, use internal workaround")
|
|
|
|
ELSE()
|
2020-06-02 13:08:38 +02:00
|
|
|
ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
|
2019-11-18 15:19:43 +01:00
|
|
|
ENDIF()
|
|
|
|
ELSE()
|
2020-06-02 13:08:38 +02:00
|
|
|
ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
|
2019-11-18 15:19:43 +01:00
|
|
|
ENDIF()
|
2020-08-27 22:12:31 +02:00
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sgemm.c" "
|
|
|
|
#include <stddef.h>
|
|
|
|
enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
|
|
|
|
enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112 };
|
|
|
|
extern void cblas_sgemm(const enum CBLAS_ORDER Order,
|
|
|
|
const enum CBLAS_TRANSPOSE TA,
|
|
|
|
const enum CBLAS_TRANSPOSE TB,
|
|
|
|
const int M, const int N, const int K,
|
|
|
|
const float alpha, const float *A, const int lda,
|
|
|
|
const float *B, const int ldb, const float beta,
|
|
|
|
float *C, const int ldc);
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 0, 0, 0, 0, NULL, 0,
|
|
|
|
NULL, 0, 0, NULL, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
")
|
|
|
|
try_compile(HAVE_CBLAS_SGEMM
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/sgemm.c"
|
|
|
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
|
|
|
LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
|
|
|
|
OUTPUT_VARIABLE SGEMM_ERR)
|
|
|
|
|
|
|
|
# Cmake is just brain damaged
|
|
|
|
#CHECK_LIBRARY_EXISTS(${BLAS_REQUIRED_LIBRARIES} cblas_sgemm "" HAVE_CBLAS_SGEMM)
|
|
|
|
if(HAVE_CBLAS_SGEMM)
|
|
|
|
MESSAGE(STATUS "Blas has CBLAS sgemm")
|
|
|
|
ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_SGEMM)
|
|
|
|
else()
|
|
|
|
MESSAGE(STATUS "Blas has -NOT- CBLAS sgemm, use internal workaround: ${SGEMM_ERR}")
|
|
|
|
endif()
|
2020-06-02 13:08:38 +02:00
|
|
|
ADD_COMPILE_OPTIONS(-DHAVE_CBLAS)
|
2019-11-18 15:19:43 +01:00
|
|
|
ENDIF(WITH_BLAS)
|