[IE][VPU]: Fix behavior tests for MXpcie (#1879)
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkldnn.cmake
1 #===============================================================================
2 # Copyright (C) 2018-2020 Intel Corporation
3 #
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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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 #===============================================================================
16 #
17 #  Brief description: This cmake file replase original mkl-dnn build scripts
18 #  for more convenient integration to IE build process
19 #
20 #===============================================================================
21
22 set(version_cmake_included true)
23
24 set(TARGET mkldnn)
25 set(MKLDNN_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/mkl-dnn)
26
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)
31
32 find_package(Git)
33 if (GIT_FOUND)
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)
39 endif()
40
41 if(NOT GIT_FOUND OR RESULT)
42     set(MKLDNN_VERSION_HASH "N/A")
43 endif()
44
45 configure_file(
46     "${MKLDNN_ROOT}/include/mkldnn_version.h.in"
47     "${CMAKE_BINARY_DIR}/include/mkldnn_version.h"
48 )
49
50 function(detect_mkl LIBNAME)
51     unset(MKLLIB CACHE)
52     unset(MKLINC CACHE)
53
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")
57
58     if(NOT MKLLIB OR NOT MKLINC)
59         message(FATAL_ERROR "${MKLINC} or ${MKLLIB} are not found")
60         return()
61     endif()
62
63     if(WIN32)
64         find_file(MKLDLL ${LIBNAME}.dll PATHS "${MKL}/lib")
65         if(NOT MKLDLL)
66             message(FATAL_ERROR "${LIBNAME} not found")
67             return()
68         endif()
69     endif()
70
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}")
75
76     if(WIN32)
77         set(MKLDLL "${MKLDLL}" PARENT_SCOPE)
78         message(STATUS "Intel(R) MKL: dll ${MKLDLL}")
79     endif()
80 endfunction()
81
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)
88 else()
89     add_definitions(-DMKLDNN_THR=MKLDNN_THR_SEQ)
90 endif ()
91
92 file(GLOB_RECURSE HDR
93         ${MKLDNN_ROOT}/include/*.h
94         ${MKLDNN_ROOT}/include/*.hpp
95 )
96 file(GLOB_RECURSE SRC
97         ${MKLDNN_ROOT}/src/*.c
98         ${MKLDNN_ROOT}/src/*.cpp
99         ${MKLDNN_ROOT}/src/*.h
100         ${MKLDNN_ROOT}/src/*.hpp
101 )
102 include_directories(
103         ${MKLDNN_ROOT}/include
104         ${MKLDNN_ROOT}/src
105         ${MKLDNN_ROOT}/src/common
106         ${MKLDNN_ROOT}/src/cpu/
107         ${MKLDNN_ROOT}/src/cpu/xbyak
108         ${CMAKE_BINARY_DIR}/include/
109 )
110
111 if(WIN32)
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")
117     endif()
118 endif()
119
120 add_library(${TARGET} STATIC ${HDR} ${SRC})
121 set_ie_threading_interface_for(${TARGET})
122
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
130     if(WIN32 OR APPLE)
131         detect_mkl("mklml")
132     else()
133         if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
134             detect_mkl("mklml_intel")
135         else()
136             detect_mkl("mklml_gnu")
137         endif()
138     endif()
139     add_definitions(-DUSE_MKL -DUSE_CBLAS)
140     include_directories(AFTER ${MKLINC})
141     list(APPEND ${TARGET}_LINKER_LIBS ${MKLLIB})
142 endif()
143 ## enable jit_gemm from mlk-dnn
144
145 add_definitions(-DMKLDNN_ENABLE_CONCURRENT_EXEC)
146
147 target_link_libraries(${TARGET} PRIVATE ${${TARGET}_LINKER_LIBS})