mklml.cmake 3.1 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})

19
IF(WIN32 OR APPLE)
20
    MESSAGE(WARNING
21 22 23
        "Windows or Mac is not supported with MKLML in Paddle yet."
        "Force WITH_MKLML=OFF")
    SET(WITH_MKLML OFF CACHE STRING "Disable MKLML package in Windows and MacOS" FORCE)
T
update  
typhoonzero 已提交
24 25 26
    IF ((NOT ${WITH_MKLDNN}) AND (NOT ${WITH_MKLML}))
        SET(WITH_MKL OFF CACHE STRING "Disable MKL for later scripts" FORCE)
    ENDIF()
27 28 29
    return()
ENDIF()

T
tensor-tang 已提交
30 31 32
INCLUDE(ExternalProject)

SET(MKLML_PROJECT       "extern_mklml")
33 34 35
IF((NOT DEFINED MKLML_VER) OR (NOT DEFINED MKLML_URL))
  MESSAGE(STATUS "use pre defined download url")
  SET(MKLML_VER "mklml_lnx_2018.0.3.20180406" CACHE STRING "" FORCE)
36
  SET(MKLML_URL "http://paddlepaddledeps.cdn.bcebos.com/${MKLML_VER}.tgz" CACHE STRING "" FORCE)
37 38
ENDIF()
MESSAGE(STATUS "MKLML_VER: ${MKLML_VER}, MKLML_URL: ${MKLML_URL}")
39 40
SET(MKLML_SOURCE_DIR    "${THIRD_PARTY_PATH}/mklml")
SET(MKLML_DOWNLOAD_DIR  "${MKLML_SOURCE_DIR}/src/${MKLML_PROJECT}")
41 42
SET(MKLML_DST_DIR       "mklml")
SET(MKLML_INSTALL_ROOT  "${THIRD_PARTY_PATH}/install")
T
tensor-tang 已提交
43
SET(MKLML_INSTALL_DIR   ${MKLML_INSTALL_ROOT}/${MKLML_DST_DIR})
44
SET(MKLML_ROOT          ${MKLML_INSTALL_DIR})
T
tensor-tang 已提交
45 46 47 48
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)
49
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib")
T
tensor-tang 已提交
50 51 52

INCLUDE_DIRECTORIES(${MKLML_INC_DIR})

Y
Yi Wang 已提交
53 54 55
FILE(WRITE ${MKLML_DOWNLOAD_DIR}/CMakeLists.txt
  "PROJECT(MKLML)\n"
  "cmake_minimum_required(VERSION 3.0)\n"
L
Luo Tao 已提交
56
  "install(DIRECTORY ${MKLML_VER}/include ${MKLML_VER}/lib \n"
Y
Yi Wang 已提交
57
  "        DESTINATION ${MKLML_DST_DIR})\n")
58

T
tensor-tang 已提交
59 60 61
ExternalProject_Add(
    ${MKLML_PROJECT}
    ${EXTERNAL_PROJECT_LOG_ARGS}
62
    PREFIX                ${MKLML_SOURCE_DIR}
T
tensor-tang 已提交
63
    DOWNLOAD_DIR          ${MKLML_DOWNLOAD_DIR}
64 65
    DOWNLOAD_COMMAND      wget --no-check-certificate ${MKLML_URL} -c -q -O ${MKLML_VER}.tgz 
                          && tar zxf ${MKLML_VER}.tgz
T
tensor-tang 已提交
66 67
    DOWNLOAD_NO_PROGRESS  1
    UPDATE_COMMAND        ""
68
    CMAKE_ARGS            -DCMAKE_INSTALL_PREFIX=${MKLML_INSTALL_ROOT}
T
tensor-tang 已提交
69
    CMAKE_CACHE_ARGS      -DCMAKE_INSTALL_PREFIX:PATH=${MKLML_INSTALL_ROOT}
T
tensor-tang 已提交
70 71
)

T
tensor-tang 已提交
72 73
ADD_LIBRARY(mklml SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET mklml PROPERTY IMPORTED_LOCATION ${MKLML_LIB})
T
tensor-tang 已提交
74 75
ADD_DEPENDENCIES(mklml ${MKLML_PROJECT})
LIST(APPEND external_project_dependencies mklml)
76 77 78 79

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