commit f031b11: [Minor] Use cblas_saxpy where possible

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 1 11:42:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-09-01 12:41:09 +0100
URL: https://github.com/rspamd/rspamd/commit/f031b11ddb8b74b82983b634fc910926ffc58600 (HEAD -> master)

[Minor] Use cblas_saxpy where possible

---
 cmake/Openblas.cmake     | 22 ++++++++++++++++++++++
 contrib/kann/kautodiff.c | 13 +++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/cmake/Openblas.cmake b/cmake/Openblas.cmake
index 2155b2955..7615408b2 100644
--- a/cmake/Openblas.cmake
+++ b/cmake/Openblas.cmake
@@ -51,6 +51,22 @@ int main(int argc, char **argv)
             COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
             LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
             OUTPUT_VARIABLE SGEMM_ERR)
+    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/saxpy.c" "
+#include <stddef.h>
+extern void cblas_saxpy(const int __N,
+    const float __alpha, const float *__X, const int __incX, float *__Y, const int __incY);
+int main(int argc, char **argv)
+{
+    cblas_saxpy(0, 0, NULL, 0, NULL, 0);
+    return 0;
+}
+")
+    try_compile(HAVE_CBLAS_SAXPY
+            ${CMAKE_CURRENT_BINARY_DIR}
+            "${CMAKE_CURRENT_BINARY_DIR}/saxpy.c"
+            COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+            LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
+            OUTPUT_VARIABLE SAXPY_ERR)
 
     # Cmake is just brain damaged
     #CHECK_LIBRARY_EXISTS(${BLAS_REQUIRED_LIBRARIES} cblas_sgemm "" HAVE_CBLAS_SGEMM)
@@ -60,5 +76,11 @@ int main(int argc, char **argv)
     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
diff --git a/contrib/kann/kautodiff.c b/contrib/kann/kautodiff.c
index a8af6796b..f336c958b 100644
--- a/contrib/kann/kautodiff.c
+++ b/contrib/kann/kautodiff.c
@@ -897,8 +897,6 @@ void kad_vec_mul_sum(int n, float *a, const float *b, const float *c)
 	for (i = 0; i < n; ++i) a[i] += b[i] * c[i];
 }
 
-void kad_saxpy(int n, float a, const float *x, float *y) { kad_saxpy_inlined(n, a, x, y); }
-
 /* This is actually lapack not cblas, but this definition is used */
 #ifdef HAVE_CBLAS
 #ifndef __APPLE__
@@ -958,6 +956,17 @@ void kad_sgemm_simple(int trans_A, int trans_B, int M, int N, int K, const float
 }
 #endif
 
+#ifdef HAVE_CBLAS_SAXPY
+#ifndef HAVE_CBLAS_H
+extern void cblas_saxpy(const int __N,
+    const float __alpha, const float *__X, const int __incX, float *__Y, const int __incY);
+#endif
+
+void kad_saxpy(int n, float a, const float *x, float *y) { cblas_saxpy(n, a, x, 1, y, 1); }
+#else
+void kad_saxpy(int n, float a, const float *x, float *y) { kad_saxpy_inlined(n, a, x, y); }
+#endif
+
 bool kad_ssyev_simple(int N, float *A, float *eigenvals)
 {
 #ifndef HAVE_CBLAS


More information about the Commits mailing list