eigen.cmake 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 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.

15
include(ExternalProject)
Q
qijun 已提交
16

17
set(EIGEN_PREFIX_DIR ${THIRD_PARTY_PATH}/eigen3)
18 19 20
set(EIGEN_SOURCE_DIR ${THIRD_PARTY_PATH}/eigen3/src/extern_eigen3)
set(EIGEN_REPOSITORY https://github.com/eigenteam/eigen-git-mirror)
set(EIGEN_TAG        917060c364181f33a735dc023818d5a54f60e54c)
J
Jiabin Yang 已提交
21

22 23 24 25 26 27 28 29 30
# eigen on cuda9.1 missing header of math_funtions.hpp
# https://stackoverflow.com/questions/43113508/math-functions-hpp-not-found-when-using-cuda-with-eigen
if(WITH_AMD_GPU)
    set(EIGEN_REPOSITORY https://github.com/sabreshao/hipeigen.git)
    set(EIGEN_TAG        7cb2b6e5a4b4a1efe658abb215cd866c6fb2275e)
endif()

cache_third_party(extern_eigen3
    REPOSITORY    ${EIGEN_REPOSITORY}
31 32
    TAG           ${EIGEN_TAG}
    DIR           EIGEN_SOURCE_DIR)
33 34 35 36 37 38

if(WIN32)
    file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/eigen/Half.h native_src)
    file(TO_NATIVE_PATH ${EIGEN_SOURCE_DIR}/Eigen/src/Core/arch/CUDA/Half.h native_dst)
    set(EIGEN_PATCH_COMMAND copy ${native_src} ${native_dst} /Y)
endif()
39 40 41 42

set(EIGEN_INCLUDE_DIR ${EIGEN_SOURCE_DIR})
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIR})

43 44 45 46
if(WITH_AMD_GPU)
    ExternalProject_Add(
        extern_eigen3
        ${EXTERNAL_PROJECT_LOG_ARGS}
47
        ${SHALLOW_CLONE}
48
        "${EIGEN_DOWNLOAD_CMD}"
49 50 51
        PREFIX          ${EIGEN_PREFIX_DIR}
        SOURCE_DIR      ${EIGEN_SOURCE_DIR}
        UPDATE_COMMAND    ""
52
        PATCH_COMMAND   ${EIGEN_PATCH_COMMAND}
53 54 55 56 57 58 59 60 61
        CONFIGURE_COMMAND ""
        BUILD_COMMAND     ""
        INSTALL_COMMAND   ""
        TEST_COMMAND      ""
    )
else()
    ExternalProject_Add(
        extern_eigen3
        ${EXTERNAL_PROJECT_LOG_ARGS}
62
        ${SHALLOW_CLONE}
63 64 65 66
        "${EIGEN_DOWNLOAD_CMD}"
        PREFIX          ${EIGEN_PREFIX_DIR}
        SOURCE_DIR      ${EIGEN_SOURCE_DIR}
        UPDATE_COMMAND    ""
67
        PATCH_COMMAND   ${EIGEN_PATCH_COMMAND}
68 69 70 71 72 73
        CONFIGURE_COMMAND ""
        BUILD_COMMAND     ""
        INSTALL_COMMAND   ""
        TEST_COMMAND      ""
    )
endif()
Q
qijun 已提交
74

L
liaogang 已提交
75 76
if (${CMAKE_VERSION} VERSION_LESS "3.3.0")
    set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/eigen3_dummy.c)
77
    file(WRITE ${dummyfile} "const char *dummy_eigen3 = \"${dummyfile}\";")
L
liaogang 已提交
78 79 80 81
    add_library(eigen3 STATIC ${dummyfile})
else()
    add_library(eigen3 INTERFACE)
endif()
L
liaogang 已提交
82

L
liaogang 已提交
83
add_dependencies(eigen3 extern_eigen3)