From 3055e3a7c213e7f1337cdc43d5b1953acd013897 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Wed, 8 Aug 2018 11:19:02 +0100 Subject: Creating a pointer type in TensorCustomOp.h --- .../Eigen/CXX11/src/Tensor/TensorCustomOp.h | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index 47b5a5a5e..87d84a311 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -88,6 +88,7 @@ struct TensorEvaluator, Devi typedef typename internal::remove_const::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; + typedef typename internal::remove_all::PointerType>::type * PointerType; enum { IsAligned = false, @@ -106,7 +107,7 @@ struct TensorEvaluator, Devi EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType* data) { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(PointerType data) { if (data) { evalTo(data); return false; @@ -139,23 +140,22 @@ struct TensorEvaluator, Devi return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); } - EIGEN_DEVICE_FUNC typename Eigen::internal::traits::PointerType data() const { return m_result; } + EIGEN_DEVICE_FUNC PointerType data() const { return m_result; } #ifdef EIGEN_USE_SYCL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device& device() const { return m_device; } #endif protected: - EIGEN_DEVICE_FUNC void evalTo(Scalar* data) { - TensorMap > result( - data, m_dimensions); + EIGEN_DEVICE_FUNC void evalTo(PointerType data) { + TensorMap > result(data, m_dimensions); m_op.func().eval(m_op.expression(), result, m_device); } Dimensions m_dimensions; const ArgType m_op; const Device& m_device; - CoeffReturnType* m_result; + PointerType m_result; }; @@ -250,6 +250,7 @@ struct TensorEvaluator::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; + typedef typename internal::remove_all::PointerType>::type * PointerType; enum { IsAligned = false, @@ -268,12 +269,12 @@ struct TensorEvaluator(m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar))); + m_result = static_cast(m_device.allocate_temp(dimensions().TotalSize() * sizeof(CoeffReturnType))); evalTo(m_result); return true; } @@ -300,22 +301,22 @@ struct TensorEvaluator::PointerType data() const { return m_result; } + EIGEN_DEVICE_FUNC PointerType data() const { return m_result; } #ifdef EIGEN_USE_SYCL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device& device() const { return m_device; } #endif protected: - EIGEN_DEVICE_FUNC void evalTo(Scalar* data) { - TensorMap > result(data, m_dimensions); + EIGEN_DEVICE_FUNC void evalTo(PointerType data) { + TensorMap > result(data, m_dimensions); m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(), result, m_device); } Dimensions m_dimensions; const XprType m_op; const Device& m_device; - CoeffReturnType* m_result; + PointerType m_result; }; -- cgit v1.2.3 From 8c083bfd0e975fc2592ced1a066e1796550338a2 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 9 Aug 2018 13:57:43 +0100 Subject: Properly fixing the PointerType for TensorCustomOp.h. As the output type here should be based on CoeffreturnType not the Scalar type. Therefore, Similar to reduction and evalTo function, it should have its own MakePointer class. In this case, for other device the type is defaulted to CoeffReturnType and no changes is required on users' code. However, in SYCL, on the device, we can recunstruct the device Type. --- .../Eigen/CXX11/src/Tensor/TensorCustomOp.h | 77 +++++++++++++--------- .../CXX11/src/Tensor/TensorForwardDeclarations.h | 4 +- 2 files changed, 48 insertions(+), 33 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index 87d84a311..39410e63d 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -20,8 +20,8 @@ namespace Eigen { * */ namespace internal { -template -struct traits > +template class MakePointer_> +struct traits > { typedef typename XprType::Scalar Scalar; typedef typename XprType::StorageKind StorageKind; @@ -30,27 +30,35 @@ struct traits > typedef typename remove_reference::type _Nested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; - typedef typename traits::PointerType PointerType; + + template struct MakePointer { + // Intermediate typedef to workaround MSVC issue. + typedef MakePointer_ MakePointerT; + typedef typename MakePointerT::Type Type; + typedef typename MakePointerT::RefType RefType; + typedef typename MakePointerT::ScalarType ScalarType; + }; + typedef typename MakePointer::type>::Type PointerType; }; -template -struct eval, Eigen::Dense> +template class MakePointer_> +struct eval, Eigen::Dense> { - typedef const TensorCustomUnaryOp& type; + typedef const TensorCustomUnaryOp& type; }; -template -struct nested > +template class MakePointer_> +struct nested > { - typedef TensorCustomUnaryOp type; + typedef TensorCustomUnaryOp type; }; } // end namespace internal -template -class TensorCustomUnaryOp : public TensorBase, ReadOnlyAccessors> +template class MakePointer_> +class TensorCustomUnaryOp : public TensorBase, ReadOnlyAccessors> { public: typedef typename internal::traits::Scalar Scalar; @@ -77,10 +85,10 @@ class TensorCustomUnaryOp : public TensorBase -struct TensorEvaluator, Device> +template class MakePointer_, typename Device> +struct TensorEvaluator, Device> { - typedef TensorCustomUnaryOp ArgType; + typedef TensorCustomUnaryOp ArgType; typedef typename internal::traits::Index Index; static const int NumDims = internal::traits::NumDimensions; typedef DSizes Dimensions; @@ -88,7 +96,7 @@ struct TensorEvaluator, Devi typedef typename internal::remove_const::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; - typedef typename internal::remove_all::PointerType>::type * PointerType; + typedef typename Eigen::internal::traits::PointerType PointerType; enum { IsAligned = false, @@ -112,7 +120,7 @@ struct TensorEvaluator, Devi evalTo(data); return false; } else { - m_result = static_cast( + m_result = static_cast( m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar))); evalTo(m_result); return true; @@ -168,8 +176,8 @@ struct TensorEvaluator, Devi * */ namespace internal { -template -struct traits > +template class MakePointer_> +struct traits > { typedef typename internal::promote_storage_type::ret Scalar; @@ -185,28 +193,35 @@ struct traits > typedef typename remove_reference::type _RhsNested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; - typedef typename conditional::val, - typename traits::PointerType, typename traits::PointerType>::type PointerType; + + template struct MakePointer { + // Intermediate typedef to workaround MSVC issue. + typedef MakePointer_ MakePointerT; + typedef typename MakePointerT::Type Type; + typedef typename MakePointerT::RefType RefType; + typedef typename MakePointerT::ScalarType ScalarType; + }; + typedef typename MakePointer::Type PointerType; }; -template -struct eval, Eigen::Dense> +template class MakePointer_> +struct eval, Eigen::Dense> { typedef const TensorCustomBinaryOp& type; }; -template -struct nested > +template class MakePointer_> +struct nested > { - typedef TensorCustomBinaryOp type; + typedef TensorCustomBinaryOp type; }; } // end namespace internal -template -class TensorCustomBinaryOp : public TensorBase, ReadOnlyAccessors> +template class MakePointer_> +class TensorCustomBinaryOp : public TensorBase, ReadOnlyAccessors> { public: typedef typename internal::traits::Scalar Scalar; @@ -239,10 +254,10 @@ class TensorCustomBinaryOp : public TensorBase -struct TensorEvaluator, Device> +template class MakePointer_, typename Device> +struct TensorEvaluator, Device> { - typedef TensorCustomBinaryOp XprType; + typedef TensorCustomBinaryOp XprType; typedef typename internal::traits::Index Index; static const int NumDims = internal::traits::NumDimensions; typedef DSizes Dimensions; @@ -250,7 +265,7 @@ struct TensorEvaluator::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; - typedef typename internal::remove_all::PointerType>::type * PointerType; + typedef typename Eigen::internal::traits::PointerType PointerType; enum { IsAligned = false, diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h b/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h index 0dd524a30..da0751039 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h @@ -89,8 +89,8 @@ template class TensorAssignOp; template class TensorScanOp; template class TensorTraceOp; -template class TensorCustomUnaryOp; -template class TensorCustomBinaryOp; +template class MakePointer_ = MakePointer> class TensorCustomUnaryOp; +template class MakePointer_ = MakePointer> class TensorCustomBinaryOp; template class MakePointer_ = MakePointer> class TensorEvalToOp; template class TensorForcedEvalOp; -- cgit v1.2.3 From d0b01ebbf63f0594760b6e1568bec0228987157a Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 16 Aug 2018 13:21:36 +0100 Subject: Reverting the unitended delete from the code. --- unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index ab5990c14..dde1b449e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -30,6 +30,7 @@ struct traits > typedef typename remove_reference::type _Nested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; + typedef typename traits::PointerType PointerType; }; @@ -185,6 +186,8 @@ struct traits > typedef typename remove_reference::type _RhsNested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; + typedef typename conditional::val, + typename traits::PointerType, typename traits::PointerType>::type PointerType; }; -- cgit v1.2.3 From 80f1a76dec9a5fbe4305633ab0c8797a876e4ab5 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 16 Aug 2018 13:33:24 +0100 Subject: removing the noises. --- unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index dde1b449e..cbec5e9b4 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -31,7 +31,6 @@ struct traits > static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; typedef typename traits::PointerType PointerType; - }; template @@ -188,7 +187,6 @@ struct traits > static const int Layout = traits::Layout; typedef typename conditional::val, typename traits::PointerType, typename traits::PointerType>::type PointerType; - }; template -- cgit v1.2.3