1 #===============================================================================
2 # Copyright (C) 2018-2019 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 (CMAKE_CXX_STANDARD 11)
23 set (CMAKE_CXX_STANDARD_REQUIRED ON)
25 set(version_cmake_included true)
28 set(MKLDNN_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/mkl-dnn)
30 string(REPLACE "." ";" VERSION_LIST "0.18.0")
31 list(GET VERSION_LIST 0 MKLDNN_VERSION_MAJOR)
32 list(GET VERSION_LIST 1 MKLDNN_VERSION_MINOR)
33 list(GET VERSION_LIST 2 MKLDNN_VERSION_PATCH)
37 execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
38 WORKING_DIRECTORY ${MKLDNN_ROOT}
39 RESULT_VARIABLE RESULT
40 OUTPUT_VARIABLE MKLDNN_VERSION_HASH
41 OUTPUT_STRIP_TRAILING_WHITESPACE)
44 if(NOT GIT_FOUND OR RESULT)
45 set(MKLDNN_VERSION_HASH "N/A")
49 "${MKLDNN_ROOT}/include/mkldnn_version.h.in"
50 "${CMAKE_BINARY_DIR}/include/mkldnn_version.h"
53 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 "OMP")
85 add_definitions(-DMKLDNN_THR=MKLDNN_THR_OMP)
87 add_definitions(-DMKLDNN_THR=MKLDNN_THR_SEQ)
91 ${MKLDNN_ROOT}/include/*.h
92 ${MKLDNN_ROOT}/include/*.hpp
95 ${MKLDNN_ROOT}/src/*.c
96 ${MKLDNN_ROOT}/src/*.cpp
97 ${MKLDNN_ROOT}/src/*.h
98 ${MKLDNN_ROOT}/src/*.hpp
101 ${MKLDNN_ROOT}/include
103 ${MKLDNN_ROOT}/src/common
104 ${MKLDNN_ROOT}/src/cpu/
105 ${MKLDNN_ROOT}/src/cpu/xbyak
106 ${CMAKE_BINARY_DIR}/include/
110 add_definitions(-D_WIN)
111 add_definitions(-DNOMINMAX)
112 # Correct 'jnl' macro/jit issue
113 if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
114 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qlong-double /bigobj")
118 # to make build time reasonable, don't use optimizations for s8u8s32 Xbyak
120 file(GLOB FILES_WITHNO_OPT
121 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_kernel_b0_gemm_s8u8s32_kern.cpp
122 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_kernel_gemm_s8u8s32_kern.cpp
123 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_u8_copy_an_kern.cpp
124 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_u8_copy_at_kern.cpp
125 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_u8_copy_bn_kern.cpp
126 ${MKLDNN_ROOT}/src/cpu/gemm/s8x8s32/jit_avx512_core_u8_copy_bt_kern.cpp)
127 if(WIN32 AND NOT MINGW)
128 set_source_files_properties(${FILES_WITHNO_OPT}
129 PROPERTIES COMPILE_FLAGS "/Od")
131 set_source_files_properties(${FILES_WITHNO_OPT}
132 PROPERTIES COMPILE_FLAGS "-O0 -U_FORTIFY_SOURCE")
135 add_library(${TARGET} STATIC ${HDR} ${SRC})
136 set_ie_threading_interface_for(${TARGET})
138 if(GEMM STREQUAL "OPENBLAS")
139 ## enable cblas_gemm from OpenBLAS package
140 add_definitions(-DUSE_CBLAS)
141 include_directories(${BLAS_INCLUDE_DIRS})
142 list(APPEND ${TARGET}_LINKER_LIBS ${BLAS_LIBRARIES})
143 elseif (GEMM STREQUAL "MKL")
144 ## enable cblas_gemm from mlkml package
148 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
149 detect_mkl("mklml_intel")
151 detect_mkl("mklml_gnu")
154 add_definitions(-DUSE_MKL -DUSE_CBLAS)
155 include_directories(AFTER ${MKLINC})
156 list(APPEND ${TARGET}_LINKER_LIBS ${MKLLIB})
158 ## enable jit_gemm from mlk-dnn
160 target_link_libraries(${TARGET} PRIVATE ${${TARGET}_LINKER_LIBS})