mkldnn.cmake 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserve.
#
# 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.

IF(NOT ${WITH_MKLDNN})
  return()
ENDIF(NOT ${WITH_MKLDNN})

INCLUDE(ExternalProject)

T
tensor-tang 已提交
21 22 23 24 25 26 27 28 29
SET(MKLDNN_PROJECT        "extern_mkldnn")
SET(MKLDNN_SOURCES_DIR    ${THIRD_PARTY_PATH}/mkldnn)
SET(MKLDNN_INSTALL_ROOT   ${CMAKE_INSTALL_PREFIX})
IF(NOT "$ENV{HOME}" STREQUAL "/root")
    SET(MKLDNN_INSTALL_ROOT  "$ENV{HOME}")
ENDIF()

SET(MKLDNN_INSTALL_DIR    "${MKLDNN_INSTALL_ROOT}/opt/paddle/third_party/mkldnn")
SET(MKLDNN_INCLUDE_DIR    "${MKLDNN_INSTALL_DIR}/include" CACHE PATH "mkldnn include directory." FORCE)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

IF(WIN32)
    MESSAGE(WARNING "It is not supported compiling with mkldnn in windows Paddle yet."
      "Force WITH_MKLDNN=OFF")
    SET(WITH_MKLDNN OFF)
    return()
ELSE(WIN32)
    SET(MKLDNN_LIBRARY "${MKLDNN_INSTALL_DIR}/lib/libmkldnn.so" CACHE FILEPATH "mkldnn library." FORCE)
    MESSAGE(STATUS "Set ${MKLDNN_INSTALL_DIR}/lib to runtime path")
    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
    #SET(CMAKE_MACOSX_RPATH 1) # hold for MacOS
    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLDNN_INSTALL_DIR}/lib")
ENDIF(WIN32)

INCLUDE_DIRECTORIES(${MKLDNN_INCLUDE_DIR})

T
tensor-tang 已提交
46 47 48
IF(${CBLAS_PROVIDER} STREQUAL "MKLML")
    SET(MKLDNN_DEPENDS   ${MKLML_PROJECT})
    SET(MKLDNN_MKLROOT   ${MKLML_ROOT})
T
tensor-tang 已提交
49
    SET(MKLDNN_IOMP_LIB  ${MKLML_IOMP_LIB})
T
tensor-tang 已提交
50
    SET(MKLDNN_IOMP_DIR  ${MKLML_LIB_DIR})
T
tensor-tang 已提交
51
ENDIF()
52 53 54 55

ExternalProject_Add(
    ${MKLDNN_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
T
tensor-tang 已提交
56 57 58 59 60 61 62
    DEPENDS             ${MKLDNN_DEPENDS}
    GIT_REPOSITORY      "https://github.com/01org/mkl-dnn.git"
    GIT_TAG             "v0.9"
    PREFIX              ${MKLDNN_SOURCES_DIR}
    CONFIGURE_COMMAND   mkdir -p <SOURCE_DIR>/build
    BUILD_COMMAND       cd <SOURCE_DIR>/build
                        && cmake .. -DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL_DIR} -DMKLROOT=${MKLDNN_MKLROOT}
63 64
                        && $(MAKE)
    INSTALL_COMMAND     cd <SOURCE_DIR>/build && $(MAKE) install
T
tensor-tang 已提交
65
    UPDATE_COMMAND      ""
66 67
)

T
tensor-tang 已提交
68
ADD_LIBRARY(mkldnn SHARED IMPORTED GLOBAL)
69 70
SET_PROPERTY(TARGET mkldnn PROPERTY IMPORTED_LOCATION ${MKLDNN_LIBRARY})
ADD_DEPENDENCIES(mkldnn ${MKLDNN_PROJECT})
T
tensor-tang 已提交
71
MESSAGE(STATUS "Mkldnn library: ${MKLDNN_LIBRARY}")
72
LIST(APPEND external_project_dependencies mkldnn)