Compute Library
 22.08
OperatorGraph.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifdef ENABLE_EXPERIMENTAL_DYNAMIC_FUSION
25 
26 #ifndef ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_OPERATORGRAPH
27 #define ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_OPERATORGRAPH
28 
29 #include "arm_compute/core/Error.h"
31 
32 #include <memory>
33 
34 namespace arm_compute
35 {
36 namespace experimental
37 {
38 namespace dynamic_fusion
39 {
40 /** Graph of operators to execute within a Workload. This is a pure descriptive construct.
41  */
42 class OperatorGraph final
43 {
44 public:
45  struct Implementation;
46  OperatorGraph();
48 
49 public:
51  const Implementation *impl() const;
52 
53 private:
54  std::unique_ptr<Implementation> _impl;
55 };
56 
57 /** Return the validity of @p op_graph, usually after performing an operation (e.g. add_tensor) on it
58  *
59  * @param[in,out] op_graph OperatorGraph to be validated
60  *
61  * @return Status
62  */
64 
65 /** Operator Tensor Handle
66  * This can be either an argument tensor, or an intermediate tensor linking 2 @ref Operator s
67  */
68 class OpTensor final
69 {
70 public:
71  using Id = int;
72  OpTensor(Id id = {});
73  /** Id of the OpTensor
74  * @return Id
75  */
76  Id id() const;
77 
78 private:
79  Id _id{};
80 };
81 
82 /** Provide order of @ref OpTensor by checking if @p t0 is "lower than" @p t1
83  *
84  * @param[in] t0 OpTensor
85  * @param[in] t1 OpTensor
86  *
87  * @return true if @p t0 is lower than @p t1
88  * @return false otherwise
89  */
90 bool operator<(const OpTensor &t0, const OpTensor &t1);
91 
92 /** Associate a TensorInfo with a newly created @ref OpTensor in the @p graph.
93  *
94  * @note @p info needs to remain in scope and valid until the workload has finished building
95  * @note Can pass in an empty TensorInfo for a destination Tensor, in which case @p info will be inferred from the source tensors
96  *
97  * @param[in,out] graph OperatorGraph where the tensor is added
98  * @param[in] info TensorInfo to be associated
99  *
100  * @return OpTensor
101  */
103 
104 /** Operator Handle
105  * This can be used to further modify an existing operator
106  */
107 class Operator final
108 {
109 public:
110  using Id = int;
111  Operator(Id id = {});
112  /** Id of the Operator
113  * @return Id
114  */
115  Id id() const;
116 
117 private:
118  Id _id{};
119 };
120 
121 /** Provide order of @ref Operator by checking if @p op0 is "lower than" @p op1
122  *
123  * @param[in] op0 Operator
124  * @param[in] op1 Operator
125  *
126  * @return true if @p op0 is lower than @p op1
127  * @return false otherwise
128  */
129 bool operator<(const Operator &op0, const Operator &op1);
130 
131 /** Padding information for 2D operations like Conv2dDescriptor
132  */
133 struct Padding2D
134 {
135  Padding2D() = default;
136  Padding2D(size_t left, size_t right, size_t top, size_t bottom)
137  : left(left), right(right), top(top), bottom(bottom)
138  {
139  }
140  size_t left = { 0 }; /**< Padding across the width dimension on the left, in elements. */
141  size_t right = { 0 }; /**< Padding across the width dimension on the right, in elements. */
142  size_t top = { 0 }; /**< Padding across the height dimension on the top, in elements. */
143  size_t bottom = { 0 }; /**< Padding across the height dimension on the bottom, in elements. */
144 };
145 
146 /** Descriptor for Conv2dDescriptor operation
147  */
149 {
150  /* TOSA compliant attribute parameters start */
151  Padding2D pad{};
152  Size2D stride{ 1U, 1U };
153  Size2D dilation{ 1U, 1U };
154  /* TOSA compliant attribute parameters end */
155  /* Non-TOSA compliant attribute parameters start */
156  /* Non-TOSA compliant attribute parameters end */
157 };
158 /** Add op Conv2d to @p graph
159  *
160  * @param[in,out] graph OperatorGraph where the operator is added to
161  * @param[in] desc Operator descriptor
162  * @param[in] input Input OpTensor
163  * @param[in] weights Weights OpTensor
164  * @param[in] bias (Optional) bias OpTensor
165  * @param[in] dst Destination OpTensor
166  *
167  * @return Operator
168  */
170 Operator add_op_conv2d(OperatorGraph &graph, const Conv2dDescriptor &desc, OpTensor input, OpTensor weights, OpTensor dst);
171 /** (Only for Debuging and Testing) Force a conv2d method
172  *
173  * @param[in,out] graph OperatorGraph where conv2d op is located
174  * @param[in] conv2d Conv2d Op
175  * @param[in] method Forced ConvolutionMethod
176  */
177 void force_conv2d_method(OperatorGraph &graph, Operator conv2d, ConvolutionMethod method);
178 
179 /** Descriptor for Elementwise binary operation
180  *
181  */
183 {
184  /* TOSA compliant attribute parameters start */
185  /* TOSA compliant attribute parameters end */
186  /* Non-TOSA compliant attribute parameters start */
188  /* Non-TOSA compliant attribute parameters end */
189 };
190 /** Add op Elementwise to @p graph, and optionally describes fusion through passing of intermediate @ref OpTensor s
191  *
192  * @param[in,out] graph OperatorGraph where the operator is added to
193  * @param[in] desc Operator descriptor
194  * @param[in] lhs Lhs OpTensor
195  * @param[in] rhs Rhs OpTensor
196  * @param[in] dst Destination OpTensor
197  *
198  * @return Operator
199  */
201 
202 /** Descriptor for Floor operation
203  *
204  */
206 {
207  /* TOSA compliant attribute parameters start */
208  /* TOSA compliant attribute parameters end */
209  /* Non-TOSA compliant attribute parameters start */
210  /* Non-TOSA compliant attribute parameters end */
211 };
212 /** Add op Floor to @p graph, and optionally describes fusion through passing of intermediate @ref OpTensor s
213  *
214  * @param[in,out] graph OperatorGraph where the operator is added to
215  * @param[in] desc Operator descriptor
216  * @param[in] src Source OpTensor
217  * @param[in] dst Destination OpTensor
218  *
219  * @return Operator
220  */
222 
223 bool operator==(const OpTensor &t0, const OpTensor &t1);
224 bool operator==(const Padding2D &pad0, const Padding2D &pad1);
225 bool operator==(const Conv2dDescriptor &conv2d0, const Conv2dDescriptor &conv2d1);
227 bool operator==(const FloorDescriptor &, const FloorDescriptor &);
228 
229 } // namespace dynamic_fusion
230 } // namespace experimental
231 } // namespace arm_compute
232 #endif //ARM_COMPUTE_EXPERIMENTAL_DYNAMICFUSION_OPERATORGRAPH
233 #endif /* ENABLE_EXPERIMENTAL_DYNAMIC_FUSION */
Operator Tensor Handle This can be either an argument tensor, or an intermediate tensor linking 2 Ope...
Definition: OperatorGraph.h:68
ArithmeticOperation
Available element-wise operations.
Definition: Types.h:489
Status validate(const OperatorGraph &op_graph)
Return the validity of op_graph, usually after performing an operation (e.g.
Operator add_op_elementwise_op(OperatorGraph &graph, const ElementwiseDescriptor &desc, OpTensor lhs, OpTensor rhs, OpTensor dst)
Add op Elementwise to graph, and optionally describes fusion through passing of intermediate OpTensor...
Graph of operators to execute within a Workload.
Definition: OperatorGraph.h:42
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
ConvolutionMethod
Available ConvolutionMethod.
Definition: Types.h:134
void force_conv2d_method(OperatorGraph &graph, Operator conv2d, ConvolutionMethod method)
(Only for Debuging and Testing) Force a conv2d method
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2022 Arm Limited.
Descriptor for Elementwise binary operation.
Descriptor for Conv2dDescriptor operation.
Operator add_op_floor(OperatorGraph &graph, const FloorDescriptor &desc, OpTensor src, OpTensor dst)
Add op Floor to graph, and optionally describes fusion through passing of intermediate OpTensor s...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
OpTensor add_tensor(OperatorGraph &graph, ITensorInfo &info)
Associate a TensorInfo with a newly created OpTensor in the graph.
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Operator Handle This can be used to further modify an existing operator.
bool operator<(const OpTensor &t0, const OpTensor &t1)
Provide order of OpTensor by checking if t0 is "lower than" t1.
Padding information for 2D operations like Conv2dDescriptor.
Padding2D(size_t left, size_t right, size_t top, size_t bottom)
bool operator==(const OpTensor &t0, const OpTensor &t1)
Operator add_op_conv2d(OperatorGraph &graph, const Conv2dDescriptor &desc, OpTensor input, OpTensor weights, OpTensor bias, OpTensor dst)
Add op Conv2d to graph.
const int32_t * bias