cblas.cmake 5.7 KB
Newer Older
L
lzhao4ever 已提交
1
# Find the CBlas and lapack libraries
Z
zhangjinchao01 已提交
2 3 4 5 6 7
#
# It will search MKL, atlas, OpenBlas, reference-cblas in order.
#
# If any cblas implementation found, the following variable will be set.
#    CBLAS_PROVIDER  # one of MKL, ATLAS, OPENBLAS, REFERENCE
#    CBLAS_INC_DIR   # the include directory for cblas.
8
#    CBLAS_LIBS      # a list of libraries should be linked by paddle.
Z
zhangjinchao01 已提交
9 10 11 12 13 14 15
#                    # Each library should be full path to object file.
#
# User should set one of MKL_ROOT, ATLAS_ROOT, OPENBLAS_ROOT, REFERENCE_CBLAS_ROOT
# during cmake. If none of them set, it will try to find cblas implementation in
# system paths.
#

16 17 18 19
if(USE_EIGEN_FOR_BLAS)
  return()
endif(USE_EIGEN_FOR_BLAS)

L
liaogang 已提交
20
set(CBLAS_FOUND OFF)
Z
zhangjinchao01 已提交
21

T
tensor-tang 已提交
22 23
## Find MKLML First.
if(WITH_MKLML AND MKLML_INC_DIR AND MKLML_LIB)
T
tensor-tang 已提交
24
  set(CBLAS_FOUND ON)
T
tensor-tang 已提交
25 26 27
  set(CBLAS_PROVIDER MKLML)
  set(CBLAS_INC_DIR ${MKLML_INC_DIR})
  set(CBLAS_LIBRARIES ${MKLML_LIB})
T
tensor-tang 已提交
28

T
tensor-tang 已提交
29
  add_definitions(-DPADDLE_USE_MKLML)
T
tensor-tang 已提交
30 31
  add_definitions(-DLAPACK_FOUND)

T
tensor-tang 已提交
32
  message(STATUS "Found cblas and lapack in MKLML "
T
tensor-tang 已提交
33 34 35 36 37
    "(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  return()
endif()

## Then find MKL.
38 39 40 41 42 43 44 45 46 47 48 49
set(INTEL_MKL_ROOT "/opt/intel/mkl" CACHE PATH "Folder contains intel mkl libs")
set(MKL_ROOT $ENV{MKL_ROOT} CACHE PATH "Folder contains env MKL")

set(MKL_INCLUDE_SEARCH_PATHS
  ${MKL_ROOT}/include
  ${INTEL_MKL_ROOT}/include)
set(MKL_LIB_SEARCH_PATHS
  ${MKL_ROOT}/lib
  ${MKL_ROOT}/lib/intel64
  ${INTEL_MKL_ROOT}/lib
  ${INTEL_MKL_ROOT}/lib/intel64)

L
Liu Yiqun 已提交
50
find_path(MKL_INC_DIR mkl.h PATHS
51
  ${MKL_INCLUDE_SEARCH_PATHS})
L
Liu Yiqun 已提交
52
find_path(MKL_LAPACK_INC_DIR mkl_lapacke.h PATHS
53
  ${MKL_INCLUDE_SEARCH_PATHS})
B
backyes 已提交
54
find_library(MKL_CORE_LIB NAMES mkl_core PATHS
55
  ${MKL_LIB_SEARCH_PATHS})
B
backyes 已提交
56
find_library(MKL_SEQUENTIAL_LIB NAMES mkl_sequential PATHS
57
  ${MKL_LIB_SEARCH_PATHS})
B
backyes 已提交
58
find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS
59
  ${MKL_LIB_SEARCH_PATHS})
Z
zhangjinchao01 已提交
60

L
liaogang 已提交
61 62
if(MKL_LAPACK_INC_DIR AND MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64)
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
63
  set(CBLAS_PROVIDER MKL)
L
liaogang 已提交
64 65 66
  set(CBLAS_INC_DIR ${MKL_INC_DIR} ${MKL_LAPACK_INC_DIR})
  set(CBLAS_LIBRARIES ${MKL_INTEL_LP64} ${MKL_SEQUENTIAL_LIB} ${MKL_CORE_LIB})

Z
zhangjinchao01 已提交
67
  add_definitions(-DPADDLE_USE_MKL)
L
liaogang 已提交
68
  add_definitions(-DLAPACK_FOUND)
