• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2021 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 #ifndef ARM_COMPUTE_GRAPH_TYPES_H
25 #define ARM_COMPUTE_GRAPH_TYPES_H
26 
27 #include "arm_compute/core/Error.h"
28 #include "arm_compute/core/PixelValue.h"
29 #include "arm_compute/core/Types.h"
30 #include "arm_compute/runtime/CL/CLTunerTypes.h"
31 #include "arm_compute/runtime/CL/CLTypes.h"
32 
33 #include <limits>
34 #include <string>
35 
36 namespace arm_compute
37 {
38 namespace graph
39 {
40 using arm_compute::CLTunerMode;
41 using arm_compute::CLBackendType;
42 using arm_compute::Status;
43 
44 using arm_compute::Coordinates;
45 using arm_compute::DataType;
46 using arm_compute::DataLayout;
47 using arm_compute::DataLayoutDimension;
48 using arm_compute::TensorShape;
49 using arm_compute::Size2D;
50 using arm_compute::PermutationVector;
51 using arm_compute::PixelValue;
52 
53 using arm_compute::ActivationLayerInfo;
54 using arm_compute::DetectionOutputLayerInfo;
55 using arm_compute::DetectionPostProcessLayerInfo;
56 using arm_compute::NormType;
57 using arm_compute::NormalizationLayerInfo;
58 using arm_compute::FullyConnectedLayerInfo;
59 using arm_compute::PadStrideInfo;
60 using arm_compute::PoolingLayerInfo;
61 using arm_compute::PoolingType;
62 using arm_compute::PriorBoxLayerInfo;
63 using arm_compute::DimensionRoundingType;
64 using arm_compute::InterpolationPolicy;
65 using arm_compute::experimental::PostOpType;
66 
67 using GraphID    = unsigned int;
68 using TensorID   = unsigned int;
69 using NodeID     = unsigned int;
70 using EdgeID     = unsigned int;
71 using Activation = arm_compute::ActivationLayerInfo::ActivationFunction;
72 
73 /**< Constant TensorID specifying an equivalent of null tensor */
74 constexpr TensorID NullTensorID = std::numeric_limits<TensorID>::max();
75 /**< Constant NodeID specifying an equivalent of null node */
76 constexpr NodeID EmptyNodeID = std::numeric_limits<NodeID>::max();
77 /**< Constant EdgeID specifying an equivalent of null edge */
78 constexpr EdgeID EmptyEdgeID = std::numeric_limits<EdgeID>::max();
79 
80 // Forward declarations
81 struct TensorDescriptor;
82 
83 /** Graph configuration structure */
84 struct GraphConfig
85 {
86     bool          use_function_memory_manager{ true };   /**< Use a memory manager to manage per-function auxilary memory */
87     bool          use_function_weights_manager{ true };  /**< Use a weights manager to manage transformed weights */
88     bool          use_transition_memory_manager{ true }; /**< Use a memory manager to manager transition buffer memory */
89     bool          use_tuner{ false };                    /**< Use a tuner in tunable backends */
90     bool          use_synthetic_type{ false };           /**< Convert graph to a synthetic graph for a data type */
91     DataType      synthetic_type{ DataType::QASYMM8 };   /**< The data type of the synthetic graph  */
92     CLTunerMode   tuner_mode{ CLTunerMode::EXHAUSTIVE }; /**< Tuner mode to be used by the CL tuner */
93     int           num_threads{ -1 };                     /**< Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is. */
94     std::string   tuner_file{ "acl_tuner.csv" };         /**< File to load/store tuning values from */
95     std::string   mlgo_file{ "heuristics.mlgo" };        /**< Filename to load MLGO heuristics from */
96     CLBackendType backend_type{ CLBackendType::Native }; /**< CL backend type to use */
97 };
98 
99 /**< Device target types */
100 enum class Target
101 {
102     UNSPECIFIED, /**< Unspecified Target */
103     NEON,        /**< Arm® Neon™ capable target device */
104     CL,          /**< OpenCL capable target device */
105     CLVK,        /**< CLVK capable target device */
106 };
107 
108 /** Supported Element-wise operations */
109 enum class EltwiseOperation
110 {
111     Add, /**< Arithmetic addition */
112     Sub, /**< Arithmetic subtraction */
113     Mul, /**< Arithmetic multiplication */
114     Max, /**< Arithmetic maximum */
115     Div, /**< Arithmetic division */
116     Min, /**< Arithmetic minimum */
117 };
118 
119 /** Supported Unary Element-wise operations */
120 enum class UnaryEltwiseOperation
121 {
122     Exp /**< Exp */
123 };
124 
125 /** Supported Convolution layer methods */
126 enum class ConvolutionMethod
127 {
128     Default, /**< Default approach using internal heuristics */
129     GEMM,    /**< GEMM based convolution */
130     Direct,  /**< Deep direct convolution */
131     Winograd /**< Winograd based convolution */
132 };
133 
134 /** Supported Depthwise Convolution layer methods */
135 enum class DepthwiseConvolutionMethod
136 {
137     Default,      /**< Default approach using internal heuristics */
138     GEMV,         /**< Generic GEMV based depthwise convolution */
139     Optimized3x3, /**< Optimized 3x3 direct depthwise convolution */
140 };
141 
142 /** Enable or disable fast math for Convolution layer */
143 enum class FastMathHint
144 {
145     Enabled,  /**< Fast math enabled for Convolution layer */
146     Disabled, /**< Fast math disabled for Convolution layer */
147 };
148 
149 /** Convolution post operator info */
150 class ConvPostOpInfo
151 {
152 public:
153     /** Returns post op type
154      *
155      * @return Post op type
156      */
157     virtual PostOpType type() const = 0;
~ConvPostOpInfo()158     virtual ~ConvPostOpInfo()
159     {
160     }
161 };
162 
163 class ConvPostOpInfoActivation : public ConvPostOpInfo
164 {
165 public:
ConvPostOpInfoActivation(const ActivationLayerInfo & act)166     ConvPostOpInfoActivation(const ActivationLayerInfo &act)
167         : _act(act)
168     {
169     }
~ConvPostOpInfoActivation()170     ~ConvPostOpInfoActivation() override
171     {
172     }
type()173     PostOpType type() const override
174     {
175         return PostOpType::Activation;
176     }
177     ActivationLayerInfo _act;
178 };
179 
180 class ConvPostOpInfoEltwiseAdd : public ConvPostOpInfo
181 {
182 public:
ConvPostOpInfoEltwiseAdd(int arg_pos,const ConvertPolicy & policy)183     ConvPostOpInfoEltwiseAdd(int arg_pos, const ConvertPolicy &policy)
184         : _prev_op_dst_pos(arg_pos), _policy(policy)
185     {
186     }
type()187     PostOpType type() const override
188     {
189         return PostOpType::Eltwise_Add;
190     }
~ConvPostOpInfoEltwiseAdd()191     ~ConvPostOpInfoEltwiseAdd() override
192     {
193     }
194     int           _prev_op_dst_pos;
195     ConvertPolicy _policy;
196 };
197 
198 /** Supported nodes */
199 enum class NodeType
200 {
201     ActivationLayer,
202     ArgMinMaxLayer,
203     BatchNormalizationLayer,
204     BoundingBoxTransformLayer,
205     ChannelShuffleLayer,
206     ConcatenateLayer,
207     ConvolutionLayer,
208     DeconvolutionLayer,
209     DepthToSpaceLayer,
210     DepthwiseConvolutionLayer,
211     DequantizationLayer,
212     DetectionOutputLayer,
213     DetectionPostProcessLayer,
214     EltwiseLayer,
215     FlattenLayer,
216     FullyConnectedLayer,
217     FusedConvolutionBatchNormalizationLayer,
218     FusedConvolutionWithPostOp,
219     FusedConvolutionBatchNormalizationLayerWithPostOpsLayer,
220     FusedDepthwiseConvolutionBatchNormalizationLayer,
221     GenerateProposalsLayer,
222     L2NormalizeLayer,
223     NormalizationLayer,
224     NormalizePlanarYUVLayer,
225     PadLayer,
226     PermuteLayer,
227     PoolingLayer,
228     PReluLayer,
229     PrintLayer,
230     PriorBoxLayer,
231     QuantizationLayer,
232     ReductionOperationLayer,
233     ReorgLayer,
234     ReshapeLayer,
235     ResizeLayer,
236     ROIAlignLayer,
237     SoftmaxLayer,
238     SliceLayer,
239     SplitLayer,
240     StackLayer,
241     StridedSliceLayer,
242     UpsampleLayer,
243     UnaryEltwiseLayer,
244 
245     Input,
246     Output,
247     Const,
248 
249     Dummy
250 };
251 
252 /** Backend Memory Manager affinity **/
253 enum class MemoryManagerAffinity
254 {
255     Buffer, /**< Affinity at buffer level */
256     Offset  /**< Affinity at offset level */
257 };
258 
259 /** NodeID-index struct
260  *
261  * Used to describe connections
262  */
263 struct NodeIdxPair
264 {
265     NodeID node_id; /**< Node ID */
266     size_t index;   /**< Index */
267 };
268 
269 /** Common node parameters */
270 struct NodeParams
271 {
272     std::string name;   /**< Node name */
273     Target      target; /**< Node target */
274 };
275 } // namespace graph
276 } // namespace arm_compute
277 #endif /* ARM_COMPUTE_GRAPH_TYPES_H */
278