From f1922b6dac4a9c18b07c26658cea08db80489278 Mon Sep 17 00:00:00 2001 From: "C. Antonio Sanchez" Date: Sun, 16 Feb 2025 11:22:08 -0800 Subject: [PATCH] Update cmake configuration from master --- CMakeLists.txt | 1175 ++++++++++++++------------- cmake/Eigen3Config.cmake.in | 4 +- cmake/EigenConfigureTesting.cmake | 2 +- cmake/EigenSmokeTestList.cmake | 7 +- cmake/EigenTesting.cmake | 105 +-- cmake/FindCLANG_FORMAT.cmake | 61 ++ cmake/FindComputeCpp.cmake | 2 +- cmake/FindDPCPP.cmake | 62 ++ cmake/SyclConfigureTesting.cmake | 64 ++ doc/examples/CMakeLists.txt | 7 +- doc/snippets/CMakeLists.txt | 1 + doc/special_examples/CMakeLists.txt | 4 +- lapack/CMakeLists.txt | 1 + test/CMakeLists.txt | 71 +- unsupported/CMakeLists.txt | 2 +- unsupported/Eigen/CMakeLists.txt | 4 +- unsupported/test/CMakeLists.txt | 189 ++--- 17 files changed, 984 insertions(+), 777 deletions(-) create mode 100644 cmake/FindCLANG_FORMAT.cmake create mode 100644 cmake/FindDPCPP.cmake create mode 100644 cmake/SyclConfigureTesting.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ac8042b18..348e0a4cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,37 @@ -# cmake_minimum_require must be the first command of the file -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10.0) + +#============================================================================== +# CMake Policy issues. +#============================================================================== +# Allow overriding options in a parent project via `set` before including Eigen. +if (POLICY CMP0077) + cmake_policy (SET CMP0077 NEW) +endif (POLICY CMP0077) + +# NOTE Remove setting the policy once the minimum required CMake version is +# increased to at least 3.15. Retain enabling the export to package registry. +if (POLICY CMP0090) + # The export command does not populate package registry by default + cmake_policy (SET CMP0090 NEW) + # Unless otherwise specified, always export to package registry to ensure + # backwards compatibility. + if (NOT DEFINED CMAKE_EXPORT_PACKAGE_REGISTRY) + set (CMAKE_EXPORT_PACKAGE_REGISTRY ON) + endif (NOT DEFINED CMAKE_EXPORT_PACKAGE_REGISTRY) +endif (POLICY CMP0090) + +# Disable warning about find_package(CUDA). +# CUDA language support is lacking for clang as the CUDA compiler +# until at least cmake version 3.18. Even then, there seems to be +# issues on Windows+Ninja in passing build flags. Continue using +# the "old" way for now. +if (POLICY CMP0146) + cmake_policy(SET CMP0146 OLD) +endif () + +#============================================================================== +# CMake Project. +#============================================================================== project(Eigen3) @@ -7,36 +39,63 @@ project(Eigen3) # PROJECT_IS_TOP_LEVEL is defined then by default if(CMAKE_VERSION VERSION_LESS 3.21.0) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(PROJECT_IS_TOP_LEVEL TRUE) + set(PROJECT_IS_TOP_LEVEL ON) else() - set(PROJECT_IS_TOP_LEVEL FALSE) + set(PROJECT_IS_TOP_LEVEL OFF) endif() endif() -# guard against in-source builds +#============================================================================== +# Build ON/OFF Settings. +#============================================================================== +# Determine if we should build tests. +include(CMakeDependentOption) +cmake_dependent_option(BUILD_TESTING "Enable creation of tests." ON "PROJECT_IS_TOP_LEVEL" OFF) +option(EIGEN_BUILD_TESTING "Enable creation of Eigen tests." ${BUILD_TESTING}) +option(EIGEN_LEAVE_TEST_IN_ALL_TARGET "Leaves tests in the all target, needed by ctest for automatic building." OFF) -if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ") +# Determine if we should build BLAS/LAPACK implementations. +option(EIGEN_BUILD_BLAS "Toggles the building of the Eigen Blas library" ${PROJECT_IS_TOP_LEVEL}) +option(EIGEN_BUILD_LAPACK "Toggles the building of the included Eigen LAPACK library" ${PROJECT_IS_TOP_LEVEL}) +if (EIGEN_BUILD_BLAS OR EIGEN_BUILD_LAPACK) + # BLAS and LAPACK currently need a fortran compiler. + include(CMakeDetermineFortranCompiler) + if (NOT CMAKE_Fortran_COMPILER) + set(EIGEN_BUILD_BLAS OFF) + set(EIGEN_BUILD_LAPACK OFF) + else() + # Determine if we should build shared libraries for BLAS/LAPACK on this platform. + get_cmake_property(EIGEN_BUILD_SHARED_LIBS TARGET_SUPPORTS_SHARED_LIBS) + endif() endif() +option(EIGEN_BUILD_BTL "Build benchmark suite" OFF) +option(EIGEN_BUILD_SPBENCH "Build sparse benchmark suite" OFF) +# Avoid building docs if included from another project. +# Building documentation requires creating and running executables on the host +# platform. We shouldn't do this if cross-compiling. +if (PROJECT_IS_TOP_LEVEL AND NOT CMAKE_CROSSCOMPILING) + set(EIGEN_BUILD_DOC_DEFAULT ON) +endif() +option(EIGEN_BUILD_DOC "Enable creation of Eigen documentation" ${EIGEN_BUILD_DOC_DEFAULT}) -# Alias Eigen_*_DIR to Eigen3_*_DIR: +option(EIGEN_BUILD_DEMOS "Toggles the building of the Eigen demos" ${PROJECT_IS_TOP_LEVEL}) -set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR}) -set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR}) +# Disable pkgconfig only for native Windows builds +if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) + option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ${PROJECT_IS_TOP_LEVEL}) +endif() +option(EIGEN_BUILD_CMAKE_PACKAGE "Enables the creation of EigenConfig.cmake and related files" ${PROJECT_IS_TOP_LEVEL}) -# guard against bad build-type strings - -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") +if (EIGEN_BUILD_TESTING OR EIGEN_BUILD_BLAS OR EIGEN_BUILD_LAPACK OR EIGEN_BUILT_BTL OR EIGEN_BUILD_BTL OR EIGEN_BUILD_SPBENCH OR EIGEN_BUILD_DOC OR EIGEN_BUILD_DEMOS) + set(EIGEN_IS_BUILDING_ ON) endif() +#============================================================================== +# Version Info. +#============================================================================== -############################################################################# -# retrieve version information # -############################################################################# - -# automatically parse the version number +# Automatically parse the version number from header files. file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header) string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}") set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}") @@ -46,11 +105,11 @@ string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_ set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}") set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}) -# if we are not in a git clone +# If we are in a git repo, extract a changeset. if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git) # if the git program is absent or this will leave the EIGEN_GIT_REVNUM string empty, # but won't stop CMake. - execute_process(COMMAND git ls-remote --refs -q ${CMAKE_SOURCE_DIR} HEAD OUTPUT_VARIABLE EIGEN_GIT_OUTPUT) + execute_process(COMMAND git ls-remote -q ${CMAKE_SOURCE_DIR} HEAD OUTPUT_VARIABLE EIGEN_GIT_OUTPUT) endif() # extract the git rev number from the git output... @@ -65,391 +124,19 @@ else() set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}") endif() -include(CheckCXXCompilerFlag) +#============================================================================== +# Install Path Configuration. +#============================================================================== + +# Unconditionally allow install of targets to support nested dependency +# installations. +# +# Note: projects that depend on Eigen should _probably_ exclude installing +# Eigen by default (e.g. by using EXCLUDE_FROM_ALL when using +# FetchContent_Declare or add_subdirectory) to avoid overwriting a previous +# installation. + include(GNUInstallDirs) -include(CMakeDependentOption) - -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) - - -option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF) - - -macro(ei_add_cxx_compiler_flag FLAG) - string(REGEX REPLACE "-" "" SFLAG1 ${FLAG}) - string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1}) - check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG}) - if(COMPILER_SUPPORT_${SFLAG}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") - endif() -endmacro() - -check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11) - -if(EIGEN_TEST_CXX11) - set(CMAKE_CXX_STANDARD 11) - set(CMAKE_CXX_EXTENSIONS OFF) - if(EIGEN_COMPILER_SUPPORT_CPP11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() -else() - #set(CMAKE_CXX_STANDARD 03) - #set(CMAKE_CXX_EXTENSIONS OFF) - ei_add_cxx_compiler_flag("-std=c++03") -endif() - -function(ei_maybe_separate_arguments variable mode args) - # Use separate_arguments if the input is a single string containing a space. - # Otherwise, if it is already a list or doesn't have a space, just propagate - # the original value. This is to better support multi-argument lists. - list(LENGTH args list_length) - if (${list_length} EQUAL 1) - string(FIND "${args}" " " has_space) - if (${has_space} GREATER -1) - separate_arguments(args ${mode} "${args}") - endif() - endif() - set(${variable} ${args} PARENT_SCOPE) -endfunction(ei_maybe_separate_arguments) - -# Determine if we should build shared libraries on this platform. -get_cmake_property(EIGEN_BUILD_SHARED_LIBS TARGET_SUPPORTS_SHARED_LIBS) - -############################################################################# -# find how to link to the standard libraries # -############################################################################# - -find_package(StandardMathLibrary) - - -set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.") -set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.") - -# Convert space-separated arguments into CMake lists for downstream consumption. -ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_LINKER_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_LINKER_FLAGS}") -ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_CXX_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_CXX_FLAGS}") - -set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "") - -if(NOT STANDARD_MATH_LIBRARY_FOUND) - - message(FATAL_ERROR - "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.") - -else() - if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) - set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}") - else() - set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}") - endif() -endif() - -if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) - message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}") -else() - message(STATUS "Standard libraries to link to explicitly: none") -endif() - -option(EIGEN_BUILD_BTL "Build benchmark suite" OFF) -option(EIGEN_BUILD_SPBENCH "Build sparse benchmark suite" OFF) - -# Disable pkgconfig only for native Windows builds -if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - option(EIGEN_BUILD_PKGCONFIG "Build pkg-config .pc file for Eigen" ON) -endif() - -set(CMAKE_INCLUDE_CURRENT_DIR OFF) - -option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON) - -option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF) -if(EIGEN_DEFAULT_TO_ROW_MAJOR) - add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR") -endif() - -set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320") - -if(NOT MSVC) - # We assume that other compilers are partly compatible with GNUCC - - # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag - # adding -Werror turns such warnings into errors - check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR) - if(COMPILER_SUPPORT_WERROR) - set(CMAKE_REQUIRED_FLAGS "-Werror") - endif() - ei_add_cxx_compiler_flag("-pedantic") - ei_add_cxx_compiler_flag("-Wall") - ei_add_cxx_compiler_flag("-Wextra") - #ei_add_cxx_compiler_flag("-Weverything") # clang - - ei_add_cxx_compiler_flag("-Wundef") - ei_add_cxx_compiler_flag("-Wcast-align") - ei_add_cxx_compiler_flag("-Wchar-subscripts") - ei_add_cxx_compiler_flag("-Wnon-virtual-dtor") - ei_add_cxx_compiler_flag("-Wunused-local-typedefs") - ei_add_cxx_compiler_flag("-Wpointer-arith") - ei_add_cxx_compiler_flag("-Wwrite-strings") - ei_add_cxx_compiler_flag("-Wformat-security") - ei_add_cxx_compiler_flag("-Wshorten-64-to-32") - ei_add_cxx_compiler_flag("-Wlogical-op") - ei_add_cxx_compiler_flag("-Wenum-conversion") - ei_add_cxx_compiler_flag("-Wc++11-extensions") - ei_add_cxx_compiler_flag("-Wdouble-promotion") -# ei_add_cxx_compiler_flag("-Wconversion") - - ei_add_cxx_compiler_flag("-Wshadow") - - ei_add_cxx_compiler_flag("-Wno-psabi") - ei_add_cxx_compiler_flag("-Wno-variadic-macros") - ei_add_cxx_compiler_flag("-Wno-long-long") - - ei_add_cxx_compiler_flag("-fno-check-new") - ei_add_cxx_compiler_flag("-fno-common") - ei_add_cxx_compiler_flag("-fstrict-aliasing") - ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark - ei_add_cxx_compiler_flag("-wd2304") # disable ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor - - - # The -ansi flag must be added last, otherwise it is also used as a linker flag by check_cxx_compiler_flag making it fails - # Moreover we should not set both -strict-ansi and -ansi - check_cxx_compiler_flag("-strict-ansi" COMPILER_SUPPORT_STRICTANSI) - ei_add_cxx_compiler_flag("-Qunused-arguments") # disable clang warning: argument unused during compilation: '-ansi' - - if(COMPILER_SUPPORT_STRICTANSI) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -strict-ansi") - else() - ei_add_cxx_compiler_flag("-ansi") - endif() - - if(ANDROID_NDK) - ei_add_cxx_compiler_flag("-pie") - ei_add_cxx_compiler_flag("-fPIE") - endif() - - set(CMAKE_REQUIRED_FLAGS "") - - option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF) - if(EIGEN_TEST_SSE2) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") - message(STATUS "Enabling SSE2 in tests/examples") - endif() - - option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF) - if(EIGEN_TEST_SSE3) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3") - message(STATUS "Enabling SSE3 in tests/examples") - endif() - - option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF) - if(EIGEN_TEST_SSSE3) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3") - message(STATUS "Enabling SSSE3 in tests/examples") - endif() - - option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF) - if(EIGEN_TEST_SSE4_1) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") - message(STATUS "Enabling SSE4.1 in tests/examples") - endif() - - option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF) - if(EIGEN_TEST_SSE4_2) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2") - message(STATUS "Enabling SSE4.2 in tests/examples") - endif() - - option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF) - if(EIGEN_TEST_AVX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") - message(STATUS "Enabling AVX in tests/examples") - endif() - - option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF) - if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma") - message(STATUS "Enabling FMA in tests/examples") - endif() - - option(EIGEN_TEST_AVX2 "Enable/Disable AVX2 in tests/examples" OFF) - if(EIGEN_TEST_AVX2) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma") - message(STATUS "Enabling AVX2 in tests/examples") - endif() - - option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF) - if(EIGEN_TEST_AVX512) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mfma") - message(STATUS "Enabling AVX512 in tests/examples") - endif() - - option(EIGEN_TEST_AVX512DQ "Enable/Disable AVX512DQ in tests/examples" OFF) - if(EIGEN_TEST_AVX512DQ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512dq -mfma") - message(STATUS "Enabling AVX512DQ in tests/examples") - endif() - - option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF) - if(EIGEN_TEST_F16C) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c") - message(STATUS "Enabling F16C in tests/examples") - endif() - - option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF) - if(EIGEN_TEST_ALTIVEC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec") - message(STATUS "Enabling AltiVec in tests/examples") - endif() - - option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF) - if(EIGEN_TEST_VSX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx") - message(STATUS "Enabling VSX in tests/examples") - endif() - - option(EIGEN_TEST_MSA "Enable/Disable MSA in tests/examples" OFF) - if(EIGEN_TEST_MSA) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmsa") - message(STATUS "Enabling MSA in tests/examples") - endif() - - option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF) - if(EIGEN_TEST_NEON) - if(EIGEN_TEST_FMA) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon") - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard") - message(STATUS "Enabling NEON in tests/examples") - endif() - - option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF) - if(EIGEN_TEST_NEON64) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - message(STATUS "Enabling NEON in tests/examples") - endif() - - option(EIGEN_TEST_Z13 "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF) - if(EIGEN_TEST_Z13) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector") - message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples") - endif() - - option(EIGEN_TEST_Z14 "Enable/Disable S390X(zEC14) ZVECTOR in tests/examples" OFF) - if(EIGEN_TEST_Z14) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z14 -mzvector") - message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples") - endif() - - check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP) - if(COMPILER_SUPPORT_OPENMP) - option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF) - if(EIGEN_TEST_OPENMP) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") - message(STATUS "Enabling OpenMP in tests/examples") - endif() - endif() - -else() - - # C4127 - conditional expression is constant - # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively) - # We can disable this warning in the unit tests since it is clear that it occurs - # because we are oftentimes returning objects that have a destructor or may - # throw exceptions - in particular in the unit tests we are throwing extra many - # exceptions to cover indexing errors. - # C4505 - unreferenced local function has been removed (impossible to deactivate selectively) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714") - - # replace all /Wx by /W4 - string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - - check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP) - if(COMPILER_SUPPORT_OPENMP) - option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF) - if(EIGEN_TEST_OPENMP) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") - message(STATUS "Enabling OpenMP in tests/examples") - endif() - endif() - - option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF) - if(EIGEN_TEST_SSE2) - if(NOT CMAKE_CL_64) - # arch is not supported on 64 bit systems, SSE is enabled automatically. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2") - endif() - message(STATUS "Enabling SSE2 in tests/examples") - endif() - - option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF) - if(EIGEN_TEST_AVX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX") - message(STATUS "Enabling AVX in tests/examples") - endif() - - option(EIGEN_TEST_FMA "Enable/Disable FMA/AVX2 in tests/examples" OFF) - option(EIGEN_TEST_AVX2 "Enable/Disable FMA/AVX2 in tests/examples" OFF) - if((EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON) OR EIGEN_TEST_AVX2) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2") - message(STATUS "Enabling FMA/AVX2 in tests/examples") - endif() - - option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF) - option(EIGEN_TEST_AVX512DQ "Enable/Disable AVX512DQ in tests/examples" OFF) - if(EIGEN_TEST_AVX512 OR EIGEN_TEST_AVX512DQ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512") - message(STATUS "Enabling AVX512 in tests/examples") - endif() - -endif() - -option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF) -option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF) -option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF) - -if(EIGEN_TEST_X87) - set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON) - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387") - message(STATUS "Forcing use of x87 instructions in tests/examples") - else() - message(STATUS "EIGEN_TEST_X87 ignored on your compiler") - endif() -endif() - -if(EIGEN_TEST_32BIT) - if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") - message(STATUS "Forcing generation of 32-bit code in tests/examples") - else() - message(STATUS "EIGEN_TEST_32BIT ignored on your compiler") - endif() -endif() - -if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) - add_definitions(-DEIGEN_DONT_VECTORIZE=1) - message(STATUS "Disabling vectorization in tests/examples") -endif() - -option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF) -if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT) - add_definitions(-DEIGEN_DONT_ALIGN=1) - message(STATUS "Disabling alignment in tests/examples") -endif() - -option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF) -if(EIGEN_TEST_NO_EXCEPTIONS) - ei_add_cxx_compiler_flag("-fno-exceptions") - message(STATUS "Disabling exceptions in tests/examples") -endif() - -set(EIGEN_CUDA_CXX_FLAGS "" CACHE STRING "Additional flags to pass to the cuda compiler.") -set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture(s) to target when compiling CUDA code") - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - # Backward compatibility support for EIGEN_INCLUDE_INSTALL_DIR if(EIGEN_INCLUDE_INSTALL_DIR) message(WARNING "EIGEN_INCLUDE_INSTALL_DIR is deprecated. Use INCLUDE_INSTALL_DIR instead.") @@ -480,16 +167,33 @@ foreach(var INCLUDE_INSTALL_DIR CMAKEPACKAGE_INSTALL_DIR PKGCONFIG_INSTALL_DIR) endif() endforeach() -# similar to set_target_properties but append the property instead of overwriting it -macro(ei_add_target_property target prop value) +#============================================================================== +# Eigen Library. +#============================================================================== - get_target_property(previous ${target} ${prop}) - # if the property wasn't previously set, ${previous} is now "previous-NOTFOUND" which cmake allows catching with plain if() - if(NOT previous) - set(previous "") - endif() - set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}") -endmacro() +set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} ) +set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} ) +set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} ) +set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} ) + +# Alias Eigen_*_DIR to Eigen3_*_DIR: +set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR}) +set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR}) + +# Imported target support +add_library (eigen INTERFACE) +add_library (Eigen3::Eigen ALIAS eigen) +target_include_directories (eigen INTERFACE + $ + $ +) + +# Export as title case Eigen +set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen) + +#============================================================================== +# Install Rule Configuration. +#============================================================================== install(FILES signature_of_eigen3_matrix_library @@ -499,80 +203,517 @@ install(FILES if(EIGEN_BUILD_PKGCONFIG) configure_file(eigen3.pc.in eigen3.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc - DESTINATION ${PKGCONFIG_INSTALL_DIR} - ) + DESTINATION ${PKGCONFIG_INSTALL_DIR}) endif() install(DIRECTORY Eigen DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel) +install(TARGETS eigen EXPORT Eigen3Targets) -option(EIGEN_BUILD_DOC "Enable creation of Eigen documentation" ON) -if(EIGEN_BUILD_DOC) - add_subdirectory(doc EXCLUDE_FROM_ALL) +if(EIGEN_BUILD_CMAKE_PACKAGE) + include (CMakePackageConfigHelpers) + configure_package_config_file ( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake + INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} + NO_SET_AND_CHECK_MACRO # Eigen does not provide legacy style defines + NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components + ) + + # NOTE Remove the first code path once the minimum required CMake version is + # bumped to 3.14 or above. + if (CMAKE_VERSION VERSION_LESS 3.14) + # Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does + # not depend on architecture specific settings or libraries. More + # specifically, an Eigen3Config.cmake generated from a 64 bit target can be + # used for 32 bit targets as well (and vice versa). + set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) + unset (CMAKE_SIZEOF_VOID_P) + write_basic_package_version_file (Eigen3ConfigVersion.cmake + VERSION ${EIGEN_VERSION_NUMBER} + COMPATIBILITY SameMajorVersion) + set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P}) + else (CMAKE_VERSION VERSION_LESS 3.14) + write_basic_package_version_file (Eigen3ConfigVersion.cmake + VERSION ${EIGEN_VERSION_NUMBER} + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT) + endif (CMAKE_VERSION VERSION_LESS 3.14) + + # The Eigen target will be located in the Eigen3 namespace. Other CMake + # targets can refer to it using Eigen3::Eigen. + export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake) + # Export Eigen3 package to CMake registry such that it can be easily found by + # CMake even if it has not been installed to a standard directory. + export (PACKAGE Eigen3) + + install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}) + + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake + DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}) + + # Add uninstall target + if(NOT TARGET uninstall) + add_custom_target ( uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake) + endif() endif() +#============================================================================== +# General Build Configuration. +#============================================================================== + +# Guard against in-source builds +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ") +endif() + +# Guard against bad build-type strings +if (PROJECT_IS_TOP_LEVEL AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +# Only try to figure out how to link the math library if we are building something. +# Otherwise, let the parent project deal with dependencies. +if (EIGEN_IS_BUILDING_) + # Use Eigen's cmake files. + set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) + + set(CMAKE_INCLUDE_CURRENT_DIR OFF) + + find_package(StandardMathLibrary) + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "") + if(NOT STANDARD_MATH_LIBRARY_FOUND) + message(FATAL_ERROR + "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.") + else() + if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}") + else() + set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}") + endif() + endif() + if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) + message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}") + else() + message(STATUS "Standard libraries to link to explicitly: none") + endif() + + # Default tests/examples/libraries to row-major. + option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF) + if(EIGEN_DEFAULT_TO_ROW_MAJOR) + add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR") + endif() +endif() + +#============================================================================== +# Test Configuration. +#============================================================================== + +if (EIGEN_BUILD_TESTING) + function(ei_maybe_separate_arguments variable mode args) + # Use separate_arguments if the input is a single string containing a space. + # Otherwise, if it is already a list or doesn't have a space, just propagate + # the original value. This is to better support multi-argument lists. + list(LENGTH args list_length) + if (${list_length} EQUAL 1) + string(FIND "${args}" " " has_space) + if (${has_space} GREATER -1) + separate_arguments(args ${mode} "${args}") + endif() + endif() + set(${variable} ${args} PARENT_SCOPE) + endfunction(ei_maybe_separate_arguments) + + include(CheckCXXCompilerFlag) + macro(ei_add_cxx_compiler_flag FLAG) + string(REGEX REPLACE "-" "" SFLAG1 ${FLAG}) + string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1}) + check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG}) + if(COMPILER_SUPPORT_${SFLAG}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") + endif() + endmacro() + + check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11) + + option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." EIGEN_COMPILER_SUPPORT_CPP11) + if(EIGEN_TEST_CXX11) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_EXTENSIONS OFF) + if(EIGEN_COMPILER_SUPPORT_CPP11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + else() + ei_add_cxx_compiler_flag("-std=c++03") + endif() + + set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.") + set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.") + # Convert space-separated arguments into CMake lists for downstream consumption. + ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_LINKER_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_LINKER_FLAGS}") + ei_maybe_separate_arguments(EIGEN_TEST_CUSTOM_CXX_FLAGS NATIVE_COMMAND "${EIGEN_TEST_CUSTOM_CXX_FLAGS}") + + option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON) + set(EIGEN_TEST_MAX_SIZE "320" CACHE STRING "Maximal matrix/vector size, default is 320") + + # Flags for tests. + if(NOT MSVC) + # We assume that other compilers are partly compatible with GNUCC + + # clang outputs some warnings for unknown flags that are not caught by check_cxx_compiler_flag + # adding -Werror turns such warnings into errors + check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR) + if(COMPILER_SUPPORT_WERROR) + set(CMAKE_REQUIRED_FLAGS "-Werror") + endif() + ei_add_cxx_compiler_flag("-pedantic") + ei_add_cxx_compiler_flag("-Wall") + ei_add_cxx_compiler_flag("-Wextra") + # ei_add_cxx_compiler_flag("-Weverything") # clang + ei_add_cxx_compiler_flag("-Wundef") + ei_add_cxx_compiler_flag("-Wcast-align") + ei_add_cxx_compiler_flag("-Wchar-subscripts") + ei_add_cxx_compiler_flag("-Wnon-virtual-dtor") + ei_add_cxx_compiler_flag("-Wunused-local-typedefs") + ei_add_cxx_compiler_flag("-Wpointer-arith") + ei_add_cxx_compiler_flag("-Wwrite-strings") + ei_add_cxx_compiler_flag("-Wformat-security") + ei_add_cxx_compiler_flag("-Wshorten-64-to-32") + ei_add_cxx_compiler_flag("-Wlogical-op") + ei_add_cxx_compiler_flag("-Wenum-conversion") + ei_add_cxx_compiler_flag("-Wc++11-extensions") + ei_add_cxx_compiler_flag("-Wdouble-promotion") + # ei_add_cxx_compiler_flag("-Wconversion") + ei_add_cxx_compiler_flag("-Wshadow") + ei_add_cxx_compiler_flag("-Wno-psabi") + ei_add_cxx_compiler_flag("-Wno-variadic-macros") + ei_add_cxx_compiler_flag("-Wno-long-long") + ei_add_cxx_compiler_flag("-fno-check-new") + ei_add_cxx_compiler_flag("-fno-common") + ei_add_cxx_compiler_flag("-fstrict-aliasing") + ei_add_cxx_compiler_flag("-wd981") # disable ICC's "operands are evaluated in unspecified order" remark + ei_add_cxx_compiler_flag("-wd2304") # disable ICC's "warning #2304: non-explicit constructor with single argument may cause implicit type conversion" produced by -Wnon-virtual-dtor + + if(ANDROID_NDK) + ei_add_cxx_compiler_flag("-pie") + ei_add_cxx_compiler_flag("-fPIE") + endif() + + set(CMAKE_REQUIRED_FLAGS "") + + option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF) + if(EIGEN_TEST_SSE2) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") + message(STATUS "Enabling SSE2 in tests/examples") + endif() + + option(EIGEN_TEST_SSE3 "Enable/Disable SSE3 in tests/examples" OFF) + if(EIGEN_TEST_SSE3) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3") + message(STATUS "Enabling SSE3 in tests/examples") + endif() + + option(EIGEN_TEST_SSSE3 "Enable/Disable SSSE3 in tests/examples" OFF) + if(EIGEN_TEST_SSSE3) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3") + message(STATUS "Enabling SSSE3 in tests/examples") + endif() + + option(EIGEN_TEST_SSE4_1 "Enable/Disable SSE4.1 in tests/examples" OFF) + if(EIGEN_TEST_SSE4_1) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") + message(STATUS "Enabling SSE4.1 in tests/examples") + endif() + + option(EIGEN_TEST_SSE4_2 "Enable/Disable SSE4.2 in tests/examples" OFF) + if(EIGEN_TEST_SSE4_2) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2") + message(STATUS "Enabling SSE4.2 in tests/examples") + endif() + + option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF) + if(EIGEN_TEST_AVX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") + message(STATUS "Enabling AVX in tests/examples") + endif() + + option(EIGEN_TEST_FMA "Enable/Disable FMA in tests/examples" OFF) + if(EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfma") + message(STATUS "Enabling FMA in tests/examples") + endif() + + option(EIGEN_TEST_AVX2 "Enable/Disable AVX2 in tests/examples" OFF) + if(EIGEN_TEST_AVX2) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2 -mfma") + message(STATUS "Enabling AVX2 in tests/examples") + endif() + + option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF) + if(EIGEN_TEST_AVX512) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mfma") + message(STATUS "Enabling AVX512 in tests/examples") + endif() + + option(EIGEN_TEST_AVX512DQ "Enable/Disable AVX512DQ in tests/examples" OFF) + if(EIGEN_TEST_AVX512DQ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512dq -mfma") + message(STATUS "Enabling AVX512DQ in tests/examples") + endif() + + option(EIGEN_TEST_AVX512FP16 "Enable/Disable AVX512-FP16 in tests/examples" OFF) + if(EIGEN_TEST_AVX512FP16) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx512f -mfma -mavx512vl -mavx512fp16") + message(STATUS "Enabling AVX512-FP16 in tests/examples") + endif() + + option(EIGEN_TEST_F16C "Enable/Disable F16C in tests/examples" OFF) + if(EIGEN_TEST_F16C) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c") + message(STATUS "Enabling F16C in tests/examples") + endif() + + option(EIGEN_TEST_ALTIVEC "Enable/Disable AltiVec in tests/examples" OFF) + if(EIGEN_TEST_ALTIVEC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec -mabi=altivec") + message(STATUS "Enabling AltiVec in tests/examples") + endif() + + option(EIGEN_TEST_VSX "Enable/Disable VSX in tests/examples" OFF) + if(EIGEN_TEST_VSX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -mvsx") + message(STATUS "Enabling VSX in tests/examples") + endif() + + option(EIGEN_TEST_MSA "Enable/Disable MSA in tests/examples" OFF) + if(EIGEN_TEST_MSA) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmsa") + message(STATUS "Enabling MSA in tests/examples") + endif() + + option(EIGEN_TEST_NEON "Enable/Disable Neon in tests/examples" OFF) + if(EIGEN_TEST_NEON) + if(EIGEN_TEST_FMA) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon") + endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard") + message(STATUS "Enabling NEON in tests/examples") + endif() + + option(EIGEN_TEST_NEON64 "Enable/Disable Neon in tests/examples" OFF) + if(EIGEN_TEST_NEON64) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + message(STATUS "Enabling NEON in tests/examples") + endif() + + option(EIGEN_TEST_Z13 "Enable/Disable S390X(zEC13) ZVECTOR in tests/examples" OFF) + if(EIGEN_TEST_Z13) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z13 -mzvector") + message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples") + endif() + + option(EIGEN_TEST_Z14 "Enable/Disable S390X(zEC14) ZVECTOR in tests/examples" OFF) + if(EIGEN_TEST_Z14) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=z14 -mzvector") + message(STATUS "Enabling S390X(zEC13) ZVECTOR in tests/examples") + endif() + + check_cxx_compiler_flag("-fopenmp" COMPILER_SUPPORT_OPENMP) + if(COMPILER_SUPPORT_OPENMP) + option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF) + if(EIGEN_TEST_OPENMP) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") + message(STATUS "Enabling OpenMP in tests/examples") + endif() + endif() + + else() + # C4127 - conditional expression is constant + # C4714 - marked as __forceinline not inlined (I failed to deactivate it selectively) + # We can disable this warning in the unit tests since it is clear that it occurs + # because we are oftentimes returning objects that have a destructor or may + # throw exceptions - in particular in the unit tests we are throwing extra many + # exceptions to cover indexing errors. + # C4505 - unreferenced local function has been removed (impossible to deactivate selectively) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /wd4127 /wd4505 /wd4714") + + # replace all /Wx by /W4 + string(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + + check_cxx_compiler_flag("/openmp" COMPILER_SUPPORT_OPENMP) + if(COMPILER_SUPPORT_OPENMP) + option(EIGEN_TEST_OPENMP "Enable/Disable OpenMP in tests/examples" OFF) + if(EIGEN_TEST_OPENMP) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") + message(STATUS "Enabling OpenMP in tests/examples") + endif() + endif() + + option(EIGEN_TEST_SSE2 "Enable/Disable SSE2 in tests/examples" OFF) + if(EIGEN_TEST_SSE2) + if(NOT CMAKE_CL_64) + # arch is not supported on 64 bit systems, SSE is enabled automatically. + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2") + endif() + message(STATUS "Enabling SSE2 in tests/examples") + endif() + + option(EIGEN_TEST_AVX "Enable/Disable AVX in tests/examples" OFF) + if(EIGEN_TEST_AVX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX") + message(STATUS "Enabling AVX in tests/examples") + endif() + + option(EIGEN_TEST_FMA "Enable/Disable FMA/AVX2 in tests/examples" OFF) + option(EIGEN_TEST_AVX2 "Enable/Disable FMA/AVX2 in tests/examples" OFF) + if((EIGEN_TEST_FMA AND NOT EIGEN_TEST_NEON) OR EIGEN_TEST_AVX2) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2") + message(STATUS "Enabling FMA/AVX2 in tests/examples") + endif() + + option(EIGEN_TEST_AVX512 "Enable/Disable AVX512 in tests/examples" OFF) + option(EIGEN_TEST_AVX512DQ "Enable/Disable AVX512DQ in tests/examples" OFF) + if(EIGEN_TEST_AVX512 OR EIGEN_TEST_AVX512DQ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX512") + message(STATUS "Enabling AVX512 in tests/examples") + endif() + + endif(NOT MSVC) + + option(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION "Disable explicit vectorization in tests/examples" OFF) + option(EIGEN_TEST_X87 "Force using X87 instructions. Implies no vectorization." OFF) + option(EIGEN_TEST_32BIT "Force generating 32bit code." OFF) + + if(EIGEN_TEST_X87) + set(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION ON) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=387") + message(STATUS "Forcing use of x87 instructions in tests/examples") + else() + message(STATUS "EIGEN_TEST_X87 ignored on your compiler") + endif() + endif() + + if(EIGEN_TEST_32BIT) + if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") + message(STATUS "Forcing generation of 32-bit code in tests/examples") + else() + message(STATUS "EIGEN_TEST_32BIT ignored on your compiler") + endif() + endif() + + if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) + add_definitions(-DEIGEN_DONT_VECTORIZE=1) + message(STATUS "Disabling vectorization in tests/examples") + endif() + + option(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT "Disable explicit alignment (hence vectorization) in tests/examples" OFF) + if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT) + add_definitions(-DEIGEN_DONT_ALIGN=1) + message(STATUS "Disabling alignment in tests/examples") + endif() + + option(EIGEN_TEST_NO_EXCEPTIONS "Disables C++ exceptions" OFF) + if(EIGEN_TEST_NO_EXCEPTIONS) + ei_add_cxx_compiler_flag("-fno-exceptions") + message(STATUS "Disabling exceptions in tests/examples") + endif() + + set(EIGEN_CUDA_CXX_FLAGS "" CACHE STRING "Additional flags to pass to the cuda compiler.") + set(EIGEN_CUDA_COMPUTE_ARCH 30 CACHE STRING "The CUDA compute architecture(s) to target when compiling CUDA code") + + option(EIGEN_TEST_SYCL "Add Sycl support." OFF) + if(EIGEN_TEST_SYCL) + option(EIGEN_SYCL_DPCPP "Use the DPCPP Sycl implementation (DPCPP is default SYCL-Compiler)." ON) + option(EIGEN_SYCL_TRISYCL "Use the triSYCL Sycl implementation." OFF) + option(EIGEN_SYCL_ComputeCpp "Use the ComputeCPP Sycl implementation." OFF) + + # Building options + # https://developer.codeplay.com/products/computecpp/ce/2.11.0/guides/eigen-overview/options-for-building-eigen-sycl + option(EIGEN_SYCL_USE_DEFAULT_SELECTOR "Use sycl default selector to select the preferred device." OFF) + option(EIGEN_SYCL_NO_LOCAL_MEM "Build for devices without dedicated shared memory." OFF) + option(EIGEN_SYCL_LOCAL_MEM "Allow the use of local memory (enabled by default)." ON) + option(EIGEN_SYCL_LOCAL_THREAD_DIM0 "Set work group size for dimension 0." 16) + option(EIGEN_SYCL_LOCAL_THREAD_DIM1 "Set work group size for dimension 1." 16) + option(EIGEN_SYCL_ASYNC_EXECUTION "Allow asynchronous execution (enabled by default)." ON) + option(EIGEN_SYCL_DISABLE_SKINNY "Disable optimization for tall/skinny matrices." OFF) + option(EIGEN_SYCL_DISABLE_DOUBLE_BUFFER "Disable double buffer." OFF) + option(EIGEN_SYCL_DISABLE_SCALAR "Disable scalar contraction." OFF) + option(EIGEN_SYCL_DISABLE_GEMV "Disable GEMV and create a single kernel to calculate contraction instead." OFF) + + set(EIGEN_SYCL ON) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-shorten-64-to-32 -Wno-cast-align") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy-with-user-provided-copy -Wno-unused-variable") + set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}") + find_package(Threads REQUIRED) + if(EIGEN_SYCL_TRISYCL) + message(STATUS "Using triSYCL") + include(FindTriSYCL) + elseif(EIGEN_SYCL_ComputeCpp) + message(STATUS "Using ComputeCPP SYCL") + include(FindComputeCpp) + set(COMPUTECPP_DRIVER_DEFAULT_VALUE OFF) + if (NOT MSVC) + set(COMPUTECPP_DRIVER_DEFAULT_VALUE ON) + endif() + option(COMPUTECPP_USE_COMPILER_DRIVER + "Use ComputeCpp driver instead of a 2 steps compilation" + ${COMPUTECPP_DRIVER_DEFAULT_VALUE} + ) + else() #Default SYCL compiler is DPCPP (EIGEN_SYCL_DPCPP) + set(DPCPP_SYCL_TARGET "spir64" CACHE STRING "Default target for Intel CPU/GPU") + message(STATUS "Using DPCPP") + find_package(DPCPP) + add_definitions(-DSYCL_COMPILER_IS_DPCPP) + endif(EIGEN_SYCL_TRISYCL) + if(EIGEN_DONT_VECTORIZE_SYCL) + message(STATUS "Disabling SYCL vectorization in tests/examples") + # When disabling SYCL vectorization, also disable Eigen default vectorization + add_definitions(-DEIGEN_DONT_VECTORIZE=1) + add_definitions(-DEIGEN_DONT_VECTORIZE_SYCL=1) + endif() + endif() -cmake_dependent_option(BUILD_TESTING "Enable creation of tests." ON "PROJECT_IS_TOP_LEVEL" OFF) -option(EIGEN_BUILD_TESTING "Enable creation of Eigen tests." ${BUILD_TESTING}) -if(EIGEN_BUILD_TESTING) include(EigenConfigureTesting) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) - add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest + # CTest automatic test building relies on the "all" target. + add_subdirectory(test) + add_subdirectory(failtest) else() add_subdirectory(test EXCLUDE_FROM_ALL) + add_subdirectory(failtest EXCLUDE_FROM_ALL) endif() - add_subdirectory(failtest) -endif() + ei_testing_print_summary() -include(CMakeDetermineFortranCompiler) -option(EIGEN_BUILD_BLAS "Toggles the building of the Eigen Blas library" ${CMAKE_Fortran_COMPILER}) -option(EIGEN_BUILD_LAPACK "Toggles the building of the included Eigen LAPACK library" ${CMAKE_Fortran_COMPILER}) -if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) - add_subdirectory(blas) - add_subdirectory(lapack) -else() - add_subdirectory(blas EXCLUDE_FROM_ALL) - add_subdirectory(lapack EXCLUDE_FROM_ALL) -endif() - -# add SYCL -option(EIGEN_TEST_SYCL "Add Sycl support." OFF) -option(EIGEN_SYCL_TRISYCL "Use the triSYCL Sycl implementation (ComputeCPP by default)." OFF) -if(EIGEN_TEST_SYCL) - set (CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "cmake/Modules/" "${CMAKE_MODULE_PATH}") - find_package(Threads REQUIRED) - if(EIGEN_SYCL_TRISYCL) - message(STATUS "Using triSYCL") - include(FindTriSYCL) - else() - message(STATUS "Using ComputeCPP SYCL") - include(FindComputeCpp) - set(COMPUTECPP_DRIVER_DEFAULT_VALUE OFF) - if (NOT MSVC) - set(COMPUTECPP_DRIVER_DEFAULT_VALUE ON) - endif() - option(COMPUTECPP_USE_COMPILER_DRIVER - "Use ComputeCpp driver instead of a 2 steps compilation" - ${COMPUTECPP_DRIVER_DEFAULT_VALUE} - ) - endif(EIGEN_SYCL_TRISYCL) - option(EIGEN_DONT_VECTORIZE_SYCL "Don't use vectorisation in the SYCL tests." OFF) - if(EIGEN_DONT_VECTORIZE_SYCL) - message(STATUS "Disabling SYCL vectorization in tests/examples") - # When disabling SYCL vectorization, also disable Eigen default vectorization - add_definitions(-DEIGEN_DONT_VECTORIZE=1) - add_definitions(-DEIGEN_DONT_VECTORIZE_SYCL=1) + if (EIGEN_SPLIT_TESTSUITE) + ei_split_testsuite("${EIGEN_SPLIT_TESTSUITE}") endif() -endif() +endif(EIGEN_BUILD_TESTING) +#============================================================================== +# Other Build Configurations. +#============================================================================== add_subdirectory(unsupported) -add_subdirectory(demos EXCLUDE_FROM_ALL) +if(EIGEN_BUILD_BLAS) + add_subdirectory(blas) +endif() -# must be after test and unsupported, for configuring buildtests.in -add_subdirectory(scripts EXCLUDE_FROM_ALL) +if (EIGEN_BUILD_LAPACK) + add_subdirectory(lapack) +endif() + +if(EIGEN_BUILD_DOC) + add_subdirectory(doc EXCLUDE_FROM_ALL) +endif() # TODO: consider also replacing EIGEN_BUILD_BTL by a custom target "make btl"? if(EIGEN_BUILD_BTL) @@ -583,15 +724,19 @@ if(NOT WIN32 AND EIGEN_BUILD_SPBENCH) add_subdirectory(bench/spbench EXCLUDE_FROM_ALL) endif() -configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY) - -if(EIGEN_BUILD_TESTING) - ei_testing_print_summary() +if (EIGEN_BUILD_DEMOS) + add_subdirectory(demos EXCLUDE_FROM_ALL) endif() -message(STATUS "") -message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}") -message(STATUS "") +if (PROJECT_IS_TOP_LEVEL) + # must be after test and unsupported, for configuring buildtests.in + add_subdirectory(scripts EXCLUDE_FROM_ALL) + configure_file(scripts/cdashtesting.cmake.in cdashtesting.cmake @ONLY) +endif() + +#============================================================================== +# Summary. +#============================================================================== if(PROJECT_IS_TOP_LEVEL) string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower) @@ -612,80 +757,24 @@ if(PROJECT_IS_TOP_LEVEL) message(STATUS " | cmake . -DCMAKE_INSTALL_PREFIX=yourprefix") message(STATUS " | Or:") message(STATUS " | cmake . -DINCLUDE_INSTALL_DIR=yourdir") - message(STATUS "doc | Generate the API documentation, requires Doxygen & LaTeX") + message(STATUS "uninstall| Remove files installed by the install target") + if (EIGEN_BUILD_DOC) + message(STATUS "doc | Generate the API documentation, requires Doxygen & LaTeX") + endif() if(EIGEN_BUILD_TESTING) message(STATUS "check | Build and run the unit-tests. Read this page:") message(STATUS " | http://eigen.tuxfamily.org/index.php?title=Tests") endif() - message(STATUS "blas | Build BLAS library (not the same thing as Eigen)") - message(STATUS "uninstall| Remove files installed by the install target") + if (EIGEN_BUILD_BLAS) + message(STATUS "blas | Build BLAS library (not the same thing as Eigen)") + endif() + if (EIGEN_BUILD_LAPACK) + message(STATUS "lapack | Build LAPACK subset library (not the same thing as Eigen)") + endif() message(STATUS "---------+--------------------------------------------------------------") message(STATUS "") endif() -set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} ) -set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} ) -set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} ) -set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} ) -set ( EIGEN_DEFINITIONS "") -set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" ) -set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} ) - -include (CMakePackageConfigHelpers) - -# Imported target support -add_library (eigen INTERFACE) -add_library (Eigen3::Eigen ALIAS eigen) -target_compile_definitions (eigen INTERFACE ${EIGEN_DEFINITIONS}) -target_include_directories (eigen INTERFACE - $ - $ -) - -# Export as title case Eigen -set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen) - -install (TARGETS eigen EXPORT Eigen3Targets) - -option(EIGEN_BUILD_CMAKE_PACKAGE "Enables the creation of EigenConfig.cmake and related files" ON) -if(EIGEN_BUILD_CMAKE_PACKAGE) -configure_package_config_file ( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3Config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake - PATH_VARS EIGEN_INCLUDE_DIR EIGEN_ROOT_DIR - INSTALL_DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} - NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components -) -# Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does -# not depend on architecture specific settings or libraries. More -# specifically, an Eigen3Config.cmake generated from a 64 bit target can be -# used for 32 bit targets as well (and vice versa). -set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) -unset (CMAKE_SIZEOF_VOID_P) -write_basic_package_version_file (Eigen3ConfigVersion.cmake - VERSION ${EIGEN_VERSION_NUMBER} - COMPATIBILITY SameMajorVersion) -set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P}) - -# The Eigen target will be located in the Eigen3 namespace. Other CMake -# targets can refer to it using Eigen3::Eigen. -export (TARGETS eigen NAMESPACE Eigen3:: FILE Eigen3Targets.cmake) -# Export Eigen3 package to CMake registry such that it can be easily found by -# CMake even if it has not been installed to a standard directory. -export (PACKAGE Eigen3) - -install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}) - -install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake - ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake - DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} ) - -# Add uninstall target -add_custom_target ( uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake) -endif() - -if (EIGEN_SPLIT_TESTSUITE) - ei_split_testsuite("${EIGEN_SPLIT_TESTSUITE}") -endif() +message(STATUS "") +message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}") +message(STATUS "") diff --git a/cmake/Eigen3Config.cmake.in b/cmake/Eigen3Config.cmake.in index 0a1ac61c9..58dc3de7d 100644 --- a/cmake/Eigen3Config.cmake.in +++ b/cmake/Eigen3Config.cmake.in @@ -3,9 +3,9 @@ @PACKAGE_INIT@ -if (NOT TARGET eigen) +if (NOT TARGET Eigen3::Eigen) include ("${CMAKE_CURRENT_LIST_DIR}/Eigen3Targets.cmake") -endif () +endif (NOT TARGET Eigen3::Eigen) # Legacy variables, do *not* use. May be removed in the future. diff --git a/cmake/EigenConfigureTesting.cmake b/cmake/EigenConfigureTesting.cmake index add6aab53..2a1e7ab5a 100644 --- a/cmake/EigenConfigureTesting.cmake +++ b/cmake/EigenConfigureTesting.cmake @@ -8,7 +8,7 @@ ei_set_sitename() ei_set_build_string() add_custom_target(buildtests) -add_custom_target(check COMMAND "ctest") +add_custom_target(check COMMAND "ctest" ${EIGEN_CTEST_ARGS}) add_dependencies(check buildtests) # Convenience target for only building GPU tests. diff --git a/cmake/EigenSmokeTestList.cmake b/cmake/EigenSmokeTestList.cmake index 6f0f72418..db7d3ff5e 100644 --- a/cmake/EigenSmokeTestList.cmake +++ b/cmake/EigenSmokeTestList.cmake @@ -61,6 +61,9 @@ set(ei_smoke_test_list mapped_matrix_1 mapstaticmethods_1 mapstride_1 + unaryviewstride_1 + unaryviewstride_2 + unaryviewstride_3 matrix_square_root_1 meta minres_2 @@ -100,6 +103,7 @@ set(ei_smoke_test_list sizeof sizeoverflow smallvectors + sparse_basic_1 sparse_basic_3 sparse_block_1 sparse_extra_4 @@ -128,4 +132,5 @@ set(ei_smoke_test_list unalignedassert unalignedcount vectorwiseop_1 - visitor_1) \ No newline at end of file + visitor_1 + vectorization_logic_1) diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake index b37d1158b..2c2019fb0 100644 --- a/cmake/EigenTesting.cmake +++ b/cmake/EigenTesting.cmake @@ -28,66 +28,59 @@ macro(ei_add_test_internal testname testname_with_suffix) set(is_gpu_test ON) if(EIGEN_TEST_HIP) hip_reset_flags() - hip_add_executable(${targetname} ${filename} HIPCC_OPTIONS "-DEIGEN_USE_HIP ${ARGV2}") + hip_add_executable(${targetname} ${filename} HIPCC_OPTIONS -std=c++14) + target_compile_definitions(${targetname} PRIVATE -DEIGEN_USE_HIP) + set_property(TARGET ${targetname} PROPERTY HIP_ARCHITECTURES gfx900 gfx906 gfx908 gfx90a gfx940 gfx941 gfx942 gfx1030) elseif(EIGEN_TEST_CUDA_CLANG) set_source_files_properties(${filename} PROPERTIES LANGUAGE CXX) - + if(CUDA_64_BIT_DEVICE_CODE AND (EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/lib64")) link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64") else() link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib") endif() - if (${ARGC} GREATER 2) - add_executable(${targetname} ${filename}) - else() - add_executable(${targetname} ${filename} OPTIONS ${ARGV2}) - endif() + add_executable(${targetname} ${filename}) set(CUDA_CLANG_LINK_LIBRARIES "cudart_static" "cuda" "dl" "pthread") if (CMAKE_SYSTEM_NAME STREQUAL "Linux") set(CUDA_CLANG_LINK_LIBRARIES ${CUDA_CLANG_LINK_LIBRARIES} "rt") endif() target_link_libraries(${targetname} ${CUDA_CLANG_LINK_LIBRARIES}) else() - if (${ARGC} GREATER 2) - cuda_add_executable(${targetname} ${filename} OPTIONS ${ARGV2}) - else() - cuda_add_executable(${targetname} ${filename}) - endif() + cuda_add_executable(${targetname} ${filename}) endif() else() add_executable(${targetname} ${filename}) endif() add_dependencies(buildtests ${targetname}) - + if (is_gpu_test) add_dependencies(buildtests_gpu ${targetname}) endif() if(EIGEN_NO_ASSERTION_CHECKING) - ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1") + target_compile_definitions(${targetname} PRIVATE EIGEN_NO_ASSERTION_CHECKING=1) else() if(EIGEN_DEBUG_ASSERTS) - ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1") + target_compile_definitions(${targetname} PRIVATE EIGEN_DEBUG_ASSERTS=1) endif() endif() - ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}") + target_compile_definitions(${targetname} PRIVATE EIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}) if(MSVC) - ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj") + target_compile_options(${targetname} PRIVATE "/bigobj") endif() # let the user pass flags. if(${ARGC} GREATER 2) - set(compile_options "${ARGV2}") - separate_arguments(compile_options) - ei_add_target_property(${targetname} COMPILE_FLAGS ${compile_options}) + separate_arguments(compile_options NATIVE_COMMAND ${ARGV2}) + target_compile_options(${targetname} PRIVATE ${compile_options}) endif() if(EIGEN_TEST_CUSTOM_CXX_FLAGS) - ei_add_target_property(${targetname} COMPILE_FLAGS ${EIGEN_TEST_CUSTOM_CXX_FLAGS}) + target_compile_options(${targetname} PRIVATE ${EIGEN_TEST_CUSTOM_CXX_FLAGS}) endif() if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) @@ -99,6 +92,7 @@ macro(ei_add_test_internal testname testname_with_suffix) if(EIGEN_TEST_CUSTOM_LINKER_FLAGS) target_link_libraries(${targetname} ${EIGEN_TEST_CUSTOM_LINKER_FLAGS}) endif() + target_link_libraries(${targetname} Eigen3::Eigen) if(${ARGC} GREATER 3) set(libs_to_link ${ARGV3}) @@ -113,7 +107,7 @@ macro(ei_add_test_internal testname testname_with_suffix) endif() endif() - add_test(${testname_with_suffix} "${targetname}") + add_test(NAME ${testname_with_suffix} COMMAND "${targetname}") # Specify target and test labels according to EIGEN_CURRENT_SUBPROJECT get_property(current_subproject GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT) @@ -126,22 +120,10 @@ macro(ei_add_test_internal testname testname_with_suffix) # Add gpu tag for testing only GPU tests. set_property(TEST ${testname_with_suffix} APPEND PROPERTY LABELS "gpu") endif() - + if(EIGEN_SYCL) # Force include of the SYCL file at the end to avoid errors. - set_property(TARGET ${targetname} PROPERTY COMPUTECPP_INCLUDE_AFTER 1) - # Set COMPILE_FLAGS to COMPILE_DEFINITIONS instead to avoid having to duplicate the flags - # to the device compiler. - get_target_property(target_compile_flags ${targetname} COMPILE_FLAGS) - separate_arguments(target_compile_flags) - foreach(flag ${target_compile_flags}) - if(${flag} MATCHES "^-D.*") - string(REPLACE "-D" "" definition_flag ${flag}) - set_property(TARGET ${targetname} APPEND PROPERTY COMPILE_DEFINITIONS ${definition_flag}) - list(REMOVE_ITEM target_compile_flags ${flag}) - endif() - endforeach() - set_property(TARGET ${targetname} PROPERTY COMPILE_FLAGS ${target_compile_flags}) + set_property(TARGET ${gittargetname} PROPERTY COMPUTECPP_INCLUDE_AFTER 1) # Link against pthread and add sycl to target set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -218,12 +200,13 @@ macro(ei_add_test testname) if( (EIGEN_SPLIT_LARGE_TESTS AND suffixes) OR explicit_suffixes) add_custom_target(${testname}) foreach(suffix ${suffixes}) - ei_add_test_internal(${testname} ${testname}_${suffix} - "${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}") + ei_add_test_internal(${testname} ${testname}_${suffix} "${ARGV1}" "${ARGV2}") add_dependencies(${testname} ${testname}_${suffix}) + target_compile_definitions(${testname}_${suffix} PRIVATE -DEIGEN_TEST_PART_${suffix}=1) endforeach() else() - ei_add_test_internal(${testname} ${testname} "${ARGV1} -DEIGEN_TEST_PART_ALL=1" "${ARGV2}") + ei_add_test_internal(${testname} ${testname} "${ARGV1}" "${ARGV2}") + target_compile_definitions(${testname} PRIVATE -DEIGEN_TEST_PART_ALL=1) endif() endmacro() @@ -249,11 +232,16 @@ macro(ei_add_failtest testname) # Add the tests to ctest. add_test(NAME ${test_target_ok} - COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ok} --config $ + COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ok} --config $ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) add_test(NAME ${test_target_ko} - COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ko} --config $ + COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ko} --config $ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) + # Disable emulator if cross-compiling. + if (CMAKE_CROSSCOMPILING) + set_property(TEST ${test_target_ok} PROPERTY CROSSCOMPILING_EMULATOR "") + set_property(TEST ${test_target_ko} PROPERTY CROSSCOMPILING_EMULATOR "") + endif() # Expect the second test to fail set_tests_properties(${test_target_ko} PROPERTIES WILL_FAIL TRUE) @@ -393,8 +381,10 @@ macro(ei_testing_print_summary) if(EIGEN_TEST_SYCL) if(EIGEN_SYCL_TRISYCL) message(STATUS "SYCL: ON (using triSYCL)") - else() + elseif(EIGEN_SYCL_ComputeCpp) message(STATUS "SYCL: ON (using computeCPP)") + elseif(EIGEN_SYCL_DPCPP) + message(STATUS "SYCL: ON (using DPCPP)") endif() else() message(STATUS "SYCL: OFF") @@ -464,15 +454,7 @@ endmacro() macro(ei_get_compilerver VAR) if(MSVC) - # on windows system, we use a modified CMake script - include(EigenDetermineVSServicePack) - EigenDetermineVSServicePack( my_service_pack ) - - if( my_service_pack ) - set(${VAR} ${my_service_pack}) - else() - set(${VAR} "na") - endif() + set(${VAR} "${CMAKE_CXX_COMPILER_VERSION}") elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "PGI") set(${VAR} "${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}") else() @@ -541,12 +523,12 @@ macro(ei_get_compilerver_from_cxx_version_string VERSTRING CNAME CVER) string(REGEX MATCH "[^0-9][0-9]+\\.[0-9]+" eicver ${VERSTRING}) if (NOT eicver AND ei_has_mingw) # try to extract 1 number plus suffix: - string(REGEX MATCH "[^0-9][0-9]+-win32" eicver ${VERSTRING}) + string(REGEX MATCH "[^0-9][0-9]+-win32" eicver ${VERSTRING}) endif() endif() endif() endif() - + if (NOT eicver) set(eicver " _") endif() @@ -607,10 +589,7 @@ macro(ei_set_build_string) ei_get_compilerver(LOCAL_COMPILER_VERSION) ei_get_cxxflags(LOCAL_COMPILER_FLAGS) - include(EigenDetermineOSVersion) - DetermineOSVersion(OS_VERSION) - - set(TMP_BUILD_STRING ${OS_VERSION}-${LOCAL_COMPILER_VERSION}) + set(TMP_BUILD_STRING ${CMAKE_SYSTEM}-${LOCAL_COMPILER_VERSION}) if (NOT ${LOCAL_COMPILER_FLAGS} STREQUAL "") set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-${LOCAL_COMPILER_FLAGS}) @@ -680,10 +659,10 @@ endmacro() # Split all tests listed in EIGEN_TESTS_LIST into num_splits many targets # named buildtestspartN with N = { 0, ..., num_splits-1}. # -# The intention behind the existance of this macro is the size of Eigen's -# testsuite. Together with the relativly big compile-times building all tests +# The intention behind the existence of this macro is the size of Eigen's +# testsuite. Together with the relatively big compile-times building all tests # can take a substantial amount of time depending on the available hardware. -# +# # The last buildtestspartN target will build possible remaining tests. # # An example: @@ -727,7 +706,7 @@ macro(ei_split_testsuite num_splits) endforeach() math(EXPR test_idx "${test_idx} + ${num_tests_per_target}") endforeach() - + # Handle the possibly remaining tests math(EXPR test_idx "${num_splits} * ${num_tests_per_target}") math(EXPR target_bound "${eigen_test_count} - 1") @@ -739,10 +718,10 @@ endmacro(ei_split_testsuite num_splits) # Defines the custom command buildsmoketests to build a number of tests # specified in smoke_test_list. -# +# # Test in smoke_test_list can be either test targets (e.g. packetmath) or # subtests targets (e.g. packetmath_2). If any of the test are not available -# in the current configuration they are just skipped. +# in the current configuration they are just skipped. # # All tests added via this macro are labeled with the smoketest label. This # allows running smoketests only using ctest. diff --git a/cmake/FindCLANG_FORMAT.cmake b/cmake/FindCLANG_FORMAT.cmake new file mode 100644 index 000000000..e00f19fe6 --- /dev/null +++ b/cmake/FindCLANG_FORMAT.cmake @@ -0,0 +1,61 @@ + + +# Find clang-format +# +# CLANG_FORMAT_EXECUTABLE - Path to clang-format executable +# CLANG_FORMAT_FOUND - True if the clang-format executable was found. +# CLANG_FORMAT_VERSION - The version of clang-format found +# +# Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) +# +# Licensed under the Mozilla Public 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 +# +# https://www.mozilla.org/en-US/MPL/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. +# + +find_program(CLANG_FORMAT_EXECUTABLE + NAMES + clang-format-9 + clang-format + clang-format-11 + clang-format-10 + clang-format-8 + clang-format-7 + + DOC "clang-format executable") +mark_as_advanced(CLANG_FORMAT_EXECUTABLE) + +# Extract version from command "clang-format -version" +if(CLANG_FORMAT_EXECUTABLE) + execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version + OUTPUT_VARIABLE clang_format_version + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(clang_format_version MATCHES "^.*clang-format version .*") + # clang_format_version sample: "clang-format version 3.9.1-4ubuntu3~16.04.1 + # (tags/RELEASE_391/rc2)" + string(REGEX + REPLACE "^.*clang-format version ([.0-9]+).*" + "\\1" + CLANG_FORMAT_VERSION + "${clang_format_version}") + # CLANG_FORMAT_VERSION sample: "3.9.1" + else() + set(CLANG_FORMAT_VERSION 0.0) + endif() +else() + set(CLANG_FORMAT_VERSION 0.0) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set CLANG_FORMAT_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(CLANG_FORMAT REQUIRED_VARS CLANG_FORMAT_EXECUTABLE VERSION_VAR CLANG_FORMAT_VERSION) diff --git a/cmake/FindComputeCpp.cmake b/cmake/FindComputeCpp.cmake index 1c271f0fe..e20052277 100644 --- a/cmake/FindComputeCpp.cmake +++ b/cmake/FindComputeCpp.cmake @@ -382,7 +382,7 @@ endfunction(__build_ir) ####################### # # Adds a SYCL compilation custom command associated with an existing -# target and sets a dependancy on that new command. +# target and sets a dependency on that new command. # # TARGET : Name of the target to add SYCL to. # SOURCES : Source files to be compiled for SYCL. diff --git a/cmake/FindDPCPP.cmake b/cmake/FindDPCPP.cmake new file mode 100644 index 000000000..73aa30f65 --- /dev/null +++ b/cmake/FindDPCPP.cmake @@ -0,0 +1,62 @@ +include_guard() + +include(CheckCXXCompilerFlag) +include(FindPackageHandleStandardArgs) + +if("${DPCPP_SYCL_TARGET}" STREQUAL "amdgcn-amd-amdhsa" AND + "${DPCPP_SYCL_ARCH}" STREQUAL "") + message(FATAL_ERROR "Architecture required for AMD DPCPP builds," + " please specify in DPCPP_SYCL_ARCH") +endif() + +set(DPCPP_USER_FLAGS "" CACHE STRING + "Additional user-specified compiler flags for DPC++") + +get_filename_component(DPCPP_BIN_DIR ${CMAKE_CXX_COMPILER} DIRECTORY) +find_library(DPCPP_LIB_DIR NAMES sycl sycl6 PATHS "${DPCPP_BIN_DIR}/../lib") + +add_library(DPCPP::DPCPP INTERFACE IMPORTED) + +set(DPCPP_FLAGS "-fsycl;-fsycl-targets=${DPCPP_SYCL_TARGET};-fsycl-unnamed-lambda;${DPCPP_USER_FLAGS};-ftemplate-backtrace-limit=0") +if(NOT "${DPCPP_SYCL_ARCH}" STREQUAL "") + if("${DPCPP_SYCL_TARGET}" STREQUAL "amdgcn-amd-amdhsa") + list(APPEND DPCPP_FLAGS "-Xsycl-target-backend") + list(APPEND DPCPP_FLAGS "--offload-arch=${DPCPP_SYCL_ARCH}") + elseif("${DPCPP_SYCL_TARGET}" STREQUAL "nvptx64-nvidia-cuda") + list(APPEND DPCPP_FLAGS "-Xsycl-target-backend") + list(APPEND DPCPP_FLAGS "--cuda-gpu-arch=${DPCPP_SYCL_ARCH}") + endif() +endif() + +if(UNIX) + set_target_properties(DPCPP::DPCPP PROPERTIES + INTERFACE_COMPILE_OPTIONS "${DPCPP_FLAGS}" + INTERFACE_LINK_OPTIONS "${DPCPP_FLAGS}" + INTERFACE_LINK_LIBRARIES ${DPCPP_LIB_DIR} + INTERFACE_INCLUDE_DIRECTORIES "${DPCPP_BIN_DIR}/../include/sycl;${DPCPP_BIN_DIR}/../include") + message(STATUS ">>>>>>>>> DPCPP INCLUDE DIR: ${DPCPP_BIN_DIR}/../include/sycl") +else() + set_target_properties(DPCPP::DPCPP PROPERTIES + INTERFACE_COMPILE_OPTIONS "${DPCPP_FLAGS}" + INTERFACE_LINK_LIBRARIES ${DPCPP_LIB_DIR} + INTERFACE_INCLUDE_DIRECTORIES "${DPCPP_BIN_DIR}/../include/sycl") +endif() + +function(add_sycl_to_target) + set(options) + set(one_value_args TARGET) + set(multi_value_args SOURCES) + cmake_parse_arguments(SB_ADD_SYCL + "${options}" + "${one_value_args}" + "${multi_value_args}" + ${ARGN} + ) + target_compile_options(${SB_ADD_SYCL_TARGET} PUBLIC ${DPCPP_FLAGS}) + target_link_libraries(${SB_ADD_SYCL_TARGET} DPCPP::DPCPP) + target_compile_features(${SB_ADD_SYCL_TARGET} PRIVATE cxx_std_17) + get_target_property(target_type ${SB_ADD_SYCL_TARGET} TYPE) + if (NOT target_type STREQUAL "OBJECT_LIBRARY") + target_link_options(${SB_ADD_SYCL_TARGET} PUBLIC ${DPCPP_FLAGS}) + endif() +endfunction() diff --git a/cmake/SyclConfigureTesting.cmake b/cmake/SyclConfigureTesting.cmake new file mode 100644 index 000000000..d4aa42369 --- /dev/null +++ b/cmake/SyclConfigureTesting.cmake @@ -0,0 +1,64 @@ +set(CMAKE_CXX_STANDARD 17) +# Forward CMake options as preprocessor definitions +if(EIGEN_SYCL_USE_DEFAULT_SELECTOR) + add_definitions(-DEIGEN_SYCL_USE_DEFAULT_SELECTOR=${EIGEN_SYCL_USE_DEFAULT_SELECTOR}) +endif() +if(EIGEN_SYCL_NO_LOCAL_MEM) + add_definitions(-DEIGEN_SYCL_NO_LOCAL_MEM=${EIGEN_SYCL_NO_LOCAL_MEM}) +endif() +if(EIGEN_SYCL_LOCAL_MEM) + add_definitions(-DEIGEN_SYCL_LOCAL_MEM=${EIGEN_SYCL_LOCAL_MEM}) +endif() +if(EIGEN_SYCL_MAX_GLOBAL_RANGE) + add_definitions(-DEIGEN_SYCL_MAX_GLOBAL_RANGE=${EIGEN_SYCL_MAX_GLOBAL_RANGE}) +endif() +if(EIGEN_SYCL_LOCAL_THREAD_DIM0) + add_definitions(-DEIGEN_SYCL_LOCAL_THREAD_DIM0=${EIGEN_SYCL_LOCAL_THREAD_DIM0}) +endif() +if(EIGEN_SYCL_LOCAL_THREAD_DIM1) + add_definitions(-DEIGEN_SYCL_LOCAL_THREAD_DIM1=${EIGEN_SYCL_LOCAL_THREAD_DIM1}) +endif() +if(EIGEN_SYCL_REG_M) + add_definitions(-DEIGEN_SYCL_REG_M=${EIGEN_SYCL_REG_M}) +endif() +if(EIGEN_SYCL_REG_N) + add_definitions(-DEIGEN_SYCL_REG_N=${EIGEN_SYCL_REG_N}) +endif() +if(EIGEN_SYCL_ASYNC_EXECUTION) + add_definitions(-DEIGEN_SYCL_ASYNC_EXECUTION=${EIGEN_SYCL_ASYNC_EXECUTION}) +endif() +if(EIGEN_SYCL_DISABLE_SKINNY) + add_definitions(-DEIGEN_SYCL_DISABLE_SKINNY=${EIGEN_SYCL_DISABLE_SKINNY}) +endif() +if(EIGEN_SYCL_DISABLE_DOUBLE_BUFFER) + add_definitions(-DEIGEN_SYCL_DISABLE_DOUBLE_BUFFER=${EIGEN_SYCL_DISABLE_DOUBLE_BUFFER}) +endif() +if(EIGEN_SYCL_DISABLE_SCALAR) + add_definitions(-DEIGEN_SYCL_DISABLE_SCALAR=${EIGEN_SYCL_DISABLE_SCALAR}) +endif() +if(EIGEN_SYCL_DISABLE_GEMV) + add_definitions(-DEIGEN_SYCL_DISABLE_GEMV=${EIGEN_SYCL_DISABLE_GEMV}) +endif() +if(EIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION) + add_definitions(-DEIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION=${EIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION}) +endif() + +if(EIGEN_SYCL_ComputeCpp) + if(MSVC) + list(APPEND COMPUTECPP_USER_FLAGS -DWIN32) + else() + list(APPEND COMPUTECPP_USER_FLAGS -Wall) + endif() + # The following flags are not supported by Clang and can cause warnings + # if used with -Werror so they are removed here. + if(COMPUTECPP_USE_COMPILER_DRIVER) + set(CMAKE_CXX_COMPILER ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE}) + string(REPLACE "-Wlogical-op" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + string(REPLACE "-Wno-psabi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + endif() + list(APPEND COMPUTECPP_USER_FLAGS + -DEIGEN_NO_ASSERTION_CHECKING=1 + -no-serial-memop + -Xclang + -cl-mad-enable) +endif(EIGEN_SYCL_ComputeCpp) diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt index a2c9d05a4..9a1949e22 100644 --- a/doc/examples/CMakeLists.txt +++ b/doc/examples/CMakeLists.txt @@ -6,6 +6,7 @@ foreach(example_src ${examples_SRCS}) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) target_link_libraries(${example} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) endif() + target_link_libraries(${example} Eigen3::Eigen) add_custom_command( TARGET ${example} POST_BUILD @@ -13,8 +14,4 @@ foreach(example_src ${examples_SRCS}) ARGS >${CMAKE_CURRENT_BINARY_DIR}/${example}.out ) add_dependencies(all_examples ${example}) -endforeach() - -if(EIGEN_COMPILER_SUPPORT_CPP11) -ei_add_target_property(nullary_indexing COMPILE_FLAGS "-std=c++11") -endif() \ No newline at end of file +endforeach() \ No newline at end of file diff --git a/doc/snippets/CMakeLists.txt b/doc/snippets/CMakeLists.txt index 65f195a31..4cf1c6a08 100644 --- a/doc/snippets/CMakeLists.txt +++ b/doc/snippets/CMakeLists.txt @@ -15,6 +15,7 @@ foreach(snippet_src ${snippets_SRCS}) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) target_link_libraries(${compile_snippet_target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) endif() + target_link_libraries(${compile_snippet_target} Eigen3::Eigen) if(${snippet_src} MATCHES "cxx11") set_target_properties(${compile_snippet_target} PROPERTIES COMPILE_FLAGS "-std=c++11") endif() diff --git a/doc/special_examples/CMakeLists.txt b/doc/special_examples/CMakeLists.txt index 5b00e8b1a..f68ab5201 100644 --- a/doc/special_examples/CMakeLists.txt +++ b/doc/special_examples/CMakeLists.txt @@ -7,7 +7,7 @@ endif() if(QT4_FOUND) add_executable(Tutorial_sparse_example Tutorial_sparse_example.cpp Tutorial_sparse_example_details.cpp) - target_link_libraries(Tutorial_sparse_example ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) + target_link_libraries(Tutorial_sparse_example ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} Eigen3::Eigen) add_custom_command( TARGET Tutorial_sparse_example @@ -23,7 +23,7 @@ if(EIGEN_COMPILER_SUPPORT_CPP11) add_executable(random_cpp11 random_cpp11.cpp) target_link_libraries(random_cpp11 ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) add_dependencies(all_examples random_cpp11) - ei_add_target_property(random_cpp11 COMPILE_FLAGS "-std=c++11") + target_compile_options(random_cpp11 PRIVATE "-std=c++11") add_custom_command( TARGET random_cpp11 diff --git a/lapack/CMakeLists.txt b/lapack/CMakeLists.txt index 8d6d75401..196835cd5 100644 --- a/lapack/CMakeLists.txt +++ b/lapack/CMakeLists.txt @@ -111,6 +111,7 @@ foreach(target IN LISTS EIGEN_LAPACK_TARGETS) if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) target_link_libraries(${target} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) endif() + target_link_libraries(${target} Eigen3::Eigen) add_dependencies(lapack ${target}) install(TARGETS ${target} RUNTIME DESTINATION bin diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dbd4bc618..97ddbbc99 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -286,7 +286,6 @@ ei_add_test(special_numbers) ei_add_test(rvalue_types) ei_add_test(dense_storage) ei_add_test(ctorleak) -ei_add_test(mpl2only) ei_add_test(inplace_decomposition) ei_add_test(half_float) ei_add_test(bfloat16_float) @@ -311,7 +310,7 @@ else() endif() endif() -ei_add_test(fastmath " ${EIGEN_FASTMATH_FLAGS} ") +ei_add_test(fastmath "${EIGEN_FASTMATH_FLAGS}") # # ei_add_test(denseLM) @@ -396,6 +395,16 @@ if(CUDA_FOUND AND EIGEN_TEST_CUDA) else() set(CUDA_PROPAGATE_HOST_FLAGS OFF) set(NVCC_ARCH_FLAGS) + # Define an -arch=sm_, otherwise if GPU does not exactly match one of + # those in the arch list for -gencode, the kernels will fail to run with + # cudaErrorNoKernelImageForDevice + # This can happen with newer cards (e.g. sm_75) and compiling with older + # versions of nvcc (e.g. 9.2) that do not support their specific arch. + list(LENGTH EIGEN_CUDA_COMPUTE_ARCH EIGEN_CUDA_COMPUTE_ARCH_SIZE) + if(EIGEN_CUDA_COMPUTE_ARCH_SIZE) + list(GET EIGEN_CUDA_COMPUTE_ARCH 0 EIGEN_CUDA_COMPUTE_DEFAULT) + set(NVCC_ARCH_FLAGS " -arch=sm_${EIGEN_CUDA_COMPUTE_DEFAULT}") + endif() foreach(ARCH IN LISTS EIGEN_CUDA_COMPUTE_ARCH) string(APPEND NVCC_ARCH_FLAGS " -gencode arch=compute_${ARCH},code=sm_${ARCH}") endforeach() @@ -416,34 +425,44 @@ endif() option(EIGEN_TEST_HIP "Add HIP support." OFF) if (EIGEN_TEST_HIP) - set(HIP_PATH "/opt/rocm/hip" CACHE STRING "Path to the HIP installation.") - - if (EXISTS ${HIP_PATH}) + set(ROCM_PATH "/opt/rocm" CACHE STRING "Path to the ROCm installation.") + if (EXISTS ${ROCM_PATH}/hip) + set(HIP_PATH ${ROCM_PATH}/hip) list(APPEND CMAKE_MODULE_PATH ${HIP_PATH}/cmake) - - find_package(HIP REQUIRED) - if (HIP_FOUND) - - execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM) - - if ((${HIP_PLATFORM} STREQUAL "hcc") OR (${HIP_PLATFORM} STREQUAL "amd")) - - include_directories(${HIP_PATH}/include) - - set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu") - ei_add_test(gpu_basic) - unset(EIGEN_ADD_TEST_FILENAME_EXTENSION) - - elseif ((${HIP_PLATFORM} STREQUAL "nvcc") OR (${HIP_PLATFORM} STREQUAL "nvidia")) - message(FATAL_ERROR "HIP_PLATFORM = nvcc is not supported within Eigen") - else () - message(FATAL_ERROR "Unknown HIP_PLATFORM = ${HIP_PLATFORM}") - endif() - endif() + elseif (EXISTS ${ROCM_PATH}/lib/cmake/hip) + set(HIP_PATH ${ROCM_PATH}) + list(APPEND CMAKE_MODULE_PATH ${HIP_PATH}/lib/cmake/hip) else () - message(FATAL_ERROR "EIGEN_TEST_HIP is ON, but the specified HIP_PATH (${HIP_PATH}) does not exist") + message(FATAL_ERROR "EIGEN_TEST_HIP is ON, but could not find the ROCm installation under ${ROCM_PATH}") endif() + + find_package(HIP REQUIRED) + if (HIP_FOUND) + execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM) + + if ((${HIP_PLATFORM} STREQUAL "hcc") OR (${HIP_PLATFORM} STREQUAL "amd")) + + include_directories(${HIP_PATH}/include) + + set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu") + ei_add_test(gpu_basic) + unset(EIGEN_ADD_TEST_FILENAME_EXTENSION) + + elseif ((${HIP_PLATFORM} STREQUAL "nvcc") OR (${HIP_PLATFORM} STREQUAL "nvidia")) + message(FATAL_ERROR "HIP_PLATFORM = nvcc is not supported within Eigen") + else () + message(FATAL_ERROR "Unknown HIP_PLATFORM = ${HIP_PLATFORM}") + endif() + endif() +endif() + +if(EIGEN_TEST_SYCL) + set(EIGEN_SYCL ON) + include(SyclConfigureTesting) + + ei_add_test(sycl_basic) + set(EIGEN_SYCL OFF) endif() cmake_dependent_option(EIGEN_TEST_BUILD_DOCUMENTATION "Test building the doxygen documentation" OFF "EIGEN_BUILD_DOC" OFF) diff --git a/unsupported/CMakeLists.txt b/unsupported/CMakeLists.txt index 67d1f6262..390460181 100644 --- a/unsupported/CMakeLists.txt +++ b/unsupported/CMakeLists.txt @@ -4,7 +4,7 @@ if(EIGEN_BUILD_DOC) endif() if(EIGEN_BUILD_TESTING) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) - add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest + add_subdirectory(test) # CTest automatic test building relies on the "all" target. else() add_subdirectory(test EXCLUDE_FROM_ALL) endif() diff --git a/unsupported/Eigen/CMakeLists.txt b/unsupported/Eigen/CMakeLists.txt index 631a06014..10ec89c77 100644 --- a/unsupported/Eigen/CMakeLists.txt +++ b/unsupported/Eigen/CMakeLists.txt @@ -1,4 +1,4 @@ -set(Eigen_HEADERS +set(Eigen_HEADERS AdolcForward AlignedVector3 ArpackSupport @@ -6,7 +6,7 @@ set(Eigen_HEADERS BVH EulerAngles FFT - IterativeSolvers + IterativeSolvers KroneckerProduct LevenbergMarquardt MatrixFunctions diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt index ab5b684e9..1d5e9b174 100644 --- a/unsupported/test/CMakeLists.txt +++ b/unsupported/test/CMakeLists.txt @@ -112,84 +112,9 @@ ei_add_test(special_packetmath "-DEIGEN_FAST_MATH=1") if(EIGEN_TEST_CXX11) if(EIGEN_TEST_SYCL) set(EIGEN_SYCL ON) - # Forward CMake options as preprocessor definitions - if(EIGEN_SYCL_USE_DEFAULT_SELECTOR) - add_definitions(-DEIGEN_SYCL_USE_DEFAULT_SELECTOR=${EIGEN_SYCL_USE_DEFAULT_SELECTOR}) - endif() - if(EIGEN_SYCL_NO_LOCAL_MEM) - add_definitions(-DEIGEN_SYCL_NO_LOCAL_MEM=${EIGEN_SYCL_NO_LOCAL_MEM}) - endif() - if(EIGEN_SYCL_LOCAL_MEM) - add_definitions(-DEIGEN_SYCL_LOCAL_MEM=${EIGEN_SYCL_LOCAL_MEM}) - endif() - if(EIGEN_SYCL_MAX_GLOBAL_RANGE) - add_definitions(-DEIGEN_SYCL_MAX_GLOBAL_RANGE=${EIGEN_SYCL_MAX_GLOBAL_RANGE}) - endif() - if(EIGEN_SYCL_LOCAL_THREAD_DIM0) - add_definitions(-DEIGEN_SYCL_LOCAL_THREAD_DIM0=${EIGEN_SYCL_LOCAL_THREAD_DIM0}) - endif() - if(EIGEN_SYCL_LOCAL_THREAD_DIM1) - add_definitions(-DEIGEN_SYCL_LOCAL_THREAD_DIM1=${EIGEN_SYCL_LOCAL_THREAD_DIM1}) - endif() - if(EIGEN_SYCL_REG_M) - add_definitions(-DEIGEN_SYCL_REG_M=${EIGEN_SYCL_REG_M}) - endif() - if(EIGEN_SYCL_REG_N) - add_definitions(-DEIGEN_SYCL_REG_N=${EIGEN_SYCL_REG_N}) - endif() - if(EIGEN_SYCL_USE_PROGRAM_CLASS) - add_definitions(-DEIGEN_SYCL_USE_PROGRAM_CLASS=${EIGEN_SYCL_USE_PROGRAM_CLASS}) - endif() - if(EIGEN_SYCL_ASYNC_EXECUTION) - add_definitions(-DEIGEN_SYCL_ASYNC_EXECUTION=${EIGEN_SYCL_ASYNC_EXECUTION}) - endif() - if(EIGEN_SYCL_DISABLE_SKINNY) - add_definitions(-DEIGEN_SYCL_DISABLE_SKINNY=${EIGEN_SYCL_DISABLE_SKINNY}) - endif() - if(EIGEN_SYCL_DISABLE_DOUBLE_BUFFER) - add_definitions(-DEIGEN_SYCL_DISABLE_DOUBLE_BUFFER=${EIGEN_SYCL_DISABLE_DOUBLE_BUFFER}) - endif() - if(EIGEN_SYCL_DISABLE_RANK1) - add_definitions(-DEIGEN_SYCL_DISABLE_RANK1=${EIGEN_SYCL_DISABLE_RANK1}) - endif() - if(EIGEN_SYCL_DISABLE_SCALAR) - add_definitions(-DEIGEN_SYCL_DISABLE_SCALAR=${EIGEN_SYCL_DISABLE_SCALAR}) - endif() - if(EIGEN_SYCL_DISABLE_GEMV) - add_definitions(-DEIGEN_SYCL_DISABLE_GEMV=${EIGEN_SYCL_DISABLE_GEMV}) - endif() - if(EIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION) - add_definitions(-DEIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION=${EIGEN_SYCL_DISABLE_ARM_GPU_CACHE_OPTIMISATION}) - endif() - - if(EIGEN_SYCL_TRISYCL) - # triSYCL now requires c++17. - set(CMAKE_CXX_STANDARD 17) - else() - if(MSVC) - # Set the host and device compilers C++ standard to C++14. On Windows setting this to C++11 - # can cause issues with the ComputeCpp device compiler parsing Visual Studio Headers. - set(CMAKE_CXX_STANDARD 14) - list(APPEND COMPUTECPP_USER_FLAGS -DWIN32) - else() - set(CMAKE_CXX_STANDARD 11) - list(APPEND COMPUTECPP_USER_FLAGS -Wall) - endif() - # The following flags are not supported by Clang and can cause warnings - # if used with -Werror so they are removed here. - if(COMPUTECPP_USE_COMPILER_DRIVER) - set(CMAKE_CXX_COMPILER ${ComputeCpp_DEVICE_COMPILER_EXECUTABLE}) - string(REPLACE "-Wlogical-op" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - string(REPLACE "-Wno-psabi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - string(REPLACE "-ansi" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - endif() - list(APPEND COMPUTECPP_USER_FLAGS - -DEIGEN_NO_ASSERTION_CHECKING=1 - -no-serial-memop - -Xclang - -cl-mad-enable) - endif() + include(SyclConfigureTesting) + ei_add_test(cxx11_tensor_sycl ${STD_CXX_FLAG}) ei_add_test(cxx11_tensor_image_op_sycl ${STD_CXX_FLAG}) ei_add_test(cxx11_tensor_math_sycl ${STD_CXX_FLAG}) @@ -281,11 +206,11 @@ if(EIGEN_TEST_CXX11) ei_add_test(cxx11_tensor_thread_pool "-pthread" "${CMAKE_THREAD_LIBS_INIT}") ei_add_test(cxx11_tensor_trace) ei_add_test(cxx11_tensor_volume_patch) -# ei_add_test(cxx11_tensor_symmetry) -if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - # This test requires __uint128_t which is only available on 64bit systems - ei_add_test(cxx11_tensor_uint128) -endif() + # ei_add_test(cxx11_tensor_symmetry) + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # This test requires __uint128_t which is only available on 64bit systems + ei_add_test(cxx11_tensor_uint128) + endif() endif() @@ -311,6 +236,16 @@ if(CUDA_FOUND AND EIGEN_TEST_CUDA) else() set(CUDA_PROPAGATE_HOST_FLAGS OFF) set(NVCC_ARCH_FLAGS) + # Define an -arch=sm_, otherwise if GPU does not exactly match one of + # those in the arch list for -gencode, the kernels will fail to run with + # cudaErrorNoKernelImageForDevice + # This can happen with newer cards (e.g. sm_75) and compiling with older + # versions of nvcc (e.g. 9.2) that do not support their specific arch. + list(LENGTH EIGEN_CUDA_COMPUTE_ARCH EIGEN_CUDA_COMPUTE_ARCH_SIZE) + if(EIGEN_CUDA_COMPUTE_ARCH_SIZE) + list(GET EIGEN_CUDA_COMPUTE_ARCH 0 EIGEN_CUDA_COMPUTE_DEFAULT) + set(NVCC_ARCH_FLAGS " -arch=sm_${EIGEN_CUDA_COMPUTE_DEFAULT}") + endif() foreach(ARCH IN LISTS EIGEN_CUDA_COMPUTE_ARCH) string(APPEND NVCC_ARCH_FLAGS " -gencode arch=compute_${ARCH},code=sm_${ARCH}") endforeach() @@ -347,63 +282,57 @@ if(CUDA_FOUND AND EIGEN_TEST_CUDA) ei_add_test(cxx11_tensor_random_gpu) endif() - unset(EIGEN_ADD_TEST_FILENAME_EXTENSION) endif() # Add HIP specific tests if (EIGEN_TEST_HIP) - set(HIP_PATH "/opt/rocm/hip" CACHE STRING "Path to the HIP installation.") - - if (EXISTS ${HIP_PATH}) + set(ROCM_PATH "/opt/rocm" CACHE STRING "Path to the ROCm installation.") + if (EXISTS ${ROCM_PATH}/hip) + set(HIP_PATH ${ROCM_PATH}/hip) list(APPEND CMAKE_MODULE_PATH ${HIP_PATH}/cmake) - - find_package(HIP REQUIRED) - if (HIP_FOUND) - - execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM) - - if ((${HIP_PLATFORM} STREQUAL "hcc") OR (${HIP_PLATFORM} STREQUAL "amd")) - - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - include_directories(${HIP_PATH}/include) - - set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu") - # - # complex datatype is not yet supported by HIP - # so leaving out those tests for now - # - # ei_add_test(cxx11_tensor_complex_gpu) - # ei_add_test(cxx11_tensor_complex_cwise_ops_gpu) - # - ei_add_test(cxx11_tensor_reduction_gpu) - ei_add_test(cxx11_tensor_argmax_gpu) - ei_add_test(cxx11_tensor_cast_float16_gpu) - ei_add_test(cxx11_tensor_scan_gpu) - ei_add_test(cxx11_tensor_device) - - ei_add_test(cxx11_tensor_gpu) - ei_add_test(cxx11_tensor_contract_gpu) - ei_add_test(cxx11_tensor_of_float16_gpu) - ei_add_test(cxx11_tensor_random_gpu) - - unset(EIGEN_ADD_TEST_FILENAME_EXTENSION) - - elseif ((${HIP_PLATFORM} STREQUAL "nvcc") OR (${HIP_PLATFORM} STREQUAL "nvidia")) - message(FATAL_ERROR "HIP_PLATFORM = nvcc is not supported within Eigen") - else () - message(FATAL_ERROR "Unknown HIP_PLATFORM = ${HIP_PLATFORM}") - endif() - - endif() - + elseif (EXISTS ${ROCM_PATH}/lib/cmake/hip) + set(HIP_PATH ${ROCM_PATH}) + list(APPEND CMAKE_MODULE_PATH ${HIP_PATH}/lib/cmake/hip) else () - - message(FATAL_ERROR "EIGEN_TEST_HIP is ON, but the specified HIP_PATH (${HIP_PATH}) does not exist") - + message(FATAL_ERROR "EIGEN_TEST_HIP is ON, but could not find the ROCm installation under ${ROCM_PATH}") endif() -endif() + find_package(HIP REQUIRED) + if (HIP_FOUND) + execute_process(COMMAND ${HIP_PATH}/bin/hipconfig --platform OUTPUT_VARIABLE HIP_PLATFORM) + if ((${HIP_PLATFORM} STREQUAL "hcc") OR (${HIP_PLATFORM} STREQUAL "amd")) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + include_directories(${HIP_PATH}/include) + + set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu") + # + # complex datatype is not yet supported by HIP + # so leaving out those tests for now + # + # ei_add_test(cxx11_tensor_complex_gpu) + # ei_add_test(cxx11_tensor_complex_cwise_ops_gpu) + # + ei_add_test(cxx11_tensor_reduction_gpu) + ei_add_test(cxx11_tensor_argmax_gpu) + ei_add_test(cxx11_tensor_cast_float16_gpu) + ei_add_test(cxx11_tensor_scan_gpu) + ei_add_test(cxx11_tensor_device) + + ei_add_test(cxx11_tensor_gpu) + ei_add_test(cxx11_tensor_contract_gpu) + ei_add_test(cxx11_tensor_of_float16_gpu) + ei_add_test(cxx11_tensor_random_gpu) + + unset(EIGEN_ADD_TEST_FILENAME_EXTENSION) + + elseif ((${HIP_PLATFORM} STREQUAL "nvcc") OR (${HIP_PLATFORM} STREQUAL "nvidia")) + message(FATAL_ERROR "HIP_PLATFORM = nvcc is not supported within Eigen") + else () + message(FATAL_ERROR "Unknown HIP_PLATFORM = ${HIP_PLATFORM}") + endif() + endif() +endif()