eigen.cmake 2.9 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
# update eigen to the commit id f612df27 on 03/16/2021
18
set(EIGEN_PREFIX_DIR ${THIRD_PARTY_PATH}/eigen3)
19
set(EIGEN_SOURCE_DIR ${THIRD_PARTY_PATH}/eigen3/src/extern_eigen3)
20
set(EIGEN_TAG f612df273689a19d25b45ca4f8269463207c4fee)
21
set(SOURCE_DIR ${PADDLE_SOURCE_DIR}/third_party/eigen3)
Z
Zhang Ting 已提交
22

23
if(WIN32)
24
  add_definitions(-DEIGEN_STRONG_INLINE=inline)
25
elseif(LINUX)
26 27
  if(WITH_ROCM)
    # For HIPCC Eigen::internal::device::numeric_limits is not EIGEN_DEVICE_FUNC
W
Wilber 已提交
28 29
    # which will cause compiler error of using __host__ funciont
    # in __host__ __device__
30
    file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/eigen/Meta.h native_src)
31
    file(TO_NATIVE_PATH ${SOURCE_DIR}/Eigen/src/Core/util/Meta.h native_dst)
32 33
    file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/eigen/TensorReductionGpu.h
         native_src1)
34 35 36
    file(TO_NATIVE_PATH
         ${SOURCE_DIR}/unsupported/Eigen/CXX11/src/Tensor/TensorReductionGpu.h
         native_dst1)
37 38 39
    set(EIGEN_PATCH_COMMAND cp ${native_src} ${native_dst} && cp ${native_src1}
                            ${native_dst1})
  endif()
40
endif()
41

R
risemeup1 已提交
42 43 44 45 46 47 48 49 50 51
if(CMAKE_COMPILER_IS_GNUCC)
  execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpfullversion -dumpversion
                  OUTPUT_VARIABLE GCC_VERSION)
  string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
  list(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
  list(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
  set(GCC_VERSION "${GCC_MAJOR}.${GCC_MINOR}")
  if(GCC_VERSION GREATER_EQUAL "12.0")
    file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/eigen/Complex.h.patch
         complex_header)
52
    # See: [Why calling some `git` commands before `patch`?]
R
risemeup1 已提交
53
    set(EIGEN_PATCH_COMMAND
54
        git checkout -- . && git checkout ${EIGEN_TAG} && patch -Nd
55
        ${SOURCE_DIR}/Eigen/src/Core/arch/SSE/ < ${complex_header})
R
risemeup1 已提交
56 57 58
  endif()
endif()

59
set(EIGEN_INCLUDE_DIR ${SOURCE_DIR})
60
include_directories(${EIGEN_INCLUDE_DIR})
61

62
ExternalProject_Add(
63
  extern_eigen3
64 65
  ${EXTERNAL_PROJECT_LOG_ARGS}
  SOURCE_DIR ${SOURCE_DIR}
66 67 68 69 70 71 72
  PREFIX ${EIGEN_PREFIX_DIR}
  UPDATE_COMMAND ""
  PATCH_COMMAND ${EIGEN_PATCH_COMMAND}
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND ""
  TEST_COMMAND "")
Q
qijun 已提交
73

74
add_library(eigen3 INTERFACE)
L
liaogang 已提交
75

L
liaogang 已提交
76
add_dependencies(eigen3 extern_eigen3)
W
Wilber 已提交
77 78 79 80 81

# sw not support thread_local semantic
if(WITH_SW)
  add_definitions(-DEIGEN_AVOID_THREAD_LOCAL)
endif()