1 #===============================================================================
2 # Copyright (C) 2018-2020 Intel Corporation
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #===============================================================================
17 # Brief description: This cmake file replase original mkl-dnn build scripts
18 # for more convenient integration to IE build process
20 #===============================================================================
22 set(version_cmake_included true)
25 set(MKLDNN_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/mkl-dnn)
27 string(REPLACE "." ";" VERSION_LIST "0.18.0")
28 list(GET VERSION_LIST 0 MKLDNN_VERSION_MAJOR)
29 list(GET VERSION_LIST 1 MKLDNN_VERSION_MINOR)
30 list(GET VERSION_LIST 2 MKLDNN_VERSION_PATCH)
34 execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
35 WORKING_DIRECTORY ${MKLDNN_ROOT}
36 RESULT_VARIABLE RESULT
37 OUTPUT_VARIABLE MKLDNN_VERSION_HASH
38 OUTPUT_STRIP_TRAILING_WHITESPACE)
41 if(NOT GIT_FOUND OR RESULT)
42 set(MKLDNN_VERSION_HASH "N/A")
46 "${MKLDNN_ROOT}/include/mkldnn_version.h.in"
47 "${CMAKE_BINARY_DIR}/include/mkldnn_version.h"
50 function(detect_mkl LIBNAME)
54 message(STATUS "Detecting Intel(R) MKL: trying ${LIBNAME}")
55 find_path(MKLINC mkl_cblas.h ${MKL}/include)
56 find_library(MKLLIB ${LIBNAME} "${MKL}/lib")
58 if(NOT MKLLIB OR NOT MKLINC)
59 message(FATAL_ERROR "${MKLINC} or ${MKLLIB} are not found")
64 find_file(MKLDLL ${LIBNAME}.dll PATHS "${MKL}/lib")
66 message(FATAL_ERROR "${LIBNAME} not found")
71 set(MKLINC ${MKLINC} PARENT_SCOPE)
72 set(MKLLIB "${MKLLIB}" PARENT_SCOPE)
73 message(STATUS "Intel(R) MKL: include ${MKLINC}")
74 message(STATUS "Intel(R) MKL: lib ${MKLLIB}")
77 set(MKLDLL "${MKLDLL}" PARENT_SCOPE)
78 message(STATUS "Intel(R) MKL: dll ${MKLDLL}")
82 if (THREADING STREQUAL "TBB")
83 add_definitions(-DMKLDNN_THR=MKLDNN_THR_TBB)
84 elseif (THREADING STREQUAL "TBB_AUTO")
85 add_definitions(-DMKLDNN_THR=MKLDNN_THR_TBB_AUTO)
86 elseif (THREADING STREQUAL "OMP")
87 add_definitions(-DMKLDNN_THR=MKLDNN_THR_OMP)
89 add_definitions(-DMKLDNN_THR=MKLDNN_THR_SEQ)
93 ${MKLDNN_ROOT}/include/*.h
94 ${MKLDNN_ROOT}/include/*.hpp
97 ${MKLDNN_ROOT}/src/*.c
98 ${MKLDNN_ROOT}/src/*.cpp
99 ${MKLDNN_ROOT}/src/*.h
100 ${MKLDNN_ROOT}/src/*.hpp
103 ${MKLDNN_ROOT}/include
105 ${MKLDNN_ROOT}/src/common
106 ${MKLDNN_ROOT}/src/cpu/
107 ${MKLDNN_ROOT}/src/cpu/xbyak
108 ${CMAKE_BINARY_DIR}/include/
112 add_definitions(-D_WIN)
113 add_definitions(-DNOMINMAX)
114 # Correct 'jnl' macro/jit issue
115 if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
116 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qlong-double /bigobj")
120 add_library(${TARGET} STATIC ${HDR} ${SRC})
121 set_ie_threading_interface_for(${TARGET})
123 if(GEMM STREQUAL "OPENBLAS")
124 ## enable cblas_gemm from OpenBLAS package
125 add_definitions(-DUSE_CBLAS)
126 include_directories(${BLAS_INCLUDE_DIRS})
127 list(APPEND ${TARGET}_LINKER_LIBS ${BLAS_LIBRARIES})
128 elseif (GEMM STREQUAL "MKL")
129 ## enable cblas_gemm from mlkml package
133 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
134 detect_mkl("mklml_intel")
136 detect_mkl("mklml_gnu")
139 add_definitions(-DUSE_MKL -DUSE_CBLAS)
140 include_directories(AFTER ${MKLINC})
141 list(APPEND ${TARGET}_LINKER_LIBS ${MKLLIB})
143 ## enable jit_gemm from mlk-dnn
145 add_definitions(-DMKLDNN_ENABLE_CONCURRENT_EXEC)
147 target_link_libraries(${TARGET} PRIVATE ${${TARGET}_LINKER_LIBS})