--- /dev/null
+#ifndef RSPAMD_BLAS_CONFIG_H_IN
+#define RSPAMD_BLAS_CONFIG_H_IN
+
+#cmakedefine HAVE_CBLAS_SGEMM 1
+#cmakedefine HAVE_CBLAS_SAXPY 1
+#cmakedefine HAVE_OPENBLAS_SET_NUM_THREADS 1
+#cmakedefine HAVE_CBLAS_H 1
+#cmakedefine HAVE_CBLAS 1
+
+#endif
\ No newline at end of file
IF(NOT HAVE_CBLAS_H)
MESSAGE(STATUS "Blas header cblas.h has not been found, use internal workaround")
ELSE()
- ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
+ SET(HAVE_CBLAS_H 1)
ENDIF()
ELSE()
- ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
+ SET(HAVE_CBLAS_H 1)
ENDIF()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sgemm.c" "
#include <stddef.h>
LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
OUTPUT_VARIABLE SAXPY_ERR)
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/openblas_set_num_threads.c" "
+#include <stddef.h>
+extern void openblas_set_num_threads(int num_threads);
+int main(int argc, char **argv)
+{
+ openblas_set_num_threads(1);
+ return 0;
+}
+")
+ try_compile(HAVE_OPENBLAS_SET_NUM_THREADS
+ ${CMAKE_CURRENT_BINARY_DIR}
+ "${CMAKE_CURRENT_BINARY_DIR}/openblas_set_num_threads.c"
+ COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
+ OUTPUT_VARIABLE OPENBLAS_SET_NUM_THREADS_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()
if(HAVE_CBLAS_SAXPY)
MESSAGE(STATUS "Blas has CBLAS saxpy")
- ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_SAXPY)
else()
MESSAGE(STATUS "Blas has -NOT- CBLAS saxpy, use internal workaround: ${SAXPY_ERR}")
endif()
- ADD_COMPILE_OPTIONS(-DHAVE_CBLAS)
-ENDIF(WITH_BLAS)
\ No newline at end of file
+ SET(HAVE_CBLAS 1)
+ENDIF(WITH_BLAS)
+
+CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/blas-config.h.in" "${CMAKE_BINARY_DIR}/src/blas-config.h")
\ No newline at end of file
#endif
#include <math.h>
+#include "blas-config.h"
+
#define DEFAULT_SCORE 10.0
#define DEFAULT_RLIMIT_NOFILE 2048
}
}
-#ifdef HAVE_CBLAS
-#ifdef HAVE_CBLAS_H
-#include "cblas.h"
-#else
+#ifdef HAVE_OPENBLAS_SET_NUM_THREADS
extern void openblas_set_num_threads(int num_threads);
#endif
-#endif
gboolean
rspamd_config_libs (struct rspamd_external_libs_ctx *ctx,
ZSTD_freeCStream (ctx->out_zstream);
ctx->out_zstream = NULL;
}
-#ifdef HAVE_CBLAS
+#ifdef HAVE_OPENBLAS_SET_NUM_THREADS
openblas_set_num_threads (cfg->max_blas_threads);
#endif
}
#include "zlib.h"
#include "contrib/uthash/utlist.h"
+#include "blas-config.h"
/* Check log messages intensity once per minute */
#define CHECK_TIME 60
-#ifdef HAVE_CBLAS
-#ifdef HAVE_CBLAS_H
-#include "cblas.h"
-#else
-#ifdef __APPLE__
-/* OSX is pure evil: number of threads must be set via env: VECLIB_MAXIMUM_THREADS */
-void openblas_set_num_threads(int num_threads) {}
-#else
+#ifdef HAVE_OPENBLAS_SET_NUM_THREADS
extern void openblas_set_num_threads(int num_threads);
-#endif
-#endif
/*
* Openblas creates threads that are not supported by
* jemalloc allocator (aside of being bloody stupid). So this hack