mklml.cmake 3.6 KB
Newer Older
1
# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved.
T
tensor-tang 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
# 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})

P
peizhilin 已提交
19
IF(APPLE)
20
    MESSAGE(WARNING
P
peizhilin 已提交
21
        "Mac is not supported with MKLML in Paddle yet."
22 23 24 25 26
        "Force WITH_MKLML=OFF")
    SET(WITH_MKLML OFF CACHE STRING "Disable MKLML package in Windows and MacOS" FORCE)
    return()
ENDIF()

T
tensor-tang 已提交
27
INCLUDE(ExternalProject)
28 29
SET(MKLML_DST_DIR       "mklml")
SET(MKLML_INSTALL_ROOT  "${THIRD_PARTY_PATH}/install")
T
tensor-tang 已提交
30
SET(MKLML_INSTALL_DIR   ${MKLML_INSTALL_ROOT}/${MKLML_DST_DIR})
31
SET(MKLML_ROOT          ${MKLML_INSTALL_DIR})
T
tensor-tang 已提交
32 33
SET(MKLML_INC_DIR       ${MKLML_ROOT}/include)
SET(MKLML_LIB_DIR       ${MKLML_ROOT}/lib)
P
peizhilin 已提交
34 35 36 37 38 39 40 41 42 43 44
if(WIN32)
    SET(MKLML_LIB                 ${MKLML_LIB_DIR}/mklml.lib)
    SET(MKLML_IOMP_LIB            ${MKLML_LIB_DIR}/libiomp5md.lib)
    SET(MKLML_SHARED_LIB          ${MKLML_LIB_DIR}/mklml.dll)
    SET(MKLML_SHARED_IOMP_LIB     ${MKLML_LIB_DIR}/libiomp5md.dll)
else()
    SET(MKLML_LIB                 ${MKLML_LIB_DIR}/libmklml_intel.so)
    SET(MKLML_IOMP_LIB            ${MKLML_LIB_DIR}/libiomp5.so)
    SET(MKLML_SHARED_LIB          ${MKLML_LIB_DIR}/libmklml_intel.so)
    SET(MKLML_SHARED_IOMP_LIB     ${MKLML_LIB_DIR}/libiomp5.so)
endif()
45
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib")
T
tensor-tang 已提交
46

P
peizhilin 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59
if(WIN32)
    MESSAGE(WARNING
    "Please download the MKLML and and put it at " ${THIRD_PARTY_PATH}/install/mklml)
else()
    SET(MKLML_PROJECT       "extern_mklml")
    IF((NOT DEFINED MKLML_VER) OR (NOT DEFINED MKLML_URL))
      MESSAGE(STATUS "use pre defined download url")
      SET(MKLML_VER "mklml_lnx_2019.0.20180710" CACHE STRING "" FORCE)
      SET(MKLML_URL "http://paddlepaddledeps.cdn.bcebos.com/${MKLML_VER}.tgz" CACHE STRING "" FORCE)
    ENDIF()
    MESSAGE(STATUS "MKLML_VER: ${MKLML_VER}, MKLML_URL: ${MKLML_URL}")
    SET(MKLML_SOURCE_DIR    "${THIRD_PARTY_PATH}/mklml")
    SET(MKLML_DOWNLOAD_DIR  "${MKLML_SOURCE_DIR}/src/${MKLML_PROJECT}")
T
tensor-tang 已提交
60

P
peizhilin 已提交
61 62 63 64 65
    FILE(WRITE ${MKLML_DOWNLOAD_DIR}/CMakeLists.txt
      "PROJECT(MKLML)\n"
      "cmake_minimum_required(VERSION 3.0)\n"
      "install(DIRECTORY ${MKLML_VER}/include ${MKLML_VER}/lib \n"
      "        DESTINATION ${MKLML_DST_DIR})\n")
66

P
peizhilin 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    ExternalProject_Add(
        ${MKLML_PROJECT}
        ${EXTERNAL_PROJECT_LOG_ARGS}
        PREFIX                ${MKLML_SOURCE_DIR}
        DOWNLOAD_DIR          ${MKLML_DOWNLOAD_DIR}
        DOWNLOAD_COMMAND      wget --no-check-certificate ${MKLML_URL} -c -q -O ${MKLML_VER}.tgz
                              && tar zxf ${MKLML_VER}.tgz
        DOWNLOAD_NO_PROGRESS  1
        UPDATE_COMMAND        ""
        CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${MKLML_INSTALL_ROOT}
        CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${MKLML_INSTALL_ROOT}
    )
endif()


INCLUDE_DIRECTORIES(${MKLML_INC_DIR})
T
tensor-tang 已提交
83

T
tensor-tang 已提交
84 85
ADD_LIBRARY(mklml SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET mklml PROPERTY IMPORTED_LOCATION ${MKLML_LIB})
P
peizhilin 已提交
86 87 88
if(NOT WIN32)
    ADD_DEPENDENCIES(mklml ${MKLML_PROJECT})
endif()
T
tensor-tang 已提交
89
LIST(APPEND external_project_dependencies mklml)
90 91 92 93

IF(WITH_C_API)
  INSTALL(FILES ${MKLML_LIB} ${MKLML_IOMP_LIB} DESTINATION lib)
ENDIF()