TensorDevice.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
12 
13 namespace Eigen {
14 
27 template <typename ExpressionType, typename DeviceType> class TensorDevice {
28  public:
29  TensorDevice(const DeviceType& device, ExpressionType& expression) : m_device(device), m_expression(expression) {}
30 
32 
33  template<typename OtherDerived>
36  Assign assign(m_expression, other);
38  return *this;
39  }
40 
41  template<typename OtherDerived>
43  typedef typename OtherDerived::Scalar Scalar;
44  typedef TensorCwiseBinaryOp<internal::scalar_sum_op<Scalar>, const ExpressionType, const OtherDerived> Sum;
45  Sum sum(m_expression, other);
47  Assign assign(m_expression, sum);
49  return *this;
50  }
51 
52  template<typename OtherDerived>
54  typedef typename OtherDerived::Scalar Scalar;
55  typedef TensorCwiseBinaryOp<internal::scalar_difference_op<Scalar>, const ExpressionType, const OtherDerived> Difference;
56  Difference difference(m_expression, other);
58  Assign assign(m_expression, difference);
60  return *this;
61  }
62 
63  protected:
64  const DeviceType& m_device;
65  ExpressionType& m_expression;
66 };
67 
82 template <typename ExpressionType, typename DeviceType, typename DoneCallback>
84  public:
85  TensorAsyncDevice(const DeviceType& device, ExpressionType& expression,
86  DoneCallback done)
87  : m_device(device), m_expression(expression), m_done(std::move(done)) {}
88 
89  template <typename OtherDerived>
93 
94  Assign assign(m_expression, other);
95  Executor::run(assign, m_device);
96  m_done();
97 
98  return *this;
99  }
100 
101  protected:
102  const DeviceType& m_device;
103  ExpressionType& m_expression;
104  DoneCallback m_done;
105 };
106 
107 
108 #ifdef EIGEN_USE_THREADS
109 template <typename ExpressionType, typename DoneCallback>
110 class TensorAsyncDevice<ExpressionType, ThreadPoolDevice, DoneCallback> {
111  public:
112  TensorAsyncDevice(const ThreadPoolDevice& device, ExpressionType& expression,
113  DoneCallback done)
114  : m_device(device), m_expression(expression), m_done(std::move(done)) {}
115 
116  template <typename OtherDerived>
117  EIGEN_STRONG_INLINE TensorAsyncDevice& operator=(const OtherDerived& other) {
118  typedef TensorAssignOp<ExpressionType, const OtherDerived> Assign;
119  typedef internal::TensorAsyncExecutor<const Assign, ThreadPoolDevice, DoneCallback> Executor;
120 
121  // WARNING: After assignment 'm_done' callback will be in undefined state.
122  Assign assign(m_expression, other);
123  Executor::runAsync(assign, m_device, std::move(m_done));
124 
125  return *this;
126  }
127 
128  protected:
129  const ThreadPoolDevice& m_device;
130  ExpressionType& m_expression;
131  DoneCallback m_done;
132 };
133 #endif
134 
135 } // end namespace Eigen
136 
137 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_H
Eigen::TensorDevice::TensorDevice
TensorDevice(const DeviceType &device, ExpressionType &expression)
Definition: TensorDevice.h:29
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TensorDevice::operator=
EIGEN_STRONG_INLINE TensorDevice & operator=(const OtherDerived &other)
Definition: TensorDevice.h:34
Eigen::TensorAsyncDevice::m_done
DoneCallback m_done
Definition: TensorDevice.h:104
Eigen::TensorDevice
Pseudo expression providing an operator = that will evaluate its argument on the specified computing ...
Definition: TensorDevice.h:27
Eigen::TensorAsyncDevice::m_device
const DeviceType & m_device
Definition: TensorDevice.h:102
Eigen::TensorDevice::operator-=
EIGEN_STRONG_INLINE TensorDevice & operator-=(const OtherDerived &other)
Definition: TensorDevice.h:53
Eigen::TensorAsyncDevice::operator=
EIGEN_STRONG_INLINE TensorAsyncDevice & operator=(const OtherDerived &other)
Definition: TensorDevice.h:90
Eigen::TensorAsyncDevice
Pseudo expression providing an operator = that will evaluate its argument asynchronously on the speci...
Definition: TensorDevice.h:83
Eigen::TensorDevice::m_device
const DeviceType & m_device
Definition: TensorDevice.h:64
Eigen::TensorDevice::operator+=
EIGEN_STRONG_INLINE TensorDevice & operator+=(const OtherDerived &other)
Definition: TensorDevice.h:42
Eigen::TensorAsyncDevice::m_expression
ExpressionType & m_expression
Definition: TensorDevice.h:103
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorCwiseBinaryOp
Definition: TensorExpr.h:196
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::TensorDevice::m_expression
ExpressionType & m_expression
Definition: TensorDevice.h:65
EIGEN_DEFAULT_COPY_CONSTRUCTOR
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Definition: Macros.h:1221
Eigen::internal::TensorExecutor
Definition: TensorExecutor.h:81
move
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1243
std
Definition: BFloat16.h:88
Eigen::TensorAsyncDevice::TensorAsyncDevice
TensorAsyncDevice(const DeviceType &device, ExpressionType &expression, DoneCallback done)
Definition: TensorDevice.h:85
Eigen::TensorAssignOp
Definition: TensorAssign.h:61
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::internal::TensorExecutor::run
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Expression &expr, const Device &device=Device())
Definition: TensorExecutor.h:96


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:04:38