L
liaogang 已提交
69 70 71 72

  message(STATUS "Found MKL (include: ${MKL_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  message(STATUS "Found lapack in MKL (include: ${MKL_LAPACK_INC_DIR})")
  return()
Z
zhangjinchao01 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85
endif()

## 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 已提交
86 87
        /usr/lib/atlas-base   # special for ubuntu 14.04.
    )
88
find_path(ATLAS_INC_DIR NAMES cblas.h
Z
zhangjinchao01 已提交
89
  PATHS ${ATLAS_INCLUDE_SEARCH_PATHS})
L
lzhao4ever 已提交
90 91
find_path(ATLAS_CLAPACK_INC_DIR NAMES clapack.h
  PATHS ${ATLAS_INCLUDE_SEARCH_PATHS})
92
find_library(ATLAS_CBLAS_LIB NAMES cblas libcblas.so.3
Z
zhangjinchao01 已提交
93
  PATHS ${ATLAS_LIB_SEARCH_PATHS})
L
liaogang 已提交
94
find_library(ATLAS_CLAPACK_LIB NAMES lapack_atlas liblapack_atlas.so.3
Z
zhangjinchao01 已提交
95 96
  PATHS ${ATLAS_LIB_SEARCH_PATHS})

L
liaogang 已提交
97 98
if(ATLAS_CLAPACK_INC_DIR AND ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_CLAPACK_LIB)
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
99
  set(CBLAS_PROVIDER ATLAS)
L
liaogang 已提交
100 101 102
  set(CBLAS_INC_DIR ${ATLAS_INC_DIR} ${ATLAS_CLAPACK_INC_DIR})
  set(CBLAS_LIBRARIES ${ATLAS_CLAPACK_LIB} ${ATLAS_CBLAS_LIB})

103
  add_definitions(-DPADDLE_USE_ATLAS)
L
liaogang 已提交
104
  add_definitions(-DLAPACK_FOUND)
L
liaogang 已提交
105 106 107

  message(STATUS "Found ATLAS (include: ${ATLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  message(STATUS "Found lapack in ATLAS (include: ${ATLAS_CLAPACK_INC_DIR})")
Z
zhangjinchao01 已提交
108 109 110 111 112 113 114 115
  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 已提交
116 117
        /usr/include/openblas
        /usr/local/opt/openblas/include)
Z
zhangjinchao01 已提交
118 119 120 121
set(OPENBLAS_LIB_SEARCH_PATHS
        ${OPENBLAS_ROOT}/lib
        /usr/lib
        /usr/lib/blas/openblas
L
liaogang 已提交
122 123
        /usr/lib/openblas
        /usr/local/opt/openblas/lib)
Z
zhangjinchao01 已提交
124 125 126

find_path(OPENBLAS_INC_DIR NAMES cblas.h
  PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
L
lzhao4ever 已提交
127 128
find_path(OPENBLAS_LAPACKE_INC_DIR NAMES lapacke.h
  PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
Z
zhangjinchao01 已提交
129 130 131
find_library(OPENBLAS_LIB NAMES openblas
  PATHS ${OPENBLAS_LIB_SEARCH_PATHS})

L
liaogang 已提交
132 133
if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB)
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
134
  set(CBLAS_PROVIDER OPENBLAS)
L
liaogang 已提交
135
  set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR})
L
liaogang 已提交
136
  set(CBLAS_LIBRARIES ${OPENBLAS_LIB})
L
liaogang 已提交
137

L
liaogang 已提交
138
  add_definitions(-DPADDLE_USE_OPENBLAS)
L
liaogang 已提交
139
  add_definitions(-DLAPACK_FOUND)
L
liaogang 已提交
140 141 142

  message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
  message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})")
Z
zhangjinchao01 已提交
143 144 145 146 147 148 149
  return()
endif()


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


150
set(REFERENCE_CBLAS_ROOT $ENV{REFERENCE_CBLAS_ROOT} CACHE PATH
Z
zhangjinchao01 已提交
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
  "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 已提交
171
  set(CBLAS_FOUND ON)
Z
zhangjinchao01 已提交
172 173
  set(CBLAS_PROVIDER REFERENCE)
  set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR})
L
liaogang 已提交
174
  set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY})
L
liaogang 已提交
175
  add_definitions(-DPADDLE_USE_REFERENCE_CBLAS)
L
liaogang 已提交
176
  message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
Z
zhangjinchao01 已提交
177
endif()