diff --git a/Eigen/src/Core/arch/GPU/PacketMath.h b/Eigen/src/Core/arch/GPU/PacketMath.h index 6d4230aa7..328b1b93f 100644 --- a/Eigen/src/Core/arch/GPU/PacketMath.h +++ b/Eigen/src/Core/arch/GPU/PacketMath.h @@ -31,6 +31,15 @@ namespace internal { #define EIGEN_GPU_HAS_FP16_ARITHMETIC 1 #endif +// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler, +// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation +// of the functions, while the latter can only deal with one of them. +#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) +#define EIGEN_HAS_GPU_DEVICE_FUNCTIONS 1 +#else +#define EIGEN_HAS_GPU_DEVICE_FUNCTIONS 0 +#endif + // Make sure this is only available when targeting a GPU: we don't want to // introduce conflicts between these packet_traits definitions and the ones // we'll use on the host side (SSE, AVX, ...) @@ -74,7 +83,10 @@ struct packet_traits : default_packet_traits { HasGammaSampleDerAlpha = 1, HasIGammac = 1, HasBetaInc = 1, - HasBlend = 0 + + HasBlend = 0, + HasFloor = 1, + HasCmp = EIGEN_HAS_GPU_DEVICE_FUNCTIONS }; }; @@ -143,10 +155,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pset1(const double& from) return make_double2(from, from); } -// We need to distinguish ‘clang as the CUDA compiler’ from ‘clang as the host compiler, -// invoked by NVCC’ (e.g. on MacOS). The former needs to see both host and device implementation -// of the functions, while the latter can only deal with one of them. -#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC) +#if EIGEN_HAS_GPU_DEVICE_FUNCTIONS EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float bitwise_and(const float& a, const float& b) { return __int_as_float(__float_as_int(a) & __float_as_int(b)); @@ -259,8 +268,7 @@ template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2 pcmp_le(const double2& a, const double2& b) { return make_double2(le_mask(a.x, b.x), le_mask(a.y, b.y)); } -#endif // defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIPCC) || (defined(EIGEN_CUDACC) && EIGEN_COMP_CLANG && - // !EIGEN_COMP_NVCC) +#endif // EIGEN_HAS_GPU_DEVICE_FUNCTIONS template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 plset(const float& a) { diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h b/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h index 26cd38eb3..3c65541b8 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h @@ -274,6 +274,10 @@ struct simpl_chol_helper { } }; +// Symbol is ODR-used, so we need a definition. +template +constexpr StorageIndex simpl_chol_helper::kEmpty; + } // namespace internal template diff --git a/test/AnnoyingScalar.h b/test/AnnoyingScalar.h index 00a20c7c7..9e320eacd 100644 --- a/test/AnnoyingScalar.h +++ b/test/AnnoyingScalar.h @@ -16,7 +16,7 @@ #pragma GCC diagnostic ignored "-Wshadow" #endif -#ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW +#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW) struct my_exception { my_exception() {} ~my_exception() {} @@ -76,7 +76,7 @@ class AnnoyingScalar { } AnnoyingScalar operator+(const AnnoyingScalar& other) const { -#ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW +#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW) countdown--; if (countdown <= 0 && !dont_throw) throw my_exception(); #endif diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index cf0e6e4b7..6ff8d67be 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -1340,7 +1340,7 @@ EIGEN_DECLARE_TEST(array_cwise) { CALL_SUBTEST_3(array_generic(Array44d())); CALL_SUBTEST_4(array_generic( ArrayXXcf(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); - CALL_SUBTEST_7(array_generic( + CALL_SUBTEST_5(array_generic( ArrayXXf(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); CALL_SUBTEST_8(array_generic( ArrayXXi(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); diff --git a/test/exceptions.cpp b/test/exceptions.cpp index e3a5893d5..751e29152 100644 --- a/test/exceptions.cpp +++ b/test/exceptions.cpp @@ -8,7 +8,7 @@ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // Various sanity tests with exceptions and non trivially copyable scalar type. -// - no memory leak when a custom scalar type trow an exceptions +// - no memory leak when a custom scalar type throw an exceptions // - todo: complete the list of tests! #define EIGEN_STACK_ALLOCATION_LIMIT 100000000 @@ -21,9 +21,8 @@ AnnoyingScalar::countdown = 100; \ int before = AnnoyingScalar::instances; \ bool exception_thrown = false; \ - try { \ - OP; \ - } catch (my_exception) { \ + EIGEN_TRY { OP; } \ + EIGEN_CATCH(my_exception) { \ exception_thrown = true; \ VERIFY(AnnoyingScalar::instances == before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \ } \ @@ -35,7 +34,11 @@ EIGEN_DECLARE_TEST(exceptions) { typedef Eigen::Matrix MatrixType; { +#if defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW) AnnoyingScalar::dont_throw = false; +#else + AnnoyingScalar::dont_throw = true; +#endif int n = 50; VectorType v0(n), v1(n); MatrixType m0(n, n), m1(n, n), m2(n, n); diff --git a/test/main.h b/test/main.h index a8e951f8b..2288778f4 100644 --- a/test/main.h +++ b/test/main.h @@ -343,7 +343,7 @@ static std::vector eigen_assert_list; #if !defined(EIGEN_TESTING_CONSTEXPR) && !defined(EIGEN_TESTING_PLAINOBJECT_CTOR) #define EIGEN_INTERNAL_DEBUGGING #endif -#include // required for createRandomPIMatrixOfRank and generateRandomMatrixSvs +#include inline void verify_impl(bool condition, const char* testname, const char* file, int line, const char* condition_as_string) { @@ -935,3 +935,7 @@ int main(int argc, char* argv[]) { #endif #include "gpu_test_helper.h" + +#ifndef EIGEN_TEST_MAX_SIZE +#define EIGEN_TEST_MAX_SIZE 320 +#endif diff --git a/test/maxsizevector.cpp b/test/maxsizevector.cpp index 7fe691a74..82aa25761 100644 --- a/test/maxsizevector.cpp +++ b/test/maxsizevector.cpp @@ -1,6 +1,8 @@ #include "main.h" +#ifdef EIGEN_EXCEPTIONS #include // std::exception +#endif #include @@ -31,28 +33,27 @@ struct Foo { std::cout << '~'; --Foo::object_count; } - +#ifdef EIGEN_EXCEPTIONS class Fail : public std::exception {}; +#endif }; Index Foo::object_count = 0; Index Foo::object_limit = 0; -EIGEN_DECLARE_TEST(cxx11_maxsizevector) { +EIGEN_DECLARE_TEST(maxsizevector) { typedef MaxSizeVector VectorX; Foo::object_count = 0; for (int r = 0; r < g_repeat; r++) { Index rows = internal::random(3, 30); Foo::object_limit = internal::random(0, rows - 2); std::cout << "object_limit = " << Foo::object_limit << std::endl; - bool exception_raised = false; #ifdef EIGEN_EXCEPTIONS + bool exception_raised = false; try { -#endif std::cout << "\nVectorX m(" << rows << ");\n"; VectorX vect(rows); for (int i = 0; i < rows; ++i) vect.push_back(Foo()); -#ifdef EIGEN_EXCEPTIONS VERIFY(false); // not reached if exceptions are enabled } catch (const Foo::Fail&) { exception_raised = true; diff --git a/test/redux.cpp b/test/redux.cpp index c9c397842..71ef535ef 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -182,8 +182,8 @@ EIGEN_DECLARE_TEST(redux) { CALL_SUBTEST_5(matrixRedux(ArrayXX(rows, cols))); CALL_SUBTEST_6(matrixRedux(MatrixXcf(rows, cols))); CALL_SUBTEST_6(matrixRedux(ArrayXXcf(rows, cols))); - CALL_SUBTEST_6(matrixRedux(MatrixXcd(rows, cols))); - CALL_SUBTEST_6(matrixRedux(ArrayXXcd(rows, cols))); + CALL_SUBTEST_7(matrixRedux(MatrixXcd(rows, cols))); + CALL_SUBTEST_7(matrixRedux(ArrayXXcd(rows, cols))); } for (int i = 0; i < g_repeat; i++) { int size = internal::random(1, maxsize); diff --git a/test/sizeoverflow.cpp b/test/sizeoverflow.cpp index 66f820f61..612067f16 100644 --- a/test/sizeoverflow.cpp +++ b/test/sizeoverflow.cpp @@ -9,6 +9,7 @@ #include "main.h" +#ifdef EIGEN_EXCEPTIONS #define VERIFY_THROWS_BADALLOC(a) \ { \ bool threw = false; \ @@ -19,6 +20,10 @@ } \ VERIFY(threw && "should have thrown bad_alloc: " #a); \ } +#else +// No way to catch a bad alloc - program terminates. +#define VERIFY_THROWS_BADALLOC(a) +#endif template void triggerMatrixBadAlloc(Index rows, Index cols) { diff --git a/test/svd_common.h b/test/svd_common.h index dd520f541..5174adec0 100644 --- a/test/svd_common.h +++ b/test/svd_common.h @@ -381,6 +381,7 @@ void svd_verify_assert_full_only(const MatrixType& input = MatrixType()) { typedef Matrix RhsType; RhsType rhs = RhsType::Zero(input.rows()); + EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled. MatrixType m(input.rows(), input.cols()); svd_fill_random(m); @@ -410,6 +411,7 @@ void svd_verify_assert(const MatrixType& input = MatrixType()) { enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime }; typedef Matrix RhsType; RhsType rhs = RhsType::Zero(input.rows()); + EIGEN_UNUSED_VARIABLE(rhs); // Only used if asserts are enabled. MatrixType m(input.rows(), input.cols()); svd_fill_random(m); diff --git a/test/zerosized.cpp b/test/zerosized.cpp index 700132796..2df2f297e 100644 --- a/test/zerosized.cpp +++ b/test/zerosized.cpp @@ -24,6 +24,8 @@ void zeroReduction(const MatrixType& m) { VERIFY_RAISES_ASSERT(m.minCoeff()); VERIFY_RAISES_ASSERT(m.maxCoeff()); Index i, j; + EIGEN_UNUSED_VARIABLE(i); // Only used if exceptions are enabled. + EIGEN_UNUSED_VARIABLE(j); VERIFY_RAISES_ASSERT(m.minCoeff(&i, &j)); VERIFY_RAISES_ASSERT(m.maxCoeff(&i, &j)); VERIFY_RAISES_ASSERT(m.reshaped().minCoeff(&i)); diff --git a/unsupported/Eigen/CXX11/Tensor b/unsupported/Eigen/CXX11/Tensor index 290a0c029..7375a9b42 100644 --- a/unsupported/Eigen/CXX11/Tensor +++ b/unsupported/Eigen/CXX11/Tensor @@ -45,7 +45,7 @@ #include #if defined(EIGEN_USE_THREADS) || defined(EIGEN_USE_SYCL) -#include "ThreadPool" +#include "../../../Eigen/ThreadPool" #endif #ifdef EIGEN_USE_GPU