cblas.cmake 4.4 KB
Newer Older
L
lzhao4ever 已提交
1
# Find the CBlas and lapack libraries
Z
zhangjinchao01 已提交
2
#
L
Luo Tao 已提交
3
# It will search MKLML, atlas, OpenBlas, reference-cblas in order.
Z
zhangjinchao01 已提交
4 5
#
# If any cblas implementation found, the following variable will be set.
L
Luo Tao 已提交
6
#    CBLAS_PROVIDER  # one of MKLML, ATLAS, OPENBLAS, REFERENCE
Z
zhangjinchao01 已提交
7
#    CBLAS_INC_DIR   # the include directory for cblas.
8
#    CBLAS_LIBS      # a list of libraries should be linked by paddle.
Z
zhangjinchao01 已提交
9 10
#                    # Each library should be full path to object file.

L
liaogang 已提交
11
set(CBLAS_FOUND OFF)
Z
zhangjinchao01 已提交
12

T
tensor-tang 已提交
13 14
## Find MKLML First.
if(WITH_MKLML AND MKLML_INC_DIR AND MKLML_LIB)
T
tensor-tang 已提交
15
  set(CBLAS_FOUND ON)
T
tensor-tang 已提交
16 17 18
  set(CBLAS_PROVIDER MKLML)
  set(CBLAS_INC_DIR ${MKLML_INC_DIR})
  set(CBLAS_LIBRARIES ${MKLML_LIB})
T
tensor-tang 已提交
19

T
tensor-tang 已提交
20
  add_definitions(-DPADDLE_WITH_MKLML)
T
tensor-tang 已提交
21 22
  add_definitions(-DLAPACK_FOUND)

T
tensor-tang 已提交
23
  message(STATUS "Found cblas and lapack in MKLML "
T
tensor-tang 已提交
24 25 26 27
    "(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  return()
endif()

Z
zhangjinchao01 已提交
28 29 30 31 32 33 34 35 36 37 38
## Then find atlas.
set(ATLAS_ROOT $ENV{ATLAS_ROOT} CACHE PATH "Folder contains Atlas")
set(ATLAS_INCLUDE_SEARCH_PATHS
        ${ATLAS_ROOT}/include
        /usr/include
        /usr/include/atlas)
set(ATLAS_LIB_SEARCH_PATHS
        ${ATLAS_ROOT}/lib
        /usr/lib
        /usr/lib/blas/atlas
        /usr/lib/atlas
L
liaogang 已提交
39 40
        /usr/lib/atlas-base   # special for ubuntu 14.04.
    )
41
find_path(ATLAS_INC_DIR NAMES cblas.h
Z
zhangjinchao01 已提交
42
  PATHS ${ATLAS_INCLUDE_SEARCH_PATHS})
L
lzhao4ever 已提交
43 44
find_path(ATLAS_CLAPACK_INC_DIR NAMES clapack.h
  PATHS ${ATLAS_INCLUDE_SEARCH_PATHS})
45
find_library(ATLAS_CBLAS_LIB NAMES cblas libcblas.so.3
Z
zhangjinchao01 已提交
46
  PATHS ${ATLAS_LIB_SEARCH_PATHS})
L
liaogang 已提交
47
find_library(ATLAS_CLAPACK_LIB NAMES lapack_atlas liblapack_atlas.so.3
Z
zhangjinchao01 已提交
48 49
  PATHS ${ATLAS_LIB_SEARCH_PATHS})

L
liaogang 已提交
50 51
if(ATLAS_CLAPACK_INC_DIR AND ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_CLAPACK_LIB)
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
52
  set(CBLAS_PROVIDER ATLAS)
L
liaogang 已提交
53 54 55
  set(CBLAS_INC_DIR ${ATLAS_INC_DIR} ${ATLAS_CLAPACK_INC_DIR})
  set(CBLAS_LIBRARIES ${ATLAS_CLAPACK_LIB} ${ATLAS_CBLAS_LIB})

56
  add_definitions(-DPADDLE_USE_ATLAS)
L
liaogang 已提交
57
  add_definitions(-DLAPACK_FOUND)
L
liaogang 已提交
58 59 60

  message(STATUS "Found ATLAS (include: ${ATLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  message(STATUS "Found lapack in ATLAS (include: ${ATLAS_CLAPACK_INC_DIR})")
Z
zhangjinchao01 已提交
61 62 63 64 65 66 67 68
  return()
endif()

## Then find openblas.
set(OPENBLAS_ROOT $ENV{OPENBLAS_ROOT} CACHE PATH "Folder contains Openblas")
set(OPENBLAS_INCLUDE_SEARCH_PATHS
        ${OPENBLAS_ROOT}/include
        /usr/include
L
liaogang 已提交
69 70
        /usr/include/openblas
        /usr/local/opt/openblas/include)
Z
zhangjinchao01 已提交
71 72 73 74
set(OPENBLAS_LIB_SEARCH_PATHS
        ${OPENBLAS_ROOT}/lib
        /usr/lib
        /usr/lib/blas/openblas
L
liaogang 已提交
75 76
        /usr/lib/openblas
        /usr/local/opt/openblas/lib)
Z
zhangjinchao01 已提交
77 78 79

find_path(OPENBLAS_INC_DIR NAMES cblas.h
  PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
L
lzhao4ever 已提交
80 81
find_path(OPENBLAS_LAPACKE_INC_DIR NAMES lapacke.h
  PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
Z
zhangjinchao01 已提交
82 83 84
find_library(OPENBLAS_LIB NAMES openblas
  PATHS ${OPENBLAS_LIB_SEARCH_PATHS})

L
liaogang 已提交
85 86
if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB)
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
87
  set(CBLAS_PROVIDER OPENBLAS)
L
liaogang 已提交
88
  set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR})
L
liaogang 已提交
89
  set(CBLAS_LIBRARIES ${OPENBLAS_LIB})
L
liaogang 已提交
90

L
liaogang 已提交
91
  add_definitions(-DPADDLE_USE_OPENBLAS)
L
liaogang 已提交
92
  add_definitions(-DLAPACK_FOUND)
L
liaogang 已提交
93 94 95

  message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})")
