#cmakedefine HAVE_CBLAS_SGEMM 1 | #cmakedefine HAVE_CBLAS_SGEMM 1 | ||||
#cmakedefine HAVE_CBLAS_SAXPY 1 | #cmakedefine HAVE_CBLAS_SAXPY 1 | ||||
#cmakedefine HAVE_OPENBLAS_SET_NUM_THREADS 1 | #cmakedefine HAVE_OPENBLAS_SET_NUM_THREADS 1 | ||||
#cmakedefine HAVE_BLI_THREAD_SET_NUM_THREADS 1 | |||||
#cmakedefine HAVE_CBLAS_H 1 | #cmakedefine HAVE_CBLAS_H 1 | ||||
#cmakedefine HAVE_CBLAS 1 | #cmakedefine HAVE_CBLAS 1 | ||||
option (ENABLE_BLAS "Enable openblas for fast neural network processing [default: OFF]" OFF) | option (ENABLE_BLAS "Enable openblas for fast neural network processing [default: OFF]" OFF) | ||||
IF(ENABLE_BLAS MATCHES "ON") | IF(ENABLE_BLAS MATCHES "ON") | ||||
ProcessPackage(BLAS OPTIONAL_INCLUDE LIBRARY openblas blas | |||||
ProcessPackage(BLAS OPTIONAL_INCLUDE LIBRARY openblas blas blis | |||||
INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas | INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas | ||||
include/blas | include/blas | ||||
include/blis | |||||
ROOT ${BLAS_ROOT_DIR} | ROOT ${BLAS_ROOT_DIR} | ||||
LIB_OUTPUT BLAS_REQUIRED_LIBRARIES) | LIB_OUTPUT BLAS_REQUIRED_LIBRARIES) | ||||
ProcessPackage(BLAS_LAPACK OPTIONAL_INCLUDE LIBRARY lapack | ProcessPackage(BLAS_LAPACK OPTIONAL_INCLUDE LIBRARY lapack | ||||
INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas | INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas | ||||
include/blas | include/blas | ||||
include/blis | |||||
ROOT ${BLAS_ROOT_DIR} | ROOT ${BLAS_ROOT_DIR} | ||||
LIB_OUTPUT BLAS_REQUIRED_LIBRARIES) | LIB_OUTPUT BLAS_REQUIRED_LIBRARIES) | ||||
ENDIF() | ENDIF() | ||||
LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES} | LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES} | ||||
OUTPUT_VARIABLE OPENBLAS_SET_NUM_THREADS_ERR) | OUTPUT_VARIABLE OPENBLAS_SET_NUM_THREADS_ERR) | ||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/bli_thread_set_num_threads.c" " | |||||
#include <stddef.h> | |||||
extern void bli_thread_set_num_threads(int num_threads); | |||||
int main(int argc, char **argv) | |||||
{ | |||||
bli_thread_set_num_threads(1); | |||||
return 0; | |||||
} | |||||
") | |||||
try_compile(HAVE_BLI_THREAD_SET_NUM_THREADS | |||||
${CMAKE_CURRENT_BINARY_DIR} | |||||
"${CMAKE_CURRENT_BINARY_DIR}/bli_thread_set_num_threads.c" | |||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} | |||||
LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES} | |||||
OUTPUT_VARIABLE BLI_SET_NUM_THREADS_ERR) | |||||
# Cmake is just brain damaged | # Cmake is just brain damaged | ||||
#CHECK_LIBRARY_EXISTS(${BLAS_REQUIRED_LIBRARIES} cblas_sgemm "" HAVE_CBLAS_SGEMM) | #CHECK_LIBRARY_EXISTS(${BLAS_REQUIRED_LIBRARIES} cblas_sgemm "" HAVE_CBLAS_SGEMM) | ||||
if(HAVE_CBLAS_SGEMM) | if(HAVE_CBLAS_SGEMM) |
#ifdef HAVE_OPENBLAS_SET_NUM_THREADS | #ifdef HAVE_OPENBLAS_SET_NUM_THREADS | ||||
extern void openblas_set_num_threads(int num_threads); | extern void openblas_set_num_threads(int num_threads); | ||||
#endif | #endif | ||||
#ifdef HAVE_BLI_THREAD_SET_NUM_THREADS | |||||
extern void bli_thread_set_num_threads(int num_threads); | |||||
#endif | |||||
gboolean | gboolean | ||||
rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, | rspamd_config_libs (struct rspamd_external_libs_ctx *ctx, | ||||
#ifdef HAVE_OPENBLAS_SET_NUM_THREADS | #ifdef HAVE_OPENBLAS_SET_NUM_THREADS | ||||
openblas_set_num_threads (cfg->max_blas_threads); | openblas_set_num_threads (cfg->max_blas_threads); | ||||
#endif | #endif | ||||
#ifdef HAVE_BLI_THREAD_SET_NUM_THREADS | |||||
bli_thread_set_num_threads (cfg->max_blas_threads); | |||||
#endif | |||||
} | } | ||||
return ret; | return ret; |
} | } | ||||
} | } | ||||
#ifdef HAVE_OPENBLAS_SET_NUM_THREADS | |||||
extern void openblas_set_num_threads(int num_threads); | |||||
/* | /* | ||||
* Openblas creates threads that are not supported by | * Openblas creates threads that are not supported by | ||||
* jemalloc allocator (aside of being bloody stupid). So this hack | * jemalloc allocator (aside of being bloody stupid). So this hack | ||||
* is intended to set number of threads to one by default. | * is intended to set number of threads to one by default. | ||||
* FIXME: is it legit to do so in ctor? | * FIXME: is it legit to do so in ctor? | ||||
*/ | */ | ||||
RSPAMD_CONSTRUCTOR (openblas_stupidity_fix_ctor) | |||||
#ifdef HAVE_OPENBLAS_SET_NUM_THREADS | |||||
extern void openblas_set_num_threads(int num_threads); | |||||
RSPAMD_CONSTRUCTOR (openblas_thread_fix_ctor) | |||||
{ | |||||
bli_thread_set_num_threads (1; | |||||
} | |||||
#endif | |||||
#ifdef HAVE_BLI_THREAD_SET_NUM_THREADS | |||||
extern void bli_thread_set_num_threads(int num_threads); | |||||
RSPAMD_CONSTRUCTOR (blis_thread_fix_ctor) | |||||
{ | { | ||||
openblas_set_num_threads (1); | |||||
bli_thread_set_num_threads (1; | |||||
} | } | ||||
#endif | #endif | ||||