TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
27template <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>
34 EIGEN_STRONG_INLINE TensorDevice& operator=(const OtherDerived& other) {
36 Assign assign(m_expression, other);
38 return *this;
39 }
40
41 template<typename OtherDerived>
42 EIGEN_STRONG_INLINE TensorDevice& operator+=(const OtherDerived& other) {
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>
53 EIGEN_STRONG_INLINE TensorDevice& operator-=(const OtherDerived& other) {
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
82template <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>
90 EIGEN_STRONG_INLINE TensorAsyncDevice& operator=(const OtherDerived& other) {
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
109template <typename ExpressionType, typename DoneCallback>
110class 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
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
Definition Macros.h:1221
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
SCALAR Scalar
Definition bench_gemm.cpp:46
Definition TensorAssign.h:62
Pseudo expression providing an operator = that will evaluate its argument asynchronously on the speci...
Definition TensorDevice.h:83
TensorAsyncDevice(const DeviceType &device, ExpressionType &expression, DoneCallback done)
Definition TensorDevice.h:85
const DeviceType & m_device
Definition TensorDevice.h:102
EIGEN_STRONG_INLINE TensorAsyncDevice & operator=(const OtherDerived &other)
Definition TensorDevice.h:90
ExpressionType & m_expression
Definition TensorDevice.h:103
DoneCallback m_done
Definition TensorDevice.h:104
Definition TensorExpr.h:197
Pseudo expression providing an operator = that will evaluate its argument on the specified computing ...
Definition TensorDevice.h:27
TensorDevice(const DeviceType &device, ExpressionType &expression)
Definition TensorDevice.h:29
EIGEN_STRONG_INLINE TensorDevice & operator-=(const OtherDerived &other)
Definition TensorDevice.h:53
EIGEN_STRONG_INLINE TensorDevice & operator+=(const OtherDerived &other)
Definition TensorDevice.h:42
const DeviceType & m_device
Definition TensorDevice.h:64
EIGEN_STRONG_INLINE TensorDevice & operator=(const OtherDerived &other)
Definition TensorDevice.h:34
ExpressionType & m_expression
Definition TensorDevice.h:65
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Expression &expr, const Device &device=Device())
Definition TensorExecutor.h:96
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BFloat16.h:88
Definition ForwardDeclarations.h:17