From 647a51b42658d1b7346581d77b63240325b8402a Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 18 Aug 2016 12:31:02 -0700 Subject: Force the inlining of a simple accessor. --- unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h index c2a327bf0..33ffaa600 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h @@ -574,7 +574,7 @@ struct TensorEvaluator .cwiseMax(m_elseImpl.costPerCoeff(vectorized)); } - EIGEN_DEVICE_FUNC CoeffReturnType* data() const { return NULL; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType* data() const { return NULL; } private: TensorEvaluator m_condImpl; -- cgit v1.2.3 From 46475eff9a9b2c48918996386db6ae0c55801ba8 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 1 Sep 2016 13:40:45 +0200 Subject: Adjust Tensor module wrt recent change in nullary functor --- .../Eigen/CXX11/src/Tensor/TensorEvaluator.h | 7 +- .../Eigen/CXX11/src/Tensor/TensorFunctors.h | 78 +++++++++------------- 2 files changed, 37 insertions(+), 48 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h index 33ffaa600..5f44dc863 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h @@ -226,7 +226,7 @@ struct TensorEvaluator, Device> EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device) - : m_functor(op.functor()), m_argImpl(op.nestedExpression(), device) + : m_functor(op.functor()), m_argImpl(op.nestedExpression(), device), m_wrapper() { } typedef typename XprType::Index Index; @@ -243,13 +243,13 @@ struct TensorEvaluator, Device> EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const { - return m_functor(index); + return m_wrapper(m_functor,index); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { - return m_functor.template packetOp(index); + return m_wrapper.template packetOp(m_functor,index); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost @@ -263,6 +263,7 @@ struct TensorEvaluator, Device> private: const NullaryOp m_functor; TensorEvaluator m_argImpl; + const internal::nullary_wrapper m_wrapper; }; diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h index 6a6700cf0..f73178b30 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h @@ -460,12 +460,11 @@ template class UniformRandomGenerator { m_deterministic = other.m_deterministic; } - template - T operator()(Index) const { + T operator()() const { return random(); } - template - PacketType packetOp(Index) const { + template + PacketType packetOp() const { const int packetSize = internal::unpacket_traits::size; EIGEN_ALIGN_MAX T values[packetSize]; for (int i = 0; i < packetSize; ++i) { @@ -490,23 +489,22 @@ template <> class UniformRandomGenerator { } UniformRandomGenerator(const UniformRandomGenerator& other) { m_generator = new std::mt19937(); - m_generator->seed(other(0) * UINT_MAX); + m_generator->seed(other() * UINT_MAX); m_deterministic = other.m_deterministic; } ~UniformRandomGenerator() { delete m_generator; } - template - float operator()(Index) const { + float operator()() const { return m_distribution(*m_generator); } - template - PacketType packetOp(Index i) const { + template + PacketType packetOp() const { const int packetSize = internal::unpacket_traits::size; EIGEN_ALIGN_MAX float values[packetSize]; for (int k = 0; k < packetSize; ++k) { - values[k] = this->operator()(i); + values[k] = this->operator()(); } return internal::pload(values); } @@ -531,23 +529,22 @@ template <> class UniformRandomGenerator { } UniformRandomGenerator(const UniformRandomGenerator& other) { m_generator = new std::mt19937(); - m_generator->seed(other(0) * UINT_MAX); + m_generator->seed(other() * UINT_MAX); m_deterministic = other.m_deterministic; } ~UniformRandomGenerator() { delete m_generator; } - template - double operator()(Index) const { + double operator()() const { return m_distribution(*m_generator); } - template - PacketType packetOp(Index i) const { + template + PacketType packetOp() const { const int packetSize = internal::unpacket_traits::size; EIGEN_ALIGN_MAX double values[packetSize]; for (int k = 0; k < packetSize; ++k) { - values[k] = this->operator()(i); + values[k] = this->operator()(); } return internal::pload(values); } @@ -584,12 +581,11 @@ template <> class UniformRandomGenerator { curand_init(seed, tid, 0, &m_state); } - template - __device__ float operator()(Index) const { + __device__ float operator()() const { return curand_uniform(&m_state); } - template - __device__ float4 packetOp(Index) const { + template + __device__ float4 packetOp() const { EIGEN_STATIC_ASSERT((is_same::value), YOU_MADE_A_PROGRAMMING_MISTAKE); return curand_uniform4(&m_state); } @@ -614,12 +610,11 @@ template <> class UniformRandomGenerator { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ double operator()(Index) const { + __device__ double operator()() const { return curand_uniform_double(&m_state); } - template - __device__ double2 packetOp(Index) const { + template + __device__ double2 packetOp() const { EIGEN_STATIC_ASSERT((is_same::value), YOU_MADE_A_PROGRAMMING_MISTAKE); return curand_uniform2_double(&m_state); } @@ -644,8 +639,7 @@ template <> class UniformRandomGenerator > { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ std::complex operator()(Index) const { + __device__ std::complex operator()() const { float4 vals = curand_uniform4(&m_state); return std::complex(vals.x, vals.y); } @@ -670,8 +664,7 @@ template <> class UniformRandomGenerator > { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ std::complex operator()(Index) const { + __device__ std::complex operator()() const { double2 vals = curand_uniform2_double(&m_state); return std::complex(vals.x, vals.y); } @@ -707,17 +700,16 @@ template class NormalRandomGenerator { } NormalRandomGenerator(const NormalRandomGenerator& other) : m_deterministic(other.m_deterministic), m_distribution(other.m_distribution), m_generator(new std::mt19937()) { - m_generator->seed(other(0) * UINT_MAX); + m_generator->seed(other() * UINT_MAX); } ~NormalRandomGenerator() { delete m_generator; } - template - T operator()(Index) const { + T operator()() const { return m_distribution(*m_generator); } - template - PacketType packetOp(Index) const { + template + PacketType packetOp() const { const int packetSize = internal::unpacket_traits::size; EIGEN_ALIGN_MAX T values[packetSize]; for (int i = 0; i < packetSize; ++i) { @@ -755,12 +747,11 @@ template <> class NormalRandomGenerator { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ float operator()(Index) const { + __device__ float operator()() const { return curand_normal(&m_state); } - template - __device__ float4 packetOp(Index) const { + template + __device__ float4 packetOp() const { EIGEN_STATIC_ASSERT((is_same::value), YOU_MADE_A_PROGRAMMING_MISTAKE); return curand_normal4(&m_state); } @@ -785,12 +776,11 @@ template <> class NormalRandomGenerator { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ double operator()(Index) const { + __device__ double operator()() const { return curand_normal_double(&m_state); } - template - __device__ double2 packetOp(Index) const { + template + __device__ double2 packetOp() const { EIGEN_STATIC_ASSERT((is_same::value), YOU_MADE_A_PROGRAMMING_MISTAKE); return curand_normal2_double(&m_state); } @@ -815,8 +805,7 @@ template <> class NormalRandomGenerator > { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ std::complex operator()(Index) const { + __device__ std::complex operator()() const { float4 vals = curand_normal4(&m_state); return std::complex(vals.x, vals.y); } @@ -841,8 +830,7 @@ template <> class NormalRandomGenerator > { const int seed = m_deterministic ? 0 : get_random_seed(); curand_init(seed, tid, 0, &m_state); } - template - __device__ std::complex operator()(Index) const { + __device__ std::complex operator()() const { double2 vals = curand_normal2_double(&m_state); return std::complex(vals.x, vals.y); } -- cgit v1.2.3 From 05b05180771584009d4499a81f5e1527391ea7dd Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 2 Sep 2016 15:29:34 -0700 Subject: Made the index type an explicit template parameter to help some compilers compile the code. --- unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h index 5f44dc863..61c111cec 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h @@ -243,13 +243,13 @@ struct TensorEvaluator, Device> EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const { - return m_wrapper(m_functor,index); + return m_wrapper(m_functor, index); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { - return m_wrapper.template packetOp(m_functor,index); + return m_wrapper.template packetOp(m_functor, index); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost -- cgit v1.2.3