Z
zhangjinchao01 已提交
96 97 98 99 100 101 102
  return()
endif()


## Then find the reference-cblas.  www.netlib.org/blas/


103
set(REFERENCE_CBLAS_ROOT $ENV{REFERENCE_CBLAS_ROOT} CACHE PATH
Z
zhangjinchao01 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  "Folder contains reference-cblas")
set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS
  ${REFERENCE_CBLAS_ROOT}/include
  /usr/include
  /usr/include/cblas
)

set(REFERENCE_CBLAS_LIB_SEARCH_PATHS
  ${REFERENCE_CBLAS_ROOT}/lib
  /usr/lib
  /usr/lib/blas/reference/
  /usr/lib/reference/
)

find_path(REFERENCE_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS
        ${REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS})
find_library(REFERENCE_CBLAS_LIBRARY NAMES cblas PATHS
        ${REFERENCE_CBLAS_LIB_SEARCH_PATHS})

if (REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY)
L
liaogang 已提交
124
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
125 126
  set(CBLAS_PROVIDER REFERENCE)
  set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR})
L
liaogang 已提交
127
  set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY})
L
liaogang 已提交
128
  add_definitions(-DPADDLE_USE_REFERENCE_CBLAS)
L
liaogang 已提交
129
  message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
Z
zhangjinchao01 已提交
130
endif()
131

132 133 134 135 136
if(IOS_USE_VECLIB_FOR_BLAS AND VECLIB_FOUND)
  set(CBLAS_FOUND ON)
  set(CBLAS_PROVIDER vecLib)
  set(CBLAS_INC_DIR ${VECLIB_INC_DIR})
  add_definitions(-DPADDLE_USE_VECLIB)
137
endif()