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) {
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
SCALAR Scalar
Definition: bench_gemm.cpp:46
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
ExpressionType & m_expression
Definition: TensorDevice.h:103
const DeviceType & m_device
Definition: TensorDevice.h:102
TensorAsyncDevice(const DeviceType &device, ExpressionType &expression, DoneCallback done)
Definition: TensorDevice.h:85
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Pseudo expression providing an operator = that will evaluate its argument on the specified computing ...
Definition: TensorDevice.h:27
Definition: BFloat16.h:88
EIGEN_STRONG_INLINE TensorDevice & operator=(const OtherDerived &other)
Definition: TensorDevice.h:34
ExpressionType & m_expression
Definition: TensorDevice.h:65
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Definition: Macros.h:1221
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Definition: cast.h:1080
EIGEN_STRONG_INLINE TensorDevice & operator-=(const OtherDerived &other)
Definition: TensorDevice.h:53
EIGEN_STRONG_INLINE TensorDevice & operator+=(const OtherDerived &other)
Definition: TensorDevice.h:42
EIGEN_STRONG_INLINE TensorAsyncDevice & operator=(const OtherDerived &other)
Definition: TensorDevice.h:90
Pseudo expression providing an operator = that will evaluate its argument asynchronously on the speci...
Definition: TensorDevice.h:83
TensorDevice(const DeviceType &device, ExpressionType &expression)
Definition: TensorDevice.h:29
const DeviceType & m_device
Definition: TensorDevice.h:64
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Expression &expr, const Device &device=Device())


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:51