You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Openblas.cmake 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. option (ENABLE_BLAS "Enable openblas for fast neural network processing [default: OFF]" OFF)
  2. IF(ENABLE_BLAS MATCHES "ON")
  3. ProcessPackage(BLAS OPTIONAL_INCLUDE LIBRARY openblas blas
  4. INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas
  5. include/blas
  6. ROOT ${BLAS_ROOT_DIR}
  7. LIB_OUTPUT BLAS_REQUIRED_LIBRARIES)
  8. ProcessPackage(BLAS_LAPACK OPTIONAL_INCLUDE LIBRARY lapack
  9. INCLUDE cblas.h INCLUDE_SUFFIXES include/openblas
  10. include/blas
  11. ROOT ${BLAS_ROOT_DIR}
  12. LIB_OUTPUT BLAS_REQUIRED_LIBRARIES)
  13. ENDIF()
  14. IF(WITH_BLAS)
  15. MESSAGE(STATUS "Use openblas to accelerate kann")
  16. IF(NOT BLAS_INCLUDE)
  17. FIND_FILE(HAVE_CBLAS_H HINTS "${RSPAMD_SEARCH_PATH}"
  18. NAMES cblas.h
  19. DOC "Path to cblas.h header")
  20. IF(NOT HAVE_CBLAS_H)
  21. MESSAGE(STATUS "Blas header cblas.h has not been found, use internal workaround")
  22. ELSE()
  23. ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
  24. ENDIF()
  25. ELSE()
  26. ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_H)
  27. ENDIF()
  28. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sgemm.c" "
  29. #include <stddef.h>
  30. enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
  31. enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112 };
  32. extern void cblas_sgemm(const enum CBLAS_ORDER Order,
  33. const enum CBLAS_TRANSPOSE TA,
  34. const enum CBLAS_TRANSPOSE TB,
  35. const int M, const int N, const int K,
  36. const float alpha, const float *A, const int lda,
  37. const float *B, const int ldb, const float beta,
  38. float *C, const int ldc);
  39. int main(int argc, char **argv)
  40. {
  41. cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 0, 0, 0, 0, NULL, 0,
  42. NULL, 0, 0, NULL, 0);
  43. return 0;
  44. }
  45. ")
  46. try_compile(HAVE_CBLAS_SGEMM
  47. ${CMAKE_CURRENT_BINARY_DIR}
  48. "${CMAKE_CURRENT_BINARY_DIR}/sgemm.c"
  49. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  50. LINK_LIBRARIES ${BLAS_REQUIRED_LIBRARIES}
  51. OUTPUT_VARIABLE SGEMM_ERR)
  52. # Cmake is just brain damaged
  53. #CHECK_LIBRARY_EXISTS(${BLAS_REQUIRED_LIBRARIES} cblas_sgemm "" HAVE_CBLAS_SGEMM)
  54. if(HAVE_CBLAS_SGEMM)
  55. MESSAGE(STATUS "Blas has CBLAS sgemm")
  56. ADD_COMPILE_OPTIONS(-DHAVE_CBLAS_SGEMM)
  57. else()
  58. MESSAGE(STATUS "Blas has -NOT- CBLAS sgemm, use internal workaround: ${SGEMM_ERR}")
  59. endif()
  60. ADD_COMPILE_OPTIONS(-DHAVE_CBLAS)
  61. ENDIF(WITH_BLAS)