forked from ITensor/ITensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindMKL.cmake
More file actions
339 lines (296 loc) · 10.6 KB
/
FindMKL.cmake
File metadata and controls
339 lines (296 loc) · 10.6 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# CMake script to detect Intel(R) Math Kernel Library (MKL)
#
# This will try to find Intel MKL libraries, and include path by automatic
# search through typical install locations and if failed it will
# examine MKLROOT environment variable.
# Note, MKLROOT is not set by IPP installer, it should be set manually.
#
# Usage example:
# set(MKL_USE_STATIC_LIBS ON)
# find_package(MKL)
# if (MKL_FOUND)
# include_directories(${MKL_INCLUDE_DIRS})
# link_directories(${MKL_LIBRARY_DIRS})
# add_executable(foo foo.cc)
# target_link_libraries(foo ${MKL_LIBRARIES})
# endif()
#
# Variables used by this module, they can change the default behaviour and
# need to be set before calling find_package:
#
# MKL_ADDITIONAL_VERSIONS A list of version numbers to use for searching
# the MKL include directory.
#
# MKL_USE_STATIC_LIBS Can be set to ON to force the use of the static
# boost libraries. Defaults to OFF.
#
# MKL_FIND_DEBUG Set this to TRUE to enable debugging output
# of FindMKL.cmake if you are having problems.
#
# On return this will define:
# MKL_FOUND Indicates whether MKL was found (True/False)
# MKL_INCLUDE_DIRS MKL include folder
# MKL_LIBRARY_DIRS MKL libraries folder
# MKL_LIBRARIES MKL libraries names
#
# NOTE: this script has only been tested with Intel(R) Parallel Studio XE 2011
# and may need changes for compatibility with older versions.
#
# Adapted from OpenCV IPP detection script
# https://code.ros.org/trac/opencv/browser/trunk/opencv/OpenCVFindIPP.cmake
# Many portions taken from FindBoost.cmake
# TODO:
# - caller needs to link with libiomp5md.lib or /Qopenmp...
# - runtime DLLs:
# <Composer XE directory> -> C:\Program Files\Intel\ComposerXE-2011
# redist\ia32\mkl
# redist\intel64\mkl
set(_MKL_IA32 FALSE)
set(_MKL_INTEL64 FALSE)
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(_MKL_IA32 TRUE)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_MKL_INTEL64 TRUE)
else()
message(FATAL_ERROR "Unsupported 'void *' size (${SIZEOF_VOID_P})")
endif()
# Versions should be listed is decreasing order of preference
set(_MKL_TEST_VERSIONS ${MKL_ADDITIONAL_VERSIONS}
"2011"
# alternative form: "2011.xxx.y"
# (y is the release-update number and xxx is the package number)
)
if (MKL_FIND_VERSION AND NOT MKL_FIND_QUIETLY)
message(WARNING "Requesting a specific version of Intel(R) MKL is not supported")
endif()
# Use environment variables from Intel build scripts, if available
if (NOT MKL_ROOT AND NOT $ENV{MKLROOT} STREQUAL "")
set(MKL_ROOT $ENV{MKLROOT})
endif()
if (MKL_ROOT)
file(TO_CMAKE_PATH ${MKL_ROOT} MKL_ROOT)
endif()
if (NOT INTEL_ROOT AND NOT $ENV{INTELROOT} STREQUAL "")
set(INTEL_ROOT $ENV{INTELROOT})
endif()
if (INTEL_ROOT)
file(TO_CMAKE_PATH ${INTEL_ROOT} INTEL_ROOT)
endif()
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"_MKL_TEST_VERSIONS = ${_MKL_TEST_VERSIONS}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"MKL_ADDITIONAL_VERSIONS = ${MKL_ADDITIONAL_VERSIONS}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"MKL_USE_STATIC_LIBS = ${MKL_USE_STATIC_LIBS}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"MKL_ROOT = ${MKL_ROOT}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"INTEL_ROOT = ${INTEL_ROOT}")
endif()
# Find MKL include directory
set(_MKL_ROOT_SEARCH_DIRS
${MKL_ROOT}
)
foreach (_MKL_VER ${_MKL_TEST_VERSIONS})
if (WIN32)
list(APPEND _MKL_ROOT_SEARCH_DIRS "$ENV{ProgramFiles}/Intel/Composer XE/mkl")
else()
list(APPEND _MKL_ROOT_SEARCH_DIRS "/opt/intel/composerxe-${_MKL_VER}/mkl")
endif()
endforeach()
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"_MKL_ROOT_SEARCH_DIRS = ${_MKL_ROOT_SEARCH_DIRS}")
endif()
find_path(MKL_INCLUDE_DIR
NAMES mkl.h
PATHS ${_MKL_ROOT_SEARCH_DIRS}
PATH_SUFFIXES include
DOC "The path to Intel(R) MKL header files"
)
if (MKL_INCLUDE_DIR)
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"location of mkl.h: ${MKL_INCLUDE_DIR}/mkl.h")
endif()
else()
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"unable to find Intel(R) MKL header files. Please set MKLROOT"
" to the root directory containing MKL.")
endif()
endif()
# Find MKL library directory
set(_INTEL_LIBRARY_DIR_SUFFIXES "lib")
if (_MKL_IA32)
list(APPEND _INTEL_LIBRARY_DIR_SUFFIXES "lib/ia32")
elseif (_MKL_INTEL64)
list(APPEND _INTEL_LIBRARY_DIR_SUFFIXES "lib/intel64")
else()
message(FATAL_ERROR "unreachable")
endif()
set(_MKL_LIBRARY_SEARCH_DIRS ${_MKL_ROOT_SEARCH_DIRS})
if (MKL_INCLUDE_DIR)
list(APPEND _MKL_LIBRARY_SEARCH_DIRS "${MKL_INCLUDE_DIR}/..")
endif()
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"_INTEL_LIBRARY_DIR_SUFFIXES = ${_INTEL_LIBRARY_DIR_SUFFIXES}")
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"_MKL_LIBRARY_SEARCH_DIRS = ${_MKL_LIBRARY_SEARCH_DIRS}")
endif()
set(MKL_LIB_PREFIX "mkl_")
if (MKL_USE_STATIC_LIBS)
if (_MKL_IA32)
if (WIN32)
set(_MKL_LIBRARIES intel_c)
else()
set(_MKL_LIBRARIES intel)
endif()
elseif (_MKL_INTEL64)
set(_MKL_LIBRARIES intel_lp64)
else()
message(FATAL_ERROR "unreachable")
endif()
list(APPEND _MKL_LIBRARIES intel_thread)
list(APPEND _MKL_LIBRARIES core)
else()
set(_MKL_LIBRARIES rt)
endif()
set(_MKL_MISSING_LIBRARIES "")
set(MKL_LIBRARIES "")
set(MKL_LIBRARY_DIRS "")
# Find MKL libraries
foreach (_MKL_LIB_RAW ${_MKL_LIBRARIES})
set(_MKL_LIB ${MKL_LIB_PREFIX}${_MKL_LIB_RAW})
string(TOUPPER ${_MKL_LIB} _MKL_LIB_UPPER)
find_library(${_MKL_LIB_UPPER}_LIBRARY
NAMES ${_MKL_LIB}
PATHS ${_MKL_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${_INTEL_LIBRARY_DIR_SUFFIXES}
DOC "The path to Intel(R) MKL ${_MKL_LIB_RAW} library"
)
mark_as_advanced(${_MKL_LIB_UPPER}_LIBRARY)
if (NOT ${_MKL_LIB_UPPER}_LIBRARY)
list(APPEND _MKL_MISSING_LIBRARIES ${_MKL_LIB})
else()
list(APPEND MKL_LIBRARIES ${${_MKL_LIB_UPPER}_LIBRARY})
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"Found ${_MKL_LIB}: ${${_MKL_LIB_UPPER}_LIBRARY}")
endif()
get_filename_component(_MKL_LIB_PATH "${${_MKL_LIB_UPPER}_LIBRARY}" PATH)
list(APPEND MKL_LIBRARY_DIRS ${_MKL_LIB_PATH})
endif()
endforeach()
## Find OpenMP, pthread and math libraries
set(_INTEL_LIBRARY_SEARCH_DIRS
${INTEL_ROOT}
${INTEL_ROOT}/compiler
)
foreach(_MKL_DIR ${_MKL_ROOT_SEARCH_DIRS})
list(APPEND _INTEL_LIBRARY_SEARCH_DIRS "${_MKL_DIR}/..")
list(APPEND _INTEL_LIBRARY_SEARCH_DIRS "${_MKL_DIR}/../compiler")
endforeach()
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"_INTEL_LIBRARY_SEARCH_DIRS = ${_INTEL_LIBRARY_SEARCH_DIRS}")
endif()
if (NOT WIN32)
find_library(PTHREAD_LIBRARY pthread DOC "Path to POSIX threads library")
endif()
set(_IOMP5_LIB iomp5)
if (WIN32)
if (MKL_USE_STATIC_LIBS)
list(APPEND _IOMP5_LIB libiomp5mt.lib)
else()
list(APPEND _IOMP5_LIB libiomp5md.lib)
endif()
endif()
find_library(IOMP5_LIBRARY
NAMES ${_IOMP5_LIB}
PATHS ${_INTEL_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${_INTEL_LIBRARY_DIR_SUFFIXES}
DOC "Path to OpenMP runtime library"
)
if (NOT IOMP5_LIBRARY)
# we could instead fallback to default library (via FindOpenMP.cmake)
list(APPEND _MKL_MISSING_LIBRARIES IOMP5)
else()
list(APPEND MKL_LIBRARIES ${IOMP5_LIBRARY})
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"Found IOMP5_LIBRARY: ${IOMP5_LIBRARY}")
endif()
get_filename_component(_MKL_LIB_PATH "${IOMP5_LIBRARY}" PATH)
list(APPEND MKL_LIBRARY_DIRS ${_MKL_LIB_PATH})
endif()
# Optimized math library (optional)
set(_MATH_LIB imf) # linked by default with Intel compiler
if (WIN32)
if (MKL_USE_STATIC_LIBS)
list(APPEND _MATH_LIB libmmds.lib) # assumes (/MD) otherwise libmmt.lib (for /MT)
else()
list(APPEND _MATH_LIB libmmd.lib)
endif()
endif()
find_library(MATH_LIBRARY
NAMES ${_MATH_LIB}
PATHS ${_INTEL_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${_INTEL_LIBRARY_DIR_SUFFIXES}
DOC "Path to optimized math library"
)
if (NOT MATH_LIBRARY)
# we could instead fallback to default library (via FindOpenMP.cmake)
list(APPEND _MKL_MISSING_LIBRARIES MATH)
else()
list(APPEND MKL_LIBRARIES ${MATH_LIBRARY})
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"Found MATH_LIBRARY: ${MATH_LIBRARY}")
endif()
get_filename_component(_MKL_LIB_PATH "${MATH_LIBRARY}" PATH)
list(APPEND MKL_LIBRARY_DIRS ${_MKL_LIB_PATH})
endif()
# Check all required libraries are available
list(REMOVE_DUPLICATES MKL_LIBRARY_DIRS)
set(MKL_INCLUDE_DIRS
${MKL_INCLUDE_DIR}
)
set(MKL_FOUND TRUE)
if (NOT MKL_INCLUDE_DIR)
set(MKL_FOUND FALSE)
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"MKL not found - MKL_INCLUDE_DIR was empty")
endif()
elseif (_MKL_MISSING_LIBRARIES)
set(MKL_FOUND FALSE)
if (MKL_FIND_DEBUG)
message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
"MKL not found - the following libraries are missing: "
"${_MKL_MISSING_LIBRARIES}")
endif()
endif()
if (MKL_FOUND)
if (NOT MKL_FIND_QUIETLY OR MKL_FIND_DEBUG)
message(STATUS
"Intel(R) MKL was found:\n"
" MKL_INCLUDE_DIRS: ${MKL_INCLUDE_DIRS}\n"
" MKL_LIBRARY_DIRS: ${MKL_LIBRARY_DIRS}\n"
" MKL_LIBRARIES: ${MKL_LIBRARIES}"
)
endif()
else()
if (MKL_FIND_REQUIRED)
message(SEND_ERROR "Intel(R) MKL could not be found.")
else()
message(STATUS "Intel(R) MKL could not be found.")
endif()
endif()
mark_as_advanced(
MKL_INCLUDE_DIR
MKL_INCLUDE_DIRS
MKL_LIBRARY_DIRS
)