diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index 9611b58162b..647c3db6a07 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -641,69 +641,91 @@ class PlainObjectBase : public internal::dense_xpr_base::type * \see class Map */ //@{ + EIGEN_DEVICE_FUNC static inline ConstMapType Map(const Scalar* data) { return ConstMapType(data); } + EIGEN_DEVICE_FUNC static inline MapType Map(Scalar* data) { return MapType(data); } + EIGEN_DEVICE_FUNC static inline ConstMapType Map(const Scalar* data, Index size) { return ConstMapType(data, size); } EIGEN_DEVICE_FUNC static inline MapType Map(Scalar* data, Index size) { return MapType(data, size); } + EIGEN_DEVICE_FUNC static inline ConstMapType Map(const Scalar* data, Index rows, Index cols) { return ConstMapType(data, rows, cols); } EIGEN_DEVICE_FUNC static inline MapType Map(Scalar* data, Index rows, Index cols) { return MapType(data, rows, cols); } + EIGEN_DEVICE_FUNC static inline ConstAlignedMapType MapAligned(const Scalar* data) { return ConstAlignedMapType(data); } + EIGEN_DEVICE_FUNC static inline AlignedMapType MapAligned(Scalar* data) { return AlignedMapType(data); } + EIGEN_DEVICE_FUNC static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size) { return ConstAlignedMapType(data, size); } + EIGEN_DEVICE_FUNC static inline AlignedMapType MapAligned(Scalar* data, Index size) { return AlignedMapType(data, size); } + EIGEN_DEVICE_FUNC static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) { return ConstAlignedMapType(data, rows, cols); } + EIGEN_DEVICE_FUNC static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) { return AlignedMapType(data, rows, cols); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstMapType >::type Map(const Scalar* data, const Stride& stride) { return typename StridedConstMapType >::type(data, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedMapType >::type Map(Scalar* data, const Stride& stride) { return typename StridedMapType >::type(data, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstMapType >::type Map(const Scalar* data, Index size, const Stride& stride) { return typename StridedConstMapType >::type(data, size, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedMapType >::type Map(Scalar* data, Index size, const Stride& stride) { return typename StridedMapType >::type(data, size, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstMapType >::type Map(const Scalar* data, Index rows, Index cols, const Stride& stride) { return typename StridedConstMapType >::type(data, rows, cols, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedMapType >::type Map(Scalar* data, Index rows, Index cols, const Stride& stride) { return typename StridedMapType >::type(data, rows, cols, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstAlignedMapType >::type MapAligned(const Scalar* data, const Stride& stride) { return typename StridedConstAlignedMapType >::type(data, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedAlignedMapType >::type MapAligned(Scalar* data, const Stride& stride) { return typename StridedAlignedMapType >::type(data, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstAlignedMapType >::type MapAligned(const Scalar* data, Index size, const Stride& stride) { return typename StridedConstAlignedMapType >::type(data, size, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedAlignedMapType >::type MapAligned(Scalar* data, Index size, const Stride& stride) { return typename StridedAlignedMapType >::type(data, size, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedConstAlignedMapType >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride& stride) { return typename StridedConstAlignedMapType >::type(data, rows, cols, stride); } template + EIGEN_DEVICE_FUNC static inline typename StridedAlignedMapType >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride& stride) { return typename StridedAlignedMapType >::type(data, rows, cols, stride); } //@} diff --git a/Eigen/src/Core/Solve.h b/Eigen/src/Core/Solve.h index 87af2957dfc..53daebd93fb 100644 --- a/Eigen/src/Core/Solve.h +++ b/Eigen/src/Core/Solve.h @@ -65,6 +65,7 @@ class Solve : public SolveImpl::PlainObject PlainObject; typedef typename internal::traits::StorageIndex StorageIndex; + EIGEN_DEVICE_FUNC Solve(const Decomposition &dec, const RhsType &rhs) : m_dec(dec), m_rhs(rhs) {} diff --git a/Eigen/src/Core/SolverBase.h b/Eigen/src/Core/SolverBase.h index 99bb9b52f0a..9e1d54f20c5 100644 --- a/Eigen/src/Core/SolverBase.h +++ b/Eigen/src/Core/SolverBase.h @@ -17,6 +17,7 @@ namespace internal { template struct solve_assertion { template + EIGEN_DEVICE_FUNC static void run(const Derived& solver, const Rhs& b) { solver.template _check_solve_assertion(b); } }; @@ -26,6 +27,7 @@ struct solve_assertion > typedef Transpose type; template + EIGEN_DEVICE_FUNC static void run(const type& transpose, const Rhs& b) { internal::solve_assertion::type>::template run(transpose.nestedExpression(), b); @@ -38,6 +40,7 @@ struct solve_assertion typedef CwiseUnaryOp, const Transpose > type; template + EIGEN_DEVICE_FUNC static void run(const type& adjoint, const Rhs& b) { internal::solve_assertion >::type>::template run(adjoint.nestedExpression(), b); @@ -105,6 +108,7 @@ class SolverBase : public EigenBase */ template inline const Solve + EIGEN_DEVICE_FUNC solve(const MatrixBase& b) const { internal::solve_assertion::type>::template run(derived(), b); @@ -147,6 +151,7 @@ class SolverBase : public EigenBase protected: template + EIGEN_DEVICE_FUNC void _check_solve_assertion(const Rhs& b) const { EIGEN_ONLY_USED_FOR_DEBUG(b); eigen_assert(derived().m_isInitialized && "Solver is not initialized."); diff --git a/Eigen/src/Core/products/GeneralBlockPanelKernel.h b/Eigen/src/Core/products/GeneralBlockPanelKernel.h index 8b1f3af767f..25737ce1bff 100644 --- a/Eigen/src/Core/products/GeneralBlockPanelKernel.h +++ b/Eigen/src/Core/products/GeneralBlockPanelKernel.h @@ -432,10 +432,10 @@ template struct QuadPacket { Packet B_0, B1, B2, B3; - const Packet& get(const FixedInt<0>&) const { return B_0; } - const Packet& get(const FixedInt<1>&) const { return B1; } - const Packet& get(const FixedInt<2>&) const { return B2; } - const Packet& get(const FixedInt<3>&) const { return B3; } + EIGEN_DEVICE_FUNC const Packet& get(const FixedInt<0>&) const { return B_0; } + EIGEN_DEVICE_FUNC const Packet& get(const FixedInt<1>&) const { return B1; } + EIGEN_DEVICE_FUNC const Packet& get(const FixedInt<2>&) const { return B2; } + EIGEN_DEVICE_FUNC const Packet& get(const FixedInt<3>&) const { return B3; } }; template @@ -1240,7 +1240,8 @@ struct last_row_process_16_packets typedef typename SwappedTraits::ResPacket SResPacket; typedef typename SwappedTraits::AccPacket SAccPacket; - EIGEN_STRONG_INLINE void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA, + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + void operator()(const DataMapper& res, SwappedTraits &straits, const LhsScalar* blA, const RhsScalar* blB, Index depth, const Index endk, Index i, Index j2, ResScalar alpha, SAccPacket &C0) { diff --git a/Eigen/src/Core/util/IntegralConstant.h b/Eigen/src/Core/util/IntegralConstant.h index caeea232df3..ac39b7f0ef1 100644 --- a/Eigen/src/Core/util/IntegralConstant.h +++ b/Eigen/src/Core/util/IntegralConstant.h @@ -52,41 +52,56 @@ template class FixedInt { public: static const int value = N; - operator int() const { return value; } - FixedInt() {} - FixedInt( VariableAndFixedInt other) { + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC operator int() const { return value; } + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt() {} +#if EIGEN_HAS_CXX14 + EIGEN_CONSTEXPR +#endif + EIGEN_DEVICE_FUNC FixedInt(VariableAndFixedInt other) { #ifndef EIGEN_INTERNAL_DEBUGGING EIGEN_UNUSED_VARIABLE(other); #endif eigen_internal_assert(int(other)==N); } + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt<-N> operator-() const { return FixedInt<-N>(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator+( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator-( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator*( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator/( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator%( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator|( FixedInt) const { return FixedInt(); } template + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator&( FixedInt) const { return FixedInt(); } #if EIGEN_HAS_CXX14 // Needed in C++14 to allow fix(): + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt operator() () const { return *this; } + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC VariableAndFixedInt operator() (int val) const { return VariableAndFixedInt(val); } #else + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt ( FixedInt (*)() ) {} #endif #if EIGEN_HAS_CXX11 + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC FixedInt(std::integral_constant) {} #endif }; @@ -124,8 +139,8 @@ template class VariableAndFixedInt { public: static const int value = N; - operator int() const { return m_value; } - VariableAndFixedInt(int val) { m_value = val; } + EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC operator int() const { return m_value; } + EIGEN_DEVICE_FUNC VariableAndFixedInt(int val) { m_value = val; } protected: int m_value; }; @@ -153,9 +168,14 @@ struct get_fixed_value,Default> { static const int value = N; }; -template EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x) { return x; } +template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC +Index get_runtime_value(const T &x) { return x; } + #if !EIGEN_HAS_CXX14 -template EIGEN_DEVICE_FUNC Index get_runtime_value(FixedInt (*)()) { return N; } +template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC +Index get_runtime_value(FixedInt (*)()) { return N; } #endif // Cleanup integer/FixedInt/VariableAndFixedInt/etc types: @@ -186,14 +206,17 @@ template struct cleanup_index_type +EIGEN_DEVICE_CONST static const internal::FixedInt fix{}; #else template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC inline internal::FixedInt fix() { return internal::FixedInt(); } // The generic typename T is mandatory. Otherwise, a code like fix could refer to either the function above or this next overload. // This way a code like fix can only refer to the previous function. template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC inline internal::VariableAndFixedInt fix(T val) { return internal::VariableAndFixedInt(internal::convert_index(val)); } #endif @@ -232,6 +255,7 @@ inline internal::VariableAndFixedInt fix(T val) { return internal::VariableAn * \sa fix(int), seq, seqN */ template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC static const auto fix(); /** \fn fix(int) @@ -263,6 +287,7 @@ static const auto fix(); * \sa fix, seqN, class ArithmeticSequence */ template +EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC static const auto fix(int val); #endif // EIGEN_PARSED_BY_DOXYGEN diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 5d10ba0eb1e..7e22a46ea98 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -970,6 +970,12 @@ #define EIGEN_DEVICE_FUNC #endif +// Define compile-time constants for use by both the host and device functions +#if defined(EIGEN_CUDA_ARCH) || defined(EIGEN_HIP_DEVICE_COMPILE) + #define EIGEN_DEVICE_CONST __device__ +#else + #define EIGEN_DEVICE_CONST +#endif // this macro allows to get rid of linking errors about multiply defined functions. // - static is not very good because it prevents definitions from different object files to be merged.