From: Vsevolod Stakhov Date: Wed, 3 Jul 2019 11:36:18 +0000 (+0100) Subject: [Minor] Allow to work without cblas.h X-Git-Tag: 2.0~672 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55f59de699aa0c7c7018e05375131d22cfd46530;p=thirdparty%2Frspamd.git [Minor] Allow to work without cblas.h --- diff --git a/config.h.in b/config.h.in index 9dcf51a508..8b876cd601 100644 --- a/config.h.in +++ b/config.h.in @@ -157,10 +157,6 @@ #cmakedefine DISABLE_PTHREAD_MUTEX 1 -#ifdef HAVE_LIBEVENT2 -#define HAVE_EVUTIL_RNG_INIT 1 -#endif - /* Detect endianness */ #ifdef HAVE_ENDIAN_H diff --git a/contrib/kann/CMakeLists.txt b/contrib/kann/CMakeLists.txt index d7bd73d28e..ba38e14c8f 100644 --- a/contrib/kann/CMakeLists.txt +++ b/contrib/kann/CMakeLists.txt @@ -15,6 +15,19 @@ ProcessPackage(BLAS OPTIONAL LIBRARY openblas blas LIB_OUTPUT BLAS_REQUIRED_LIBRARIES) 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() + ADD_DEFINITIONS(-DHAVE_CBLAS_H) + ENDIF() + ELSE() + ADD_DEFINITIONS(-DHAVE_CBLAS_H) + ENDIF() + TARGET_LINK_LIBRARIES(rspamd-kann ${BLAS_REQUIRED_LIBRARIES}) ADD_DEFINITIONS(-DHAVE_CBLAS) ENDIF(WITH_BLAS) diff --git a/contrib/kann/kann.c b/contrib/kann/kann.c index 43227bdc66..76ade6a526 100644 --- a/contrib/kann/kann.c +++ b/contrib/kann/kann.c @@ -1,3 +1,5 @@ +#include "config.h" + #include #include #include diff --git a/contrib/kann/kautodiff.c b/contrib/kann/kautodiff.c index f303a723fa..bc9458f42a 100644 --- a/contrib/kann/kautodiff.c +++ b/contrib/kann/kautodiff.c @@ -1,3 +1,5 @@ +#include "config.h" + #include #include #include @@ -898,7 +900,20 @@ void kad_vec_mul_sum(int n, float *a, const float *b, const float *c) void kad_saxpy(int n, float a, const float *x, float *y) { kad_saxpy_inlined(n, a, x, y); } #ifdef HAVE_CBLAS +#ifdef HAVE_CBLAS_H #include "cblas.h" +#else +/* Poor man approach */ +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); +#endif void kad_sgemm_simple(int trans_A, int trans_B, int M, int N, int K, const float *A, const float *B, float *C) { cblas_sgemm(CblasRowMajor, trans_A? CblasTrans : CblasNoTrans, trans_B? CblasTrans : CblasNoTrans, M, N, K, 1.0f, A, trans_A? M : K, B, trans_B? K : N, 1.0f, C, N);