blob: 1847d9c22634f41590e290db6a72911e3d88bf7f [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
2 * Copyright (c) 2018 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 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#ifndef __ARM_COMPUTE_GRAPH_TYPE_PRINTER_H__
25#define __ARM_COMPUTE_GRAPH_TYPE_PRINTER_H__
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Types.h"
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010029#include "arm_compute/graph/Types.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000030
31namespace arm_compute
32{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010033namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000034{
35/** Formatted output of the Dimensions type. */
36template <typename T>
37inline ::std::ostream &operator<<(::std::ostream &os, const arm_compute::Dimensions<T> &dimensions)
38{
39 if(dimensions.num_dimensions() > 0)
40 {
41 os << dimensions[0];
42
43 for(unsigned int d = 1; d < dimensions.num_dimensions(); ++d)
44 {
45 os << "x" << dimensions[d];
46 }
47 }
48
49 return os;
50}
51
52/** Formatted output of the Size2D type. */
53inline ::std::ostream &operator<<(::std::ostream &os, const Size2D &size)
54{
55 os << size.width << "x" << size.height;
56
57 return os;
58}
59
60/** Formatted output of the DataType type. */
61inline ::std::ostream &operator<<(::std::ostream &os, const DataType &data_type)
62{
63 switch(data_type)
64 {
65 case DataType::UNKNOWN:
66 os << "UNKNOWN";
67 break;
68 case DataType::U8:
69 os << "U8";
70 break;
71 case DataType::QS8:
72 os << "QS8";
73 break;
74 case DataType::QASYMM8:
75 os << "QASYMM8";
76 break;
77 case DataType::S8:
78 os << "S8";
79 break;
80 case DataType::U16:
81 os << "U16";
82 break;
83 case DataType::S16:
84 os << "S16";
85 break;
86 case DataType::QS16:
87 os << "QS16";
88 break;
89 case DataType::U32:
90 os << "U32";
91 break;
92 case DataType::S32:
93 os << "S32";
94 break;
95 case DataType::U64:
96 os << "U64";
97 break;
98 case DataType::S64:
99 os << "S64";
100 break;
101 case DataType::F16:
102 os << "F16";
103 break;
104 case DataType::F32:
105 os << "F32";
106 break;
107 case DataType::F64:
108 os << "F64";
109 break;
110 case DataType::SIZET:
111 os << "SIZET";
112 break;
113 default:
114 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
115 }
116
117 return os;
118}
119
120/** Formatted output of the Target. */
121inline ::std::ostream &operator<<(::std::ostream &os, const Target &target)
122{
123 switch(target)
124 {
125 case Target::UNSPECIFIED:
126 os << "UNSPECIFIED";
127 break;
128 case Target::NEON:
129 os << "NEON";
130 break;
131 case Target::CL:
132 os << "CL";
133 break;
Georgios Pinitas2e01e182018-06-06 14:35:15 +0100134 case Target::GC:
135 os << "GC";
136 break;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000137 default:
138 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
139 }
140
141 return os;
142}
143
Georgios Pinitascac13b12018-04-27 19:07:19 +0100144/** Formatted output of the DataLayout */
145inline ::std::ostream &operator<<(::std::ostream &os, const DataLayout &data_layout)
146{
147 switch(data_layout)
148 {
149 case DataLayout::NCHW:
150 os << "NCHW";
151 break;
152 case DataLayout::NHWC:
153 os << "NHWC";
154 break;
155 default:
156 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
157 }
158
159 return os;
160}
161
Georgios Pinitasda2491f2018-06-01 17:49:09 +0100162inline ::std::ostream &operator<<(::std::ostream &os, const NodeType &node_type)
163{
164 switch(node_type)
165 {
166 case NodeType::ActivationLayer:
167 os << "ActivationLayer";
168 break;
169 case NodeType::BatchNormalizationLayer:
170 os << "BatchNormalizationLayer";
171 break;
172 case NodeType::ChannelShuffleLayer:
173 os << "ChannelShuffleLayer";
174 break;
175 case NodeType::ConvolutionLayer:
176 os << "ConvolutionLayer";
177 break;
178 case NodeType::DeconvolutionLayer:
179 os << "DeconvolutionLayer";
180 break;
181 case NodeType::DepthConcatenateLayer:
182 os << "DepthConcatenateLayer";
183 break;
184 case NodeType::DepthwiseConvolutionLayer:
185 os << "DepthwiseConvolutionLayer";
186 break;
187 case NodeType::EltwiseLayer:
188 os << "EltwiseLayer";
189 break;
190 case NodeType::FlattenLayer:
191 os << "FlattenLayer";
192 break;
193 case NodeType::FullyConnectedLayer:
194 os << "FullyConnectedLayer";
195 break;
196 case NodeType::NormalizationLayer:
197 os << "NormalizationLayer";
198 break;
199 case NodeType::PoolingLayer:
200 os << "PoolingLayer";
201 break;
202 case NodeType::ReshapeLayer:
203 os << "ReshapeLayer";
204 break;
205 case NodeType::ResizeLayer:
206 os << "ResizeLayer";
207 break;
208 case NodeType::SoftmaxLayer:
209 os << "SoftmaxLayer";
210 break;
211 case NodeType::SplitLayer:
212 os << "SplitLayer";
213 break;
214 case NodeType::Input:
215 os << "Input";
216 break;
217 case NodeType::Output:
218 os << "Output";
219 break;
220 case NodeType::Const:
221 os << "Const";
222 break;
223 case NodeType::Dummy:
224 os << "Dummy";
225 break;
226 default:
227 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
228 }
229
230 return os;
231}
232
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000233/** Formatted output of the activation function type. */
234inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
235{
236 switch(act_function)
237 {
238 case ActivationLayerInfo::ActivationFunction::ABS:
239 os << "ABS";
240 break;
241 case ActivationLayerInfo::ActivationFunction::LINEAR:
242 os << "LINEAR";
243 break;
244 case ActivationLayerInfo::ActivationFunction::LOGISTIC:
245 os << "LOGISTIC";
246 break;
247 case ActivationLayerInfo::ActivationFunction::RELU:
248 os << "RELU";
249 break;
250 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
251 os << "BOUNDED_RELU";
252 break;
253 case ActivationLayerInfo::ActivationFunction::LEAKY_RELU:
254 os << "LEAKY_RELU";
255 break;
256 case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
257 os << "SOFT_RELU";
258 break;
259 case ActivationLayerInfo::ActivationFunction::SQRT:
260 os << "SQRT";
261 break;
262 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
263 os << "LU_BOUNDED_RELU";
264 break;
265 case ActivationLayerInfo::ActivationFunction::SQUARE:
266 os << "SQUARE";
267 break;
268 case ActivationLayerInfo::ActivationFunction::TANH:
269 os << "TANH";
270 break;
271 default:
272 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
273 }
274
275 return os;
276}
277
278inline std::string to_string(const ActivationLayerInfo::ActivationFunction &act_function)
279{
280 std::stringstream str;
281 str << act_function;
282 return str.str();
283}
284
285/** Formatted output of the PoolingType type. */
286inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type)
287{
288 switch(pool_type)
289 {
290 case PoolingType::AVG:
291 os << "AVG";
292 break;
293 case PoolingType::MAX:
294 os << "MAX";
295 break;
296 case PoolingType::L2:
297 os << "L2";
298 break;
299 default:
300 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
301 }
302
303 return os;
304}
305
306/** Formatted output of the NormType type. */
307inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type)
308{
309 switch(norm_type)
310 {
311 case NormType::CROSS_MAP:
312 os << "CROSS_MAP";
313 break;
314 case NormType::IN_MAP_1D:
315 os << "IN_MAP_1D";
316 break;
317 case NormType::IN_MAP_2D:
318 os << "IN_MAP_2D";
319 break;
320 default:
321 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
322 }
323
324 return os;
325}
326
327/** Formatted output of the EltwiseOperation type. */
328inline ::std::ostream &operator<<(::std::ostream &os, const EltwiseOperation &eltwise_op)
329{
330 switch(eltwise_op)
331 {
332 case EltwiseOperation::ADD:
333 os << "ADD";
334 break;
335 case EltwiseOperation::MUL:
336 os << "MUL";
337 break;
338 case EltwiseOperation::SUB:
339 os << "SUB";
340 break;
341 default:
342 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
343 }
344
345 return os;
346}
347
348/** Formatted output of the ConvolutionMethod type. */
349inline ::std::ostream &operator<<(::std::ostream &os, const ConvolutionMethod &method)
350{
351 switch(method)
352 {
353 case ConvolutionMethod::DEFAULT:
354 os << "DEFAULT";
355 break;
356 case ConvolutionMethod::DIRECT:
357 os << "DIRECT";
358 break;
359 case ConvolutionMethod::GEMM:
360 os << "GEMM";
361 break;
362 case ConvolutionMethod::WINOGRAD:
363 os << "WINOGRAD";
364 break;
365 default:
366 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
367 }
368
369 return os;
370}
371
Giorgio Arena59631a12018-05-02 13:59:04 +0100372/** Formatted output of the FastMathHint type. */
373inline ::std::ostream &operator<<(::std::ostream &os, const FastMathHint &hint)
374{
375 switch(hint)
376 {
377 case FastMathHint::ENABLED:
378 os << "ENABLED";
379 break;
380 case FastMathHint::DISABLED:
381 os << "DISABLED";
382 break;
383 default:
384 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
385 }
386
387 return os;
388}
389
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000390/** Formatted output of the DepthwiseConvolutionMethod type. */
391inline ::std::ostream &operator<<(::std::ostream &os, const DepthwiseConvolutionMethod &method)
392{
393 switch(method)
394 {
395 case DepthwiseConvolutionMethod::DEFAULT:
396 os << "DEFAULT";
397 break;
398 case DepthwiseConvolutionMethod::GEMV:
399 os << "GEMV";
400 break;
401 case DepthwiseConvolutionMethod::OPTIMIZED_3x3:
402 os << "OPTIMIZED_3x3";
403 break;
404 default:
405 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
406 }
407
408 return os;
409}
410
411/** Formatted output of the PadStrideInfo type. */
412inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info)
413{
414 os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second;
415 os << ";";
416 os << pad_stride_info.pad_left() << "," << pad_stride_info.pad_right() << ","
417 << pad_stride_info.pad_top() << "," << pad_stride_info.pad_bottom();
418
419 return os;
420}
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100421
422/** Formatted output of the QuantizationInfo type. */
423inline ::std::ostream &operator<<(::std::ostream &os, const QuantizationInfo &quantization_info)
424{
425 os << "Scale:" << quantization_info.scale << "~"
426 << "Offset:" << quantization_info.offset;
427 return os;
428}
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100429
430/** Formatted output of the Interpolation policy type.
431 *
432 * @param[out] os Output stream.
433 * @param[in] policy Interpolation policy to output.
434 *
435 * @return Modified output stream.
436 */
437inline ::std::ostream &operator<<(::std::ostream &os, const InterpolationPolicy &policy)
438{
439 switch(policy)
440 {
441 case InterpolationPolicy::NEAREST_NEIGHBOR:
442 os << "NEAREST NEIGHBOR";
443 break;
444 case InterpolationPolicy::BILINEAR:
445 os << "BILINEAR";
446 break;
447 case InterpolationPolicy::AREA:
448 os << "AREA";
449 break;
450 default:
451 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
452 }
453
454 return os;
455}
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100456} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000457} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100458#endif /* __ARM_COMPUTE_GRAPH_TYPE_PRINTER_H__ */