This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
FindMKL.cmake
170 lines (141 loc) · 4.97 KB
/
FindMKL.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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# Find the MKL libraries
#
# Options:
#
# MKL_USE_SINGLE_DYNAMIC_LIBRARY : use single dynamic library interface
# MKL_USE_STATIC_LIBS : use static libraries
# MKL_MULTI_THREADED : use multi-threading
# MKL_USE_ILP64 : use ilp64 data model
# MKL_USE_CLUSTER : use cluster libraries
#
# This module defines the following variables:
#
# MKL_FOUND : True mkl is found
# MKL_INCLUDE_DIR : unclude directory
# MKL_LIBRARIES : the libraries to link against.
#
if(MKL_FOUND)
return()
endif()
if($ENV{MKLROOT})
file(TO_CMAKE_PATH "$ENV{MKLROOT}" MKLROOT)
message(STATUS "MKLROOT=${MKLROOT}")
endif()
# ---[ Root folders
set(INTEL_ROOT "/opt/intel" CACHE PATH "Folder contains intel libs")
# ---[ Options
mxnet_option(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use single dynamic library interface" ON)
mxnet_option(MKL_USE_STATIC_LIBS "Use static libraries" OFF IF NOT ${MKL_USE_SINGLE_DYNAMIC_LIBRARY})
mxnet_option(MKL_MULTI_THREADED "Use multi-threading" ON IF NOT ${MKL_USE_SINGLE_DYNAMIC_LIBRARY})
mxnet_option(MKL_USE_ILP64 "Use ilp64 data model" OFF)
mxnet_option(MKL_USE_CLUSTER "Use cluster functions" OFF IF ${CMAKE_SIZEOF_VOID_P} EQUAL 4)
set(MKL_INCLUDE_SEARCH_PATHS
${MKL_INCLUDE_SEARCH_PATHS}
"${MKLROOT}"
"${MKLROOT}/include"
"${INTEL_ROOT}/mkl"
)
# ---[ Find include dir
find_path(MKL_INCLUDE_DIR mkl.h
PATHS ${MKL_INCLUDE_SEARCH_PATHS}
PATH_SUFFIXES include)
if(NOT MKLROOT)
get_filename_component(MKLROOT "${MKL_INCLUDE_DIR}" DIRECTORY)
endif()
set(__looked_for MKL_INCLUDE_DIR)
# ---[ Find libraries
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(__path_suffixes lib lib/ia32)
else()
set(__path_suffixes lib lib/intel64)
endif()
set(__mkl_libs "")
if(MKL_USE_SINGLE_DYNAMIC_LIBRARY)
list(APPEND __mkl_libs rt)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
if(WIN32)
list(APPEND __mkl_libs intel_c)
else()
list(APPEND __mkl_libs intel)
if(CMAKE_COMPILER_IS_GNUFORTRAN)
list(APPEND __mkl_libs gf)
endif()
endif()
else()
set(__mkl_lib64_suffix "lp64")
if(MKL_USE_ILP64)
set(__mkl_lib64_suffix "ilp64")
add_definitions(-DMKL_ILP64)
endif()
list(APPEND __mkl_libs "intel_${__mkl_lib64_suffix}")
if(CMAKE_COMPILER_IS_GNUFORTRAN)
list(APPEND __mkl_libs "gf_${__mkl_lib64_suffix}")
endif()
endif()
if(MKL_MULTI_THREADED)
list(APPEND __mkl_libs intel_thread)
else()
list(APPEND __mkl_libs sequential)
endif()
list(APPEND __mkl_libs core)
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MKL_USE_CLUSTER)
list(APPEND __mkl_libs cdft_core)
endif()
endif()
foreach(__lib ${__mkl_libs})
set(__mkl_lib "mkl_${__lib}")
string(TOUPPER ${__mkl_lib} __mkl_lib_upper)
if(MKL_USE_STATIC_LIBS)
set(__mkl_lib "lib${__mkl_lib}.a")
endif()
find_library(${__mkl_lib_upper}_LIBRARY
NAMES ${__mkl_lib}
PATHS "${MKLROOT}"
PATH_SUFFIXES ${__path_suffixes}
DOC "The path to Intel(R) MKL ${__mkl_lib} library")
mark_as_advanced(${__mkl_lib_upper}_LIBRARY)
list(APPEND __looked_for ${__mkl_lib_upper}_LIBRARY)
list(APPEND MKL_LIBRARIES ${${__mkl_lib_upper}_LIBRARY})
endforeach()
if(NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)
if(MKL_USE_STATIC_LIBS)
set(__iomp5_libs iomp5 libiomp5mt.lib)
else()
set(__iomp5_libs iomp5 libiomp5md.lib)
endif()
if(WIN32)
find_path(INTEL_INCLUDE_DIR omp.h
PATHS "${INTEL_ROOT}"
PATH_SUFFIXES include)
list(APPEND __looked_for INTEL_INCLUDE_DIR)
endif()
find_library(MKL_RTL_LIBRARY ${__iomp5_libs}
PATHS "${INTEL_RTL_ROOT}" "${INTEL_ROOT}/compiler" "${MKLROOT}" "${MKLROOT}/.." "${MKLROOT}/../compiler"
PATH_SUFFIXES ${__path_suffixes}
DOC "Path to OpenMP runtime library")
list(APPEND __looked_for MKL_RTL_LIBRARY)
list(APPEND MKL_LIBRARIES ${MKL_RTL_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MKL DEFAULT_MSG ${__looked_for})
if(MKL_FOUND)
message(STATUS "Found MKL (include: ${MKL_INCLUDE_DIR}, lib: ${MKL_LIBRARIES}")
endif()
mxnet_clear_vars(__looked_for __mkl_libs __path_suffixes __lib_suffix __iomp5_libs)