Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_GRAPH2_TYPE_PRINTER_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH2_TYPE_PRINTER_H__ |
| 26 | |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/graph2/Types.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace graph2 |
| 34 | { |
| 35 | /** Formatted output of the Dimensions type. */ |
| 36 | template <typename T> |
| 37 | inline ::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. */ |
| 53 | inline ::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. */ |
| 61 | inline ::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. */ |
| 121 | inline ::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; |
| 134 | default: |
| 135 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 136 | } |
| 137 | |
| 138 | return os; |
| 139 | } |
| 140 | |
| 141 | /** Formatted output of the activation function type. */ |
| 142 | inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function) |
| 143 | { |
| 144 | switch(act_function) |
| 145 | { |
| 146 | case ActivationLayerInfo::ActivationFunction::ABS: |
| 147 | os << "ABS"; |
| 148 | break; |
| 149 | case ActivationLayerInfo::ActivationFunction::LINEAR: |
| 150 | os << "LINEAR"; |
| 151 | break; |
| 152 | case ActivationLayerInfo::ActivationFunction::LOGISTIC: |
| 153 | os << "LOGISTIC"; |
| 154 | break; |
| 155 | case ActivationLayerInfo::ActivationFunction::RELU: |
| 156 | os << "RELU"; |
| 157 | break; |
| 158 | case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU: |
| 159 | os << "BOUNDED_RELU"; |
| 160 | break; |
| 161 | case ActivationLayerInfo::ActivationFunction::LEAKY_RELU: |
| 162 | os << "LEAKY_RELU"; |
| 163 | break; |
| 164 | case ActivationLayerInfo::ActivationFunction::SOFT_RELU: |
| 165 | os << "SOFT_RELU"; |
| 166 | break; |
| 167 | case ActivationLayerInfo::ActivationFunction::SQRT: |
| 168 | os << "SQRT"; |
| 169 | break; |
| 170 | case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU: |
| 171 | os << "LU_BOUNDED_RELU"; |
| 172 | break; |
| 173 | case ActivationLayerInfo::ActivationFunction::SQUARE: |
| 174 | os << "SQUARE"; |
| 175 | break; |
| 176 | case ActivationLayerInfo::ActivationFunction::TANH: |
| 177 | os << "TANH"; |
| 178 | break; |
| 179 | default: |
| 180 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 181 | } |
| 182 | |
| 183 | return os; |
| 184 | } |
| 185 | |
| 186 | inline std::string to_string(const ActivationLayerInfo::ActivationFunction &act_function) |
| 187 | { |
| 188 | std::stringstream str; |
| 189 | str << act_function; |
| 190 | return str.str(); |
| 191 | } |
| 192 | |
| 193 | /** Formatted output of the PoolingType type. */ |
| 194 | inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type) |
| 195 | { |
| 196 | switch(pool_type) |
| 197 | { |
| 198 | case PoolingType::AVG: |
| 199 | os << "AVG"; |
| 200 | break; |
| 201 | case PoolingType::MAX: |
| 202 | os << "MAX"; |
| 203 | break; |
| 204 | case PoolingType::L2: |
| 205 | os << "L2"; |
| 206 | break; |
| 207 | default: |
| 208 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 209 | } |
| 210 | |
| 211 | return os; |
| 212 | } |
| 213 | |
| 214 | /** Formatted output of the NormType type. */ |
| 215 | inline ::std::ostream &operator<<(::std::ostream &os, const NormType &norm_type) |
| 216 | { |
| 217 | switch(norm_type) |
| 218 | { |
| 219 | case NormType::CROSS_MAP: |
| 220 | os << "CROSS_MAP"; |
| 221 | break; |
| 222 | case NormType::IN_MAP_1D: |
| 223 | os << "IN_MAP_1D"; |
| 224 | break; |
| 225 | case NormType::IN_MAP_2D: |
| 226 | os << "IN_MAP_2D"; |
| 227 | break; |
| 228 | default: |
| 229 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 230 | } |
| 231 | |
| 232 | return os; |
| 233 | } |
| 234 | |
| 235 | /** Formatted output of the EltwiseOperation type. */ |
| 236 | inline ::std::ostream &operator<<(::std::ostream &os, const EltwiseOperation &eltwise_op) |
| 237 | { |
| 238 | switch(eltwise_op) |
| 239 | { |
| 240 | case EltwiseOperation::ADD: |
| 241 | os << "ADD"; |
| 242 | break; |
| 243 | case EltwiseOperation::MUL: |
| 244 | os << "MUL"; |
| 245 | break; |
| 246 | case EltwiseOperation::SUB: |
| 247 | os << "SUB"; |
| 248 | break; |
| 249 | default: |
| 250 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 251 | } |
| 252 | |
| 253 | return os; |
| 254 | } |
| 255 | |
| 256 | /** Formatted output of the ConvolutionMethod type. */ |
| 257 | inline ::std::ostream &operator<<(::std::ostream &os, const ConvolutionMethod &method) |
| 258 | { |
| 259 | switch(method) |
| 260 | { |
| 261 | case ConvolutionMethod::DEFAULT: |
| 262 | os << "DEFAULT"; |
| 263 | break; |
| 264 | case ConvolutionMethod::DIRECT: |
| 265 | os << "DIRECT"; |
| 266 | break; |
| 267 | case ConvolutionMethod::GEMM: |
| 268 | os << "GEMM"; |
| 269 | break; |
| 270 | case ConvolutionMethod::WINOGRAD: |
| 271 | os << "WINOGRAD"; |
| 272 | break; |
| 273 | default: |
| 274 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 275 | } |
| 276 | |
| 277 | return os; |
| 278 | } |
| 279 | |
| 280 | /** Formatted output of the DepthwiseConvolutionMethod type. */ |
| 281 | inline ::std::ostream &operator<<(::std::ostream &os, const DepthwiseConvolutionMethod &method) |
| 282 | { |
| 283 | switch(method) |
| 284 | { |
| 285 | case DepthwiseConvolutionMethod::DEFAULT: |
| 286 | os << "DEFAULT"; |
| 287 | break; |
| 288 | case DepthwiseConvolutionMethod::GEMV: |
| 289 | os << "GEMV"; |
| 290 | break; |
| 291 | case DepthwiseConvolutionMethod::OPTIMIZED_3x3: |
| 292 | os << "OPTIMIZED_3x3"; |
| 293 | break; |
| 294 | default: |
| 295 | ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); |
| 296 | } |
| 297 | |
| 298 | return os; |
| 299 | } |
| 300 | |
| 301 | /** Formatted output of the PadStrideInfo type. */ |
| 302 | inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_stride_info) |
| 303 | { |
| 304 | os << pad_stride_info.stride().first << "," << pad_stride_info.stride().second; |
| 305 | os << ";"; |
| 306 | os << pad_stride_info.pad_left() << "," << pad_stride_info.pad_right() << "," |
| 307 | << pad_stride_info.pad_top() << "," << pad_stride_info.pad_bottom(); |
| 308 | |
| 309 | return os; |
| 310 | } |
| 311 | } // namespace graph2 |
| 312 | } // namespace arm_compute |
| 313 | #endif /* __ARM_COMPUTE_GRAPH2_TYPE_PRINTER_H__ */ |