commit 55f59de: [Minor] Allow to work without cblas.h

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Jul 3 11:42:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-07-03 12:36:18 +0100
URL: https://github.com/rspamd/rspamd/commit/55f59de699aa0c7c7018e05375131d22cfd46530

[Minor] Allow to work without cblas.h

---
 config.h.in                 |  4 ----
 contrib/kann/CMakeLists.txt | 13 +++++++++++++
 contrib/kann/kann.c         |  2 ++
 contrib/kann/kautodiff.c    | 15 +++++++++++++++
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/config.h.in b/config.h.in
index 9dcf51a50..8b876cd60 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 d7bd73d28..ba38e14c8 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 43227bdc6..76ade6a52 100644
--- a/contrib/kann/kann.c
+++ b/contrib/kann/kann.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <math.h>
 #include <float.h>
 #include <string.h>
diff --git a/contrib/kann/kautodiff.c b/contrib/kann/kautodiff.c
index f303a723f..bc9458f42 100644
--- a/contrib/kann/kautodiff.c
+++ b/contrib/kann/kautodiff.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include <stdlib.h>
 #include <assert.h>
 #include <stdarg.h>
@@ -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);


More information about the Commits mailing list