aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h
diff options
context:
space:
mode:
authorGravatar Rasmus Munk Larsen <rmlarsen@google.com>2016-04-15 12:51:33 -0700
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2016-04-15 12:51:33 -0700
commit3718bf654bd173ae05f396f5d0cff1a4e15ef72d (patch)
treec4a39a634c56ffc334f2f98c35dde80725c488e9 /unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h
parent07ac4f7e027cddd3457a34295420480f7e541ac5 (diff)
Get rid of void* casting when calling EvalRange::run.
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h')
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h28
1 files changed, 8 insertions, 20 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h
index df9cc0998..7a54f7a23 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h
@@ -85,8 +85,8 @@ class TensorExecutor<Expression, DefaultDevice, true>
#ifdef EIGEN_USE_THREADS
template <typename Evaluator, typename Index, bool Vectorizable>
struct EvalRange {
- static void run(void* evaluator_in, const Index first, const Index last) {
- Evaluator evaluator(*static_cast<Evaluator*>(evaluator_in));
+ static void run(Evaluator* evaluator_in, const Index first, const Index last) {
+ Evaluator evaluator = *evaluator_in;
eigen_assert(last >= first);
for (Index i = first; i < last; ++i) {
evaluator.evalScalar(i);
@@ -96,10 +96,9 @@ struct EvalRange {
template <typename Evaluator, typename Index>
struct EvalRange<Evaluator, Index, true> {
- static void run(void* evaluator_in, const Index first, const Index last) {
- Evaluator evaluator(*static_cast<Evaluator*>(evaluator_in));
+ static void run(Evaluator* evaluator_in, const Index first, const Index last) {
+ Evaluator evaluator = *evaluator_in;
eigen_assert(last >= first);
-
Index i = first;
const int PacketSize = unpacket_traits<typename Evaluator::PacketReturnType>::size;
if (last - first >= PacketSize) {
@@ -123,16 +122,6 @@ struct EvalRange<Evaluator, Index, true> {
}
};
-// Used to make an std::function to add to the ThreadPool with less templating
-// than EvalRange::Run.
-// This requires that this and EvalRange takes a void* to the evaluator that can
-// be downcast to the right type by the EvalRange.
-template <typename Index>
-inline void InvokeEvalRange(void (*run_fn)(void*, const Index, const Index),
- void* evaluator, const Index first, const Index last) {
- run_fn(evaluator, first, last);
-}
-
template <typename Expression, bool Vectorizable>
class TensorExecutor<Expression, ThreadPoolDevice, Vectorizable> {
public:
@@ -163,13 +152,12 @@ class TensorExecutor<Expression, ThreadPoolDevice, Vectorizable> {
Barrier barrier(numblocks);
for (int i = 0; i < numblocks; ++i) {
device.enqueue_with_barrier(
- &barrier, &InvokeEvalRange<Index>,
- &EvalRange<Evaluator, Index, Vectorizable>::run,
- static_cast<void*>(&evaluator), i * blocksize,
- (i + 1) * blocksize);
+ &barrier, &EvalRange<Evaluator, Index, Vectorizable>::run,
+ &evaluator, i * blocksize, (i + 1) * blocksize);
}
if (numblocks * blocksize < size) {
- EvalRange<Evaluator, Index, Vectorizable>::run(&evaluator, numblocks * blocksize, size);
+ EvalRange<Evaluator, Index, Vectorizable>::run(
+ &evaluator, numblocks * blocksize, size);
}
barrier.Wait();
}