From f5aa64086228ca9ccfa27e6086667fd0bdbad22c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 15 Jul 2015 10:57:55 +0200 Subject: [PATCH] Clean some previous changes and more cuda fixes --- Eigen/src/Core/DenseBase.h | 8 ++++---- Eigen/src/Core/GlobalFunctions.h | 3 --- Eigen/src/Core/MathFunctions.h | 2 -- Eigen/src/Core/MatrixBase.h | 2 +- Eigen/src/Core/VectorwiseOp.h | 4 ---- Eigen/src/Core/Visitor.h | 12 ++++++++---- Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h | 2 +- test/cuda_basic.cu | 9 ++++++--- 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index d486f3fd50..58f682dce0 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -491,10 +491,10 @@ template class DenseBase typedef VectorwiseOp ColwiseReturnType; typedef const VectorwiseOp ConstColwiseReturnType; - ConstRowwiseReturnType rowwise() const; - RowwiseReturnType rowwise(); - ConstColwiseReturnType colwise() const; - ColwiseReturnType colwise(); + EIGEN_DEVICE_FUNC ConstRowwiseReturnType rowwise() const; + EIGEN_DEVICE_FUNC RowwiseReturnType rowwise(); + EIGEN_DEVICE_FUNC ConstColwiseReturnType colwise() const; + EIGEN_DEVICE_FUNC ColwiseReturnType colwise(); typedef CwiseNullaryOp,PlainObject> RandomReturnType; static const RandomReturnType Random(Index rows, Index cols); diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 1f5caab4f6..15d92b8627 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -34,7 +34,6 @@ } \ }; - namespace Eigen { EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op) @@ -62,11 +61,9 @@ namespace Eigen EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op) -#ifndef __CUDACC__ EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op) -#endif template inline const Eigen::CwiseUnaryOp, const Derived> diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index fd65198559..fb2e2a5f1f 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -794,7 +794,6 @@ bool (isfinite)(const T& x) #endif } -#ifndef __CUDACC__ template bool (isfinite)(const std::complex& x) { @@ -812,7 +811,6 @@ bool (isinf)(const std::complex& x) { return (numext::isinf(numext::real(x)) || numext::isinf(numext::imag(x))) && (!numext::isnan(x)); } -#endif template EIGEN_DEVICE_FUNC diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8549cf83c0..7c66572d1b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -312,7 +312,7 @@ template class MatrixBase template inline const Derived& forceAlignedAccessIf() const { return derived(); } template inline Derived& forceAlignedAccessIf() { return derived(); } - Scalar trace() const; + EIGEN_DEVICE_FUNC Scalar trace() const; template EIGEN_DEVICE_FUNC RealScalar lpNorm() const; diff --git a/Eigen/src/Core/VectorwiseOp.h b/Eigen/src/Core/VectorwiseOp.h index 273361bcec..5ebcdc1001 100644 --- a/Eigen/src/Core/VectorwiseOp.h +++ b/Eigen/src/Core/VectorwiseOp.h @@ -644,7 +644,6 @@ template class VectorwiseOp * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting */ template -EIGEN_DEVICE_FUNC inline const typename DenseBase::ConstColwiseReturnType DenseBase::colwise() const { @@ -656,7 +655,6 @@ DenseBase::colwise() const * \sa rowwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting */ template -EIGEN_DEVICE_FUNC inline typename DenseBase::ColwiseReturnType DenseBase::colwise() { @@ -671,7 +669,6 @@ DenseBase::colwise() * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting */ template -EIGEN_DEVICE_FUNC inline const typename DenseBase::ConstRowwiseReturnType DenseBase::rowwise() const { @@ -683,7 +680,6 @@ DenseBase::rowwise() const * \sa colwise(), class VectorwiseOp, \ref TutorialReductionsVisitorsBroadcasting */ template -EIGEN_DEVICE_FUNC inline typename DenseBase::RowwiseReturnType DenseBase::rowwise() { diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 06c8bbf110..374972d3e3 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -22,6 +22,7 @@ struct visitor_impl row = (UnrollCount-1) % Derived::RowsAtCompileTime }; + EIGEN_DEVICE_FUNC static inline void run(const Derived &mat, Visitor& visitor) { visitor_impl::run(mat, visitor); @@ -32,6 +33,7 @@ struct visitor_impl template struct visitor_impl { + EIGEN_DEVICE_FUNC static inline void run(const Derived &mat, Visitor& visitor) { return visitor.init(mat.coeff(0, 0), 0, 0); @@ -41,6 +43,7 @@ struct visitor_impl template struct visitor_impl { + EIGEN_DEVICE_FUNC static inline void run(const Derived& mat, Visitor& visitor) { visitor.init(mat.coeff(0,0), 0, 0); @@ -57,6 +60,7 @@ template class visitor_evaluator { public: + EIGEN_DEVICE_FUNC explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) {} typedef typename XprType::Scalar Scalar; @@ -67,11 +71,11 @@ public: CoeffReadCost = internal::evaluator::CoeffReadCost }; - Index rows() const { return m_xpr.rows(); } - Index cols() const { return m_xpr.cols(); } - Index size() const { return m_xpr.size(); } + EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); } + EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); } + EIGEN_DEVICE_FUNC Index size() const { return m_xpr.size(); } - CoeffReturnType coeff(Index row, Index col) const + EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col) const { return m_evaluator.coeff(row, col); } protected: diff --git a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h index 8728668505..db6eba10d1 100644 --- a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +++ b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h @@ -654,7 +654,7 @@ template struct direct_selfadjoint_eigenvalues d1) { - std::swap(k,l); + numext::swap(k,l); d0 = d1; } diff --git a/test/cuda_basic.cu b/test/cuda_basic.cu index 300bced02f..6ec9446c68 100644 --- a/test/cuda_basic.cu +++ b/test/cuda_basic.cu @@ -53,14 +53,17 @@ struct redux { void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const { using namespace Eigen; - int N = 6; + int N = 10; T x1(in+i); out[i*N+0] = x1.minCoeff(); out[i*N+1] = x1.maxCoeff(); out[i*N+2] = x1.sum(); out[i*N+3] = x1.prod(); -// out[i*N+4] = x1.colwise().sum().maxCoeff(); -// out[i*N+5] = x1.rowwise().maxCoeff().sum(); + out[i*N+4] = x1.matrix().squaredNorm(); + out[i*N+5] = x1.matrix().norm(); + out[i*N+6] = x1.colwise().sum().maxCoeff(); + out[i*N+7] = x1.rowwise().maxCoeff().sum(); + out[i*N+8] = x1.matrix().colwise().squaredNorm().sum(); } };