forked from oneapi-src/oneDNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MKL.cmake
213 lines (197 loc) · 7.27 KB
/
MKL.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#===============================================================================
# Copyright 2016-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#===============================================================================
# Locate Intel(R) MKL installation using MKLROOT or look in
# ${CMAKE_CURRENT_SOURCE_DIR}/external
#===============================================================================
if(MKL_cmake_included)
return()
endif()
set(MKL_cmake_included true)
function(detect_mkl LIBNAME)
if(HAVE_MKL)
return()
endif()
message(STATUS "Detecting Intel(R) MKL: trying ${LIBNAME}")
find_path(MKLINC mkl_cblas.h
HINTS ${MKLROOT}/include $ENV{MKLROOT}/include)
if(NOT MKLINC)
file(GLOB_RECURSE MKLINC
${CMAKE_CURRENT_SOURCE_DIR}/external/*/mkl_cblas.h)
if(MKLINC)
# if user has multiple version under external/ then guess last
# one alphabetically is "latest" and warn
list(LENGTH MKLINC MKLINCLEN)
if(MKLINCLEN GREATER 1)
list(SORT MKLINC)
list(REVERSE MKLINC)
# message(STATUS "MKLINC found ${MKLINCLEN} files:")
# foreach(LOCN IN LISTS MKLINC)
# message(STATUS " ${LOCN}")
# endforeach()
list(GET MKLINC 0 MKLINCLST)
set(MKLINC "${MKLINCLST}")
# message(WARNING "MKLINC guessing... ${MKLINC}. "
# "Please check that above dir has the desired mkl_cblas.h")
endif()
get_filename_component(MKLINC ${MKLINC} PATH)
endif()
endif()
if(NOT MKLINC)
return()
endif()
get_filename_component(__mklinc_root "${MKLINC}" PATH)
find_library(MKLLIB NAMES ${LIBNAME}
HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64
$ENV{MKLROOT}/lib $ENV{MKLROOT}/lib/intel64
${__mklinc_root}/lib ${__mklinc_root}/lib/intel64)
if(NOT MKLLIB)
return()
endif()
if(WIN32)
set(MKLREDIST ${MKLINC}/../../redist/)
find_file(MKLDLL NAMES ${LIBNAME}.dll
HINTS
${MKLREDIST}/mkl
${MKLREDIST}/intel64/mkl
${__mklinc_root}/lib)
if(NOT MKLDLL)
return()
endif()
endif()
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
get_filename_component(MKLLIBPATH ${MKLLIB} PATH)
find_library(MKLIOMP5LIB
NAMES "iomp5" "iomp5md" "libiomp5" "libiomp5md"
HINTS ${MKLLIBPATH}
${MKLLIBPATH}/../../lib
${MKLLIBPATH}/../../../lib/intel64
${MKLLIBPATH}/../../compiler/lib
${MKLLIBPATH}/../../../compiler/lib/intel64)
if(NOT MKLIOMP5LIB)
return()
endif()
if(WIN32)
find_file(MKLIOMP5DLL
NAMES "libiomp5.dll" "libiomp5md.dll"
HINTS ${MKLREDIST}/../compiler ${__mklinc_root}/lib)
if(NOT MKLIOMP5DLL)
return()
endif()
endif()
else()
set(MKLIOMP5LIB)
set(MKLIOMP5DLL)
endif()
get_filename_component(MKLLIBPATH "${MKLLIB}" PATH)
string(FIND "${MKLLIBPATH}" ${CMAKE_CURRENT_SOURCE_DIR}/external __idx)
if(${__idx} EQUAL 0)
if(WIN32)
if(MINGW)
# We need to install *.dll into bin/ instead of lib/.
install(PROGRAMS ${MKLDLL} DESTINATION bin)
else()
install(PROGRAMS ${MKLDLL} DESTINATION lib)
endif()
else()
install(PROGRAMS ${MKLLIB} DESTINATION lib)
endif()
if(MKLIOMP5LIB)
if(WIN32)
if(MINGW)
# We need to install *.dll into bin/ instead of lib/.
install(PROGRAMS ${MKLIOMP5DLL} DESTINATION bin)
else()
install(PROGRAMS ${MKLIOMP5DLL} DESTINATION lib)
endif()
else()
install(PROGRAMS ${MKLIOMP5LIB} DESTINATION lib)
endif()
endif()
endif()
if(WIN32)
# Add paths to DLL to %PATH% on Windows
get_filename_component(MKLDLLPATH "${MKLDLL}" PATH)
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}\;${MKLDLLPATH}")
set(CTESTCONFIG_PATH "${CTESTCONFIG_PATH}" PARENT_SCOPE)
endif()
if (${LIBNAME} STREQUAL "mkl_intel_lp64")
Message(STATUS "We need extra libs to link whole Intel MKL")
find_library(MKL_GNU_THREAD_LIB NAMES "mkl_gnu_thread"
HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64
$ENV{MKLROOT}/lib $ENV{MKLROOT}/lib/intel64
${__mklinc_root}/lib ${__mklinc_root}/lib/intel64)
if(NOT MKL_GNU_THREAD_LIB)
return()
endif()
find_library(MKL_CORE_LIB NAMES "mkl_core"
HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64
$ENV{MKLROOT}/lib $ENV{MKLROOT}/lib/intel64
${__mklinc_root}/lib ${__mklinc_root}/lib/intel64)
if(NOT MKL_CORE_LIB)
return()
endif()
set(MKLLIB "${MKLLIB}" "${MKL_GNU_THREAD_LIB}" "${MKL_CORE_LIB}")
endif()
# TODO: cache the value
set(HAVE_MKL TRUE PARENT_SCOPE)
set(MKLINC ${MKLINC} PARENT_SCOPE)
set(MKLLIB "${MKLLIB}" PARENT_SCOPE)
if(WIN32)
set(MKLDLL "${MKLDLL}" PARENT_SCOPE)
endif()
if(MKLIOMP5LIB)
set(MKLIOMP5LIB "${MKLIOMP5LIB}" PARENT_SCOPE)
endif()
if(WIN32 AND MKLIOMP5DLL)
set(MKLIOMP5DLL "${MKLIOMP5DLL}" PARENT_SCOPE)
endif()
endfunction()
detect_mkl("mkl_intel_lp64")
detect_mkl("mklml_intel")
detect_mkl("mklml")
detect_mkl("mkl_rt")
if(HAVE_MKL)
add_definitions(-DUSE_MKL -DUSE_CBLAS)
include_directories(AFTER ${MKLINC})
list(APPEND mkldnn_LINKER_LIBS ${MKLLIB})
set(MSG "Intel(R) MKL:")
message(STATUS "${MSG} include ${MKLINC}")
message(STATUS "${MSG} lib ${MKLLIB}")
if(MKLIOMP5LIB)
message(STATUS "${MSG} OpenMP lib ${MKLIOMP5LIB}")
else()
message(STATUS "${MSG} OpenMP lib provided by compiler")
endif()
if(WIN32)
message(STATUS "${MSG} dll ${MKLDLL}")
if(MKLIOMP5DLL)
message(STATUS "${MSG} OpenMP dll ${MKLIOMP5DLL}")
else()
message(STATUS "${MSG} OpenMP dll provided by compiler")
endif()
endif()
else()
if(DEFINED ENV{FAIL_WITHOUT_MKL} OR DEFINED FAIL_WITHOUT_MKL)
set(SEVERITY "FATAL_ERROR")
else()
set(SEVERITY "WARNING")
endif()
message(${SEVERITY}
"Intel(R) MKL not found. Some performance features may not be "
"available. Please run scripts/prepare_mkl.sh to download a minimal "
"set of libraries or get a full version from "
"https://software.intel.com/en-us/intel-mkl")
endif()