blob: 167f7388d4e132572ca8579965b38c192c9abe66 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2018-2021, 2023 Arm Limited.
Anthony Barbier2a07e182017-08-04 18:20:27 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_TYPES_H
25#define ARM_COMPUTE_GRAPH_TYPES_H
Anthony Barbier2a07e182017-08-04 18:20:27 +010026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/core/Error.h"
Georgios Pinitas102b0ce2020-02-13 17:59:09 +000028#include "arm_compute/core/PixelValue.h"
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010029#include "arm_compute/core/Types.h"
SiCong Li91295492023-07-21 18:16:13 +010030#include "arm_compute/function_info/ActivationLayerInfo.h"
31#include "arm_compute/function_info/ConvolutionInfo.h"
32#include "arm_compute/function_info/FullyConnectedLayerInfo.h"
33#include "arm_compute/function_info/GEMMInfo.h"
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010034#include "arm_compute/runtime/CL/CLTunerTypes.h"
Michalis Spyrou402740d2021-04-20 11:26:21 +010035#include "arm_compute/runtime/CL/CLTypes.h"
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010036
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010037#include <limits>
38#include <string>
Anthony Barbier2a07e182017-08-04 18:20:27 +010039
40namespace arm_compute
41{
42namespace graph
43{
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010044using arm_compute::CLTunerMode;
Michalis Spyrou402740d2021-04-20 11:26:21 +010045using arm_compute::CLBackendType;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010046using arm_compute::Status;
47
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010048using arm_compute::Coordinates;
49using arm_compute::DataType;
Georgios Pinitascac13b12018-04-27 19:07:19 +010050using arm_compute::DataLayout;
51using arm_compute::DataLayoutDimension;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010052using arm_compute::TensorShape;
53using arm_compute::Size2D;
Georgios Pinitas57c48242018-08-02 13:41:49 +010054using arm_compute::PermutationVector;
Georgios Pinitas102b0ce2020-02-13 17:59:09 +000055using arm_compute::PixelValue;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010056
57using arm_compute::ActivationLayerInfo;
Isabella Gottardi7234ed82018-11-27 08:51:10 +000058using arm_compute::DetectionOutputLayerInfo;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000059using arm_compute::DetectionPostProcessLayerInfo;
Georgios Pinitas6f669f02017-09-26 12:32:57 +010060using arm_compute::NormType;
61using arm_compute::NormalizationLayerInfo;
Georgios Pinitasc55cef12018-08-01 15:24:18 +010062using arm_compute::FullyConnectedLayerInfo;
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010063using arm_compute::PadStrideInfo;
Anthony Barbier2a07e182017-08-04 18:20:27 +010064using arm_compute::PoolingLayerInfo;
65using arm_compute::PoolingType;
Pablo Tello32521432018-11-15 14:43:10 +000066using arm_compute::PriorBoxLayerInfo;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010067using arm_compute::DimensionRoundingType;
Georgios Pinitas087eaf62018-05-16 15:52:35 +010068using arm_compute::InterpolationPolicy;
Sheri Zhangfb228032021-11-02 10:45:07 +000069using arm_compute::experimental::PostOpType;
Anthony Barbier2a07e182017-08-04 18:20:27 +010070
Georgios Pinitas54c92fd2018-11-05 12:16:15 +000071using GraphID = unsigned int;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010072using TensorID = unsigned int;
73using NodeID = unsigned int;
74using EdgeID = unsigned int;
75using Activation = arm_compute::ActivationLayerInfo::ActivationFunction;
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010076
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010077/**< Constant TensorID specifying an equivalent of null tensor */
78constexpr TensorID NullTensorID = std::numeric_limits<TensorID>::max();
79/**< Constant NodeID specifying an equivalent of null node */
80constexpr NodeID EmptyNodeID = std::numeric_limits<NodeID>::max();
81/**< Constant EdgeID specifying an equivalent of null edge */
82constexpr EdgeID EmptyEdgeID = std::numeric_limits<EdgeID>::max();
83
84// Forward declarations
Georgios Pinitas879d1312019-09-30 13:25:53 +010085struct TensorDescriptor;
SiCongLif466d752021-03-01 15:26:18 +000086
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010087/** Graph configuration structure */
88struct GraphConfig
Anthony Barbier2a07e182017-08-04 18:20:27 +010089{
Michalis Spyrou402740d2021-04-20 11:26:21 +010090 bool use_function_memory_manager{ true }; /**< Use a memory manager to manage per-function auxilary memory */
91 bool use_function_weights_manager{ true }; /**< Use a weights manager to manage transformed weights */
92 bool use_transition_memory_manager{ true }; /**< Use a memory manager to manager transition buffer memory */
93 bool use_tuner{ false }; /**< Use a tuner in tunable backends */
94 bool use_synthetic_type{ false }; /**< Convert graph to a synthetic graph for a data type */
95 DataType synthetic_type{ DataType::QASYMM8 }; /**< The data type of the synthetic graph */
96 CLTunerMode tuner_mode{ CLTunerMode::EXHAUSTIVE }; /**< Tuner mode to be used by the CL tuner */
97 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. */
98 std::string tuner_file{ "acl_tuner.csv" }; /**< File to load/store tuning values from */
99 std::string mlgo_file{ "heuristics.mlgo" }; /**< Filename to load MLGO heuristics from */
100 CLBackendType backend_type{ CLBackendType::Native }; /**< CL backend type to use */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100101};
102
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100103/**< Device target types */
104enum class Target
105{
106 UNSPECIFIED, /**< Unspecified Target */
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +0000107 NEON, /**< Arm® Neon™ capable target device */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100108 CL, /**< OpenCL capable target device */
Michalis Spyrou402740d2021-04-20 11:26:21 +0100109 CLVK, /**< CLVK capable target device */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100110};
111
112/** Supported Element-wise operations */
113enum class EltwiseOperation
114{
Georgios Pinitase2220552018-07-20 13:23:44 +0100115 Add, /**< Arithmetic addition */
116 Sub, /**< Arithmetic subtraction */
Sheri Zhang16dddd22020-05-27 15:03:48 +0100117 Mul, /**< Arithmetic multiplication */
thecha01f8e35842020-07-28 17:28:17 +0100118 Max, /**< Arithmetic maximum */
Alessandro Navone6413e492021-02-02 11:39:05 +0000119 Div, /**< Arithmetic division */
Sheri Zhang1d359272021-06-10 13:56:11 +0100120 Min, /**< Arithmetic minimum */
Sheri Zhang16dddd22020-05-27 15:03:48 +0100121};
122
123/** Supported Unary Element-wise operations */
124enum class UnaryEltwiseOperation
125{
126 Exp /**< Exp */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100127};
128
129/** Supported Convolution layer methods */
130enum class ConvolutionMethod
131{
Georgios Pinitase2220552018-07-20 13:23:44 +0100132 Default, /**< Default approach using internal heuristics */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100133 GEMM, /**< GEMM based convolution */
Georgios Pinitase2220552018-07-20 13:23:44 +0100134 Direct, /**< Deep direct convolution */
135 Winograd /**< Winograd based convolution */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100136};
137
138/** Supported Depthwise Convolution layer methods */
139enum class DepthwiseConvolutionMethod
140{
Georgios Pinitase2220552018-07-20 13:23:44 +0100141 Default, /**< Default approach using internal heuristics */
142 GEMV, /**< Generic GEMV based depthwise convolution */
143 Optimized3x3, /**< Optimized 3x3 direct depthwise convolution */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100144};
145
Giorgio Arena59631a12018-05-02 13:59:04 +0100146/** Enable or disable fast math for Convolution layer */
147enum class FastMathHint
148{
Georgios Pinitase2220552018-07-20 13:23:44 +0100149 Enabled, /**< Fast math enabled for Convolution layer */
150 Disabled, /**< Fast math disabled for Convolution layer */
Giorgio Arena59631a12018-05-02 13:59:04 +0100151};
152
Sheri Zhangfb228032021-11-02 10:45:07 +0000153/** Convolution post operator info */
154class ConvPostOpInfo
155{
156public:
157 /** Returns post op type
158 *
159 * @return Post op type
160 */
161 virtual PostOpType type() const = 0;
162 virtual ~ConvPostOpInfo()
163 {
164 }
165};
166
167class ConvPostOpInfoActivation : public ConvPostOpInfo
168{
169public:
170 ConvPostOpInfoActivation(const ActivationLayerInfo &act)
171 : _act(act)
172 {
173 }
174 ~ConvPostOpInfoActivation() override
175 {
176 }
177 PostOpType type() const override
178 {
179 return PostOpType::Activation;
180 }
181 ActivationLayerInfo _act;
182};
183
184class ConvPostOpInfoEltwiseAdd : public ConvPostOpInfo
185{
186public:
187 ConvPostOpInfoEltwiseAdd(int arg_pos, const ConvertPolicy &policy)
188 : _prev_op_dst_pos(arg_pos), _policy(policy)
189 {
190 }
191 PostOpType type() const override
192 {
193 return PostOpType::Eltwise_Add;
194 }
195 ~ConvPostOpInfoEltwiseAdd() override
196 {
197 }
198 int _prev_op_dst_pos;
199 ConvertPolicy _policy;
200};
201
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100202/** Supported nodes */
203enum class NodeType
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100204{
205 ActivationLayer,
thecha01e8f05da2020-08-24 17:21:41 +0100206 ArgMinMaxLayer,
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100207 BatchNormalizationLayer,
Manuel Bottinid2048ce2018-10-23 17:00:42 +0100208 BoundingBoxTransformLayer,
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100209 ChannelShuffleLayer,
Georgios Pinitase2220552018-07-20 13:23:44 +0100210 ConcatenateLayer,
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100211 ConvolutionLayer,
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100212 DeconvolutionLayer,
thecha010a05e6a2020-08-28 18:40:38 +0100213 DepthToSpaceLayer,
Michalis Spyrou7bfe4c52017-11-24 09:54:20 +0000214 DepthwiseConvolutionLayer,
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +0000215 DequantizationLayer,
Isabella Gottardi7234ed82018-11-27 08:51:10 +0000216 DetectionOutputLayer,
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000217 DetectionPostProcessLayer,
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100218 EltwiseLayer,
Michalis Spyrou27c9efb2017-10-09 15:46:30 +0100219 FlattenLayer,
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100220 FullyConnectedLayer,
giuros01acce5042019-02-21 17:32:34 +0000221 FusedConvolutionBatchNormalizationLayer,
Sheri Zhangfb228032021-11-02 10:45:07 +0000222 FusedConvolutionWithPostOp,
ramelg01b75d6242021-11-26 19:12:40 +0000223 FusedConvolutionBatchNormalizationLayerWithPostOpsLayer,
Manuel Bottinibffb41e2019-06-20 16:00:27 +0100224 FusedDepthwiseConvolutionBatchNormalizationLayer,
Manuel Bottini5209be52019-02-13 16:34:56 +0000225 GenerateProposalsLayer,
thecha013603aff2020-09-01 14:52:38 +0100226 L2NormalizeLayer,
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100227 NormalizationLayer,
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100228 NormalizePlanarYUVLayer,
Michele Di Giorgio4bb17332018-09-26 13:56:51 +0100229 PadLayer,
Georgios Pinitas57c48242018-08-02 13:41:49 +0100230 PermuteLayer,
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100231 PoolingLayer,
Georgios Pinitasf8c47492020-02-04 17:39:59 +0000232 PReluLayer,
Giorgio Arena6e9d0e02020-01-03 15:02:04 +0000233 PrintLayer,
Pablo Tello32521432018-11-15 14:43:10 +0000234 PriorBoxLayer,
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100235 QuantizationLayer,
thecha01d64444b2020-09-07 14:50:21 +0100236 ReductionOperationLayer,
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100237 ReorgLayer,
Michalis Spyrou27c9efb2017-10-09 15:46:30 +0100238 ReshapeLayer,
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100239 ResizeLayer,
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100240 ROIAlignLayer,
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100241 SoftmaxLayer,
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100242 SliceLayer,
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100243 SplitLayer,
Michele Di Giorgioec699752019-03-22 15:25:32 +0000244 StackLayer,
thecha012bfadd92020-08-12 17:25:51 +0100245 StridedSliceLayer,
Michalis Spyrou4e1c3f32018-09-20 17:14:03 +0100246 UpsampleLayer,
Sheri Zhang16dddd22020-05-27 15:03:48 +0100247 UnaryEltwiseLayer,
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100248
249 Input,
250 Output,
251 Const,
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100252
253 Dummy
Georgios Pinitas407c3e62017-10-25 18:26:46 +0100254};
255
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100256/** Backend Memory Manager affinity **/
257enum class MemoryManagerAffinity
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100258{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100259 Buffer, /**< Affinity at buffer level */
260 Offset /**< Affinity at offset level */
261};
262
263/** NodeID-index struct
264 *
265 * Used to describe connections
266 */
267struct NodeIdxPair
268{
269 NodeID node_id; /**< Node ID */
270 size_t index; /**< Index */
271};
272
273/** Common node parameters */
274struct NodeParams
275{
276 std::string name; /**< Node name */
277 Target target; /**< Node target */
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100278};
Anthony Barbier2a07e182017-08-04 18:20:27 +0100279} // namespace graph
280} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000281#endif /* ARM_COMPUTE_GRAPH_TYPES_H */