mklml.cmake 2.7 KB
Newer Older
T
tensor-tang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 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_MKLML})
  return()
ENDIF(NOT ${WITH_MKLML})

INCLUDE(ExternalProject)

SET(MKLML_PROJECT       "extern_mklml")
SET(MKLML_VER           "mklml_lnx_2018.0.20170425")
SET(MKLML_URL           "https://github.com/01org/mkl-dnn/releases/download/v0.9/${MKLML_VER}.tgz")
24 25 26
SET(MKLML_SOURCE_DIR    "${THIRD_PARTY_PATH}/mklml")
SET(MKLML_DOWNLOAD_DIR  "${MKLML_SOURCE_DIR}/src/${MKLML_PROJECT}")
SET(MKLML_DST_DIR       "opt/paddle/third_party/mklml")
T
tensor-tang 已提交
27 28 29 30
SET(MKLML_INSTALL_ROOT  "${CMAKE_INSTALL_PREFIX}")
IF(NOT "$ENV{HOME}" STREQUAL "/root")
    SET(MKLML_INSTALL_ROOT  "$ENV{HOME}")
ENDIF()
T
tensor-tang 已提交
31

T
tensor-tang 已提交
32
SET(MKLML_INSTALL_DIR   ${MKLML_INSTALL_ROOT}/${MKLML_DST_DIR})
33
SET(MKLML_ROOT          ${MKLML_INSTALL_DIR}/${MKLML_VER})
T
tensor-tang 已提交
34 35 36 37
SET(MKLML_INC_DIR       ${MKLML_ROOT}/include)
SET(MKLML_LIB_DIR       ${MKLML_ROOT}/lib)
SET(MKLML_LIB           ${MKLML_LIB_DIR}/libmklml_intel.so)
SET(MKLML_IOMP_LIB      ${MKLML_LIB_DIR}/libiomp5.so)
38
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib")
T
tensor-tang 已提交
39 40 41

INCLUDE_DIRECTORIES(${MKLML_INC_DIR})

42 43 44 45 46 47
SET(mklml_cmakefile ${MKLML_DOWNLOAD_DIR}/CMakeLists.txt)
FILE(WRITE ${mklml_cmakefile} "PROJECT(MKLML)\n"
                              "cmake_minimum_required(VERSION 3.0)\n"
                              "install(DIRECTORY ${MKLML_VER}\n"
                              "        DESTINATION ${MKLML_DST_DIR})\n")

T
tensor-tang 已提交
48 49 50
ExternalProject_Add(
    ${MKLML_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
51
    PREFIX                ${MKLML_SOURCE_DIR}
T
tensor-tang 已提交
52 53
    DOWNLOAD_DIR          ${MKLML_DOWNLOAD_DIR}
    DOWNLOAD_COMMAND      wget --no-check-certificate -O ${MKLML_DOWNLOAD_DIR}/${MKLML_VER}.tgz ${MKLML_URL}
54
                          && tar -xzf ${MKLML_DOWNLOAD_DIR}/${MKLML_VER}.tgz
T
tensor-tang 已提交
55 56
    DOWNLOAD_NO_PROGRESS  1
    UPDATE_COMMAND        ""
T
tensor-tang 已提交
57 58
    CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${MKLML_INSTALL_ROOT} 
    CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${MKLML_INSTALL_ROOT}
T
tensor-tang 已提交
59 60
)

T
tensor-tang 已提交
61 62
ADD_LIBRARY(mklml SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET mklml PROPERTY IMPORTED_LOCATION ${MKLML_LIB})
T
tensor-tang 已提交
63 64
ADD_DEPENDENCIES(mklml ${MKLML_PROJECT})
LIST(APPEND external_project_dependencies mklml)