mklml.cmake 3.91 KB
Newer Older
yuguo960516yuguo's avatar
yuguo960516yuguo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (c) 2017 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

include(ExternalProject)
set(MKLML_INSTALL_DIR ${THIRD_PARTY_PATH}/install/mklml)
set(MKLML_INC_DIR ${MKLML_INSTALL_DIR}/include)
set(MKLML_LIB_DIR ${MKLML_INSTALL_DIR}/lib)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_LIB_DIR}")
“yuguo”'s avatar
2.5  
“yuguo” committed
20
21
set(MKLML_DOWNLOAD_DIR
    ${PADDLE_SOURCE_DIR}/third_party/mklml/${CMAKE_SYSTEM_NAME})
yuguo960516yuguo's avatar
yuguo960516yuguo committed
22
23

if(WIN32)
“yuguo”'s avatar
2.5  
“yuguo” committed
24
25
  set(MKLML_FILE
      "mklml_win_2019.0.5.20190502.zip"
yuguo960516yuguo's avatar
yuguo960516yuguo committed
26
27
      CACHE STRING "" FORCE)
  set(MKLML_URL
“yuguo”'s avatar
2.5  
“yuguo” committed
28
      "https://paddlepaddledeps.bj.bcebos.com/${MKLML_FILE}"
yuguo960516yuguo's avatar
yuguo960516yuguo committed
29
30
31
32
33
34
35
36
37
38
      CACHE STRING "" FORCE)
  set(MKLML_URL_MD5 ff8c5237570f03eea37377ccfc95a08a)
  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()
  #TODO(intel-huying):
  #  Now enable csrmm function in mklml library temporarily,
  #  it will be updated as offical version later.
“yuguo”'s avatar
2.5  
“yuguo” committed
39
40
  set(MKLML_FILE
      "csrmm_mklml_lnx_2019.0.5.tgz"
yuguo960516yuguo's avatar
yuguo960516yuguo committed
41
42
      CACHE STRING "" FORCE)
  set(MKLML_URL
“yuguo”'s avatar
2.5  
“yuguo” committed
43
      "http://paddlepaddledeps.bj.bcebos.com/${MKLML_FILE}"
yuguo960516yuguo's avatar
yuguo960516yuguo committed
44
45
46
47
48
49
50
51
52
      CACHE STRING "" FORCE)
  set(MKLML_URL_MD5 bc6a7faea6a2a9ad31752386f3ae87da)
  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()

set(MKLML_PROJECT "extern_mklml")
“yuguo”'s avatar
2.5  
“yuguo” committed
53
message(STATUS "MKLML_FILE: ${MKLML_FILE}, MKLML_URL: ${MKLML_URL}")
yuguo960516yuguo's avatar
yuguo960516yuguo committed
54
set(MKLML_PREFIX_DIR ${THIRD_PARTY_PATH}/mklml)
“yuguo”'s avatar
2.5  
“yuguo” committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

function(download_mklml)
  message(
    STATUS "Downloading ${MKLML_URL} to ${MKLML_DOWNLOAD_DIR}/${MKLML_FILE}")
  # NOTE: If the version is updated, consider emptying the folder; maybe add timeout
  file(
    DOWNLOAD ${MKLML_URL} ${MKLML_DOWNLOAD_DIR}/${MKLML_FILE}
    EXPECTED_MD5 ${MKLML_URL_MD5}
    STATUS ERR)
  if(ERR EQUAL 0)
    message(STATUS "Download ${MKLML_FILE} success")
  else()
    message(
      FATAL_ERROR
        "Download failed, error: ${ERR}\n You can try downloading ${MKLML_FILE} again"
    )
  endif()
endfunction()

# Download and check mklml.
if(EXISTS ${MKLML_DOWNLOAD_DIR}/${MKLML_FILE})
  file(MD5 ${MKLML_DOWNLOAD_DIR}/${MKLML_FILE} MKLML_MD5)
  if(NOT MKLML_MD5 STREQUAL MKLML_URL_MD5)
    # clean build file
    file(REMOVE_RECURSE ${MKLML_PREFIX_DIR})
    file(REMOVE_RECURSE ${MKLML_INSTALL_DIR})
    download_mklml()
  endif()
else()
  download_mklml()
endif()
yuguo960516yuguo's avatar
yuguo960516yuguo committed
86
87
88
89
90
91
92
93
94

# Ninja Generator can not establish the correct dependency relationship
# between the imported library with target, the product file
# in the ExternalProject need to be specified manually, please refer to
# https://stackoverflow.com/questions/54866067/cmake-and-ninja-missing-and-no-known-rule-to-make-it
# It is the same to all other ExternalProject.
ExternalProject_Add(
  ${MKLML_PROJECT}
  ${EXTERNAL_PROJECT_LOG_ARGS}
“yuguo”'s avatar
2.5  
“yuguo” committed
95
  URL ${MKLML_DOWNLOAD_DIR}/${MKLML_FILE}
yuguo960516yuguo's avatar
yuguo960516yuguo committed
96
  URL_MD5 ${MKLML_URL_MD5}
“yuguo”'s avatar
2.5  
“yuguo” committed
97
98
  DOWNLOAD_DIR ${MKLML_DOWNLOAD_DIR}
  SOURCE_DIR ${MKLML_INSTALL_DIR}
yuguo960516yuguo's avatar
yuguo960516yuguo committed
99
100
101
102
  PREFIX ${MKLML_PREFIX_DIR}
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  UPDATE_COMMAND ""
“yuguo”'s avatar
2.5  
“yuguo” committed
103
  INSTALL_COMMAND ""
yuguo960516yuguo's avatar
yuguo960516yuguo committed
104
105
106
107
108
109
110
111
  BUILD_BYPRODUCTS ${MKLML_LIB}
  BUILD_BYPRODUCTS ${MKLML_IOMP_LIB})

include_directories(${MKLML_INC_DIR})

add_library(mklml SHARED IMPORTED GLOBAL)
set_property(TARGET mklml PROPERTY IMPORTED_LOCATION ${MKLML_LIB})
add_dependencies(mklml ${MKLML_PROJECT})