From ae45f5147cd3258d05c0ec47e02424131f4eb4c4 Mon Sep 17 00:00:00 2001 From: "Yusheng.Ma" Date: Tue, 13 Sep 2022 03:47:11 +0000 Subject: [PATCH] remove openblas header, fix openblas always compile bug Signed-off-by: Yusheng.Ma --- cmake/ThirdPartyPackagesKw.cmake | 16 ++++------- thirdparty/DiskANN/src/aux_utils.cpp | 1 - thirdparty/DiskANN/src/math_utils.cpp | 38 ++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cmake/ThirdPartyPackagesKw.cmake b/cmake/ThirdPartyPackagesKw.cmake index 6df3b2788..abb2e2584 100644 --- a/cmake/ThirdPartyPackagesKw.cmake +++ b/cmake/ThirdPartyPackagesKw.cmake @@ -227,18 +227,10 @@ endmacro() if (KNOWHERE_WITH_OPENBLAS) if (OpenBLAS_SOURCE STREQUAL "AUTO") # Protect OpenBLAS for faiss build - if (LINUX) + if(LINUX) set (BLA_VENDOR OpenBLAS) endif() - - if ( CMAKE_BUILD_TYPE STREQUAL "Debug" OR APPLE OR MSYS) - message(STATUS "Using debug mode or host is MacOS/MSYS, try to find openblas") - find_package(BLAS) - message(STATUS "Knowhere openblas libraries: ${BLAS_LIBRARIES}") - message(STATUS "Knowhere openblas found: ${BLAS_FOUND}") - endif() - - + find_package(BLAS) if (BLAS_FOUND) add_library(openblas ALIAS BLAS::BLAS) else() @@ -248,7 +240,9 @@ if (KNOWHERE_WITH_OPENBLAS) elseif (OpenBLAS_SOURCE STREQUAL "BUNDLED") build_openblas() elseif (OpenBLAS_SOURCE STREQUAL "SYSTEM") - set (BLA_VENDOR OpenBLAS) + if(LINUX) + set (BLA_VENDOR OpenBLAS) + endif() find_package(BLAS REQUIRED) add_library(openblas ALIAS BLAS::BLAS) endif () diff --git a/thirdparty/DiskANN/src/aux_utils.cpp b/thirdparty/DiskANN/src/aux_utils.cpp index 54bc0a61f..05c66bad8 100644 --- a/thirdparty/DiskANN/src/aux_utils.cpp +++ b/thirdparty/DiskANN/src/aux_utils.cpp @@ -18,7 +18,6 @@ #include "aux_utils.h" #include "cached_io.h" #include "index.h" -#include "openblas/cblas.h" #include "omp.h" #include "partition_and_pq.h" #include "percentile_stats.h" diff --git a/thirdparty/DiskANN/src/math_utils.cpp b/thirdparty/DiskANN/src/math_utils.cpp index dfca4f6ea..40c1067f0 100644 --- a/thirdparty/DiskANN/src/math_utils.cpp +++ b/thirdparty/DiskANN/src/math_utils.cpp @@ -5,10 +5,46 @@ #include #include #include -#include "openblas/cblas.h" #include "logger.h" #include "utils.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef OPENBLAS_CONST +# define OPENBLAS_CONST const +#endif + +typedef int blasint; + +typedef enum CBLAS_ORDER { + CblasRowMajor = 101, + CblasColMajor = 102 +} CBLAS_ORDER; +typedef enum CBLAS_TRANSPOSE { + CblasNoTrans = 111, + CblasTrans = 112, + CblasConjTrans = 113, + CblasConjNoTrans = 114 +} CBLAS_TRANSPOSE; + +float cblas_snrm2(const int N, const float* X, const int incX); +void cblas_sgemm(OPENBLAS_CONST enum CBLAS_ORDER Order, + OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, + OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, + OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, + OPENBLAS_CONST blasint K, OPENBLAS_CONST float alpha, + OPENBLAS_CONST float* A, OPENBLAS_CONST blasint lda, + OPENBLAS_CONST float* B, OPENBLAS_CONST blasint ldb, + OPENBLAS_CONST float beta, float* C, + OPENBLAS_CONST blasint ldc); +#ifdef __cplusplus +} +#endif + + namespace math_utils { float calc_distance(float* vec_1, float* vec_2, size_t dim) {