Skip to content

Commit

Permalink
build: add MKLDNN_INSTALL_MODE option
Browse files Browse the repository at this point in the history
  • Loading branch information
densamoilov committed Apr 11, 2019
1 parent 2925e14 commit 2c02e0b
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 3 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,9 @@ add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tests)

# Cannot use CMAKE_INSTALL_DOCDIR since it uses PROJECT_NAME and not LIB_NAME
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${LIB_NAME})
if(MKLDNN_INSTALL_MODE STREQUAL "BUNDLE")
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_PREFIX})
else()
# Cannot use CMAKE_INSTALL_DOCDIR since it uses PROJECT_NAME and not LIB_NAME
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${LIB_NAME})
endif()
25 changes: 24 additions & 1 deletion cmake/MKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ function(detect_mkl LIBNAME)
endif()
endif()

if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel"
OR MKLDNN_INSTALL_MODE STREQUAL "BUNDLE")
get_filename_component(MKLLIBPATH ${MKLLIB} PATH)
find_library(MKLIOMP5LIB
NAMES "iomp5" "iomp5md" "libiomp5" "libiomp5md"
Expand All @@ -171,6 +172,15 @@ function(detect_mkl LIBNAME)
set(MKLIOMP5DLL)
endif()

if(MKLDNN_INSTALL_MODE STREQUAL "BUNDLE"
AND NOT MKLDNN_THREADING STREQUAL "TBB"
AND NOT (MKLDNN_THREADING STREQUAL "OMP:COMP"
AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
set(INSTALL_IOMP5 TRUE)
else()
set(INSTALL_IOMP5 FALSE)
endif()

get_filename_component(MKLLIBPATH "${MKLLIB}" PATH)
string(FIND "${MKLLIBPATH}" ${CMAKE_CURRENT_SOURCE_DIR}/external __idx)
if(${__idx} EQUAL 0)
Expand All @@ -181,6 +191,13 @@ function(detect_mkl LIBNAME)
install(PROGRAMS ${MKLLIB} ${MKLIOMP5LIB}
DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
elseif(INSTALL_IOMP5)
if(WIN32)
install(PROGRAMS ${MKLIOMP5DLL} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(PROGRAMS ${MKLIOMP5LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
install(PROGRAMS ${MKLIOMP5LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()

if(WIN32)
Expand Down Expand Up @@ -236,6 +253,12 @@ detect_mkl("mklml")
detect_mkl("mkl_rt")

if(HAVE_MKL)
if(MKLDNN_INSTALL_MODE STREQUAL "BUNDLE"
AND NOT MKLDNN_USE_MKL STREQUAL "FULL:STATIC")
message(FATAL_ERROR "MKL-DNN can only be installed as a bundle with
MKLDNN_USE_MKL set to FULL:STATIC")
endif()

if (MKLDNN_USE_MKL STREQUAL "FULL:STATIC")
set(MKLDLL "")
get_filename_component(MKLLIBPATH "${MKLLIB}" PATH)
Expand Down
7 changes: 7 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ option(MKLDNN_BUILD_EXAMPLES "builds examples" ON)
option(MKLDNN_BUILD_TESTS "builds tests" ON)
option(MKLDNN_WERROR "treat warnings as errors" ON)

set(MKLDNN_INSTALL_MODE "DEFAULT" CACHE STRING
"specifies installation mode; supports DEFAULT or BUNDLE.
When BUNDLE option is set MKL-DNN will be installed as a bundle
which contains examples and benchdnn.
The BUNDLE option requires MKLDNN_USE_MKL be set to FULL:STATIC.")

set(MKLDNN_THREADING "OMP" CACHE STRING
"specifies threading type; supports OMP (default), OMP:COMP, OMP:INTEL, or TBB.
Expand Down
10 changes: 10 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ register_exe(simple-net-int8-cpp simple_net_int8.cpp "test")
register_exe(simple-rnn-cpp simple_rnn.cpp "test")
register_exe(simple-rnn-int8-cpp simple_rnn_int8.cpp "test")
register_exe(simple-rnn-training-cpp simple_rnn_training.cpp "test")

if (MKLDNN_INSTALL_MODE STREQUAL "BUNDLE")
file(GLOB example_sources "*.cpp" "*.c")
configure_file(CMakeLists.txt.in CMakeLists.txt @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt
${PROJECT_SOURCE_DIR}/cmake/template.vcxproj.user
${example_sources}
DESTINATION examples)
endif()
93 changes: 93 additions & 0 deletions examples/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#===============================================================================
# Copyright 2019 Intel Corporation
#
# Licensed 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.
#===============================================================================

cmake_minimum_required(VERSION 2.8.11)
project (MKLDNN_EXAMPLES)

if(POLICY CMP0015)
cmake_policy(SET CMP0015 NEW)
endif()

set(MKLDNNROOT "..")

if(APPLE OR WIN32)
set(LIBDIR ${MKLDNNROOT}/lib)
else()
set(LIBDIR ${MKLDNNROOT}/lib64)
endif()

link_directories(${LIBDIR})
include_directories(${MKLDNNROOT}/include)

enable_testing()

if(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qstd=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++11")
else()
set(LIBM m)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
endif()
endif()

if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_definitions(/Qpar)
add_definitions(/openmp)
else()
find_package(OpenMP)
#newer version for findOpenMP (>= v. 3.9)
if(CMAKE_VERSION VERSION_LESS "3.9" AND OPENMP_FOUND)
if(${CMAKE_MAJOR_VERSION} VERSION_LESS "3" AND
${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
# Override FindOpenMP flags for Intel Compiler (otherwise deprecated)
set(OpenMP_CXX_FLAGS "-fopenmp")
set(OpenMP_C_FLAGS "-fopenmp")
endif()
set(OpenMP_C_FOUND true)
set(OpenMP_CXX_FOUND true)
endif()
if(OpenMP_C_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
endif()
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
endif()

# Register example
# name -- name of the executable
# srcs -- list of source, if many must be enclosed with ""
function(register_example name srcs)
add_executable(${name} ${srcs})
find_package(mkldnn @PROJECT_VERSION@ CONFIG REQUIRED HINTS ${LIBDIR}/cmake/mkldnn)
target_link_libraries(${name} mkldnn ${LIBM})
add_test(${name} ${name})
if(WIN32 OR MINGW)
set_property(TEST ${name} PROPERTY ENVIRONMENT "PATH=${CTESTCONFIG_PATH};$ENV{PATH}")
configure_file(template.vcxproj.user ${name}.vcxproj.user @ONLY)
endif()
endfunction()

register_example(simple-net-c simple_net.c)
register_example(simple-net-cpp simple_net.cpp)
register_example(simple-training-net-c simple_training_net.c)
register_example(simple-training-net-cpp simple_training_net.cpp)
register_example(simple-net-int8-cpp simple_net_int8.cpp)
register_example(simple-rnn-cpp simple_rnn.cpp)
register_example(simple-rnn-training-cpp simple_rnn_training.cpp)
6 changes: 6 additions & 0 deletions tests/benchdnn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ register_benchdnn_test(test_benchdnn_regression
register_benchdnn_test(test_benchdnn_regression_large
"benchdnn --bnorm --batch=inputs/bnorm/test_bnorm_regressions_large"
)

if(MKLDNN_INSTALL_MODE STREQUAL "BUNDLE")
install(TARGETS benchdnn RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES README.md DESTINATION ${CMAKE_INSTALL_DATADIR}/benchdnn)
install(DIRECTORY inputs DESTINATION ${CMAKE_INSTALL_DATADIR}/benchdnn)
endif()

0 comments on commit 2c02e0b

Please sign in to comment.