Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018 ARM Limited. |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 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 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/core/utils/strong_type/StrongType.h" |
| 30 | #include "arm_compute/core/utils/strong_type/StrongTypeAttributes.h" |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 31 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 32 | #include <limits> |
| 33 | #include <string> |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace graph |
| 38 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 39 | using arm_compute::Status; |
| 40 | |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 41 | using arm_compute::Coordinates; |
| 42 | using arm_compute::DataType; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 43 | using arm_compute::TensorShape; |
| 44 | using arm_compute::Size2D; |
| 45 | |
| 46 | using arm_compute::ActivationLayerInfo; |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 47 | using arm_compute::NormType; |
| 48 | using arm_compute::NormalizationLayerInfo; |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 49 | using arm_compute::PadStrideInfo; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 50 | using arm_compute::PoolingLayerInfo; |
| 51 | using arm_compute::PoolingType; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 52 | using arm_compute::DimensionRoundingType; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 53 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 54 | /** TODO (geopin01): Make ids strongly typed */ |
| 55 | using TensorID = unsigned int; |
| 56 | using NodeID = unsigned int; |
| 57 | using EdgeID = unsigned int; |
| 58 | using Activation = arm_compute::ActivationLayerInfo::ActivationFunction; |
Georgios Pinitas | 7d3d1b9 | 2017-10-12 17:34:20 +0100 | [diff] [blame] | 59 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 60 | /**< GraphID strong type */ |
| 61 | using GraphID = strong_type::StrongType<unsigned int, struct graph_id_t, strong_type::Comparable>; |
| 62 | /* TODO (geopin01): Strong types for NodeID */ |
| 63 | |
| 64 | /**< Constant TensorID specifying an equivalent of null tensor */ |
| 65 | constexpr TensorID NullTensorID = std::numeric_limits<TensorID>::max(); |
| 66 | /**< Constant NodeID specifying an equivalent of null node */ |
| 67 | constexpr NodeID EmptyNodeID = std::numeric_limits<NodeID>::max(); |
| 68 | /**< Constant EdgeID specifying an equivalent of null edge */ |
| 69 | constexpr EdgeID EmptyEdgeID = std::numeric_limits<EdgeID>::max(); |
| 70 | |
| 71 | // Forward declarations |
| 72 | class TensorDescriptor; |
| 73 | |
| 74 | /** Graph configuration structure */ |
| 75 | struct GraphConfig |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 76 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 77 | bool use_function_memory_manager{ false }; /**< Use a memory manager to manage per-funcion auxilary memory */ |
| 78 | bool use_transition_memory_manager{ false }; /**< Use a memory manager to manager transition buffer memory */ |
| 79 | bool use_tuner{ false }; /**< Use a tuner in tunable backends */ |
| 80 | unsigned int num_threads{ 0 }; /**< Number of threads to use (thread capable backends), if 0 the backend will auto-initialize */ |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 83 | /**< Data layout format */ |
| 84 | enum class DataLayout |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 85 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 86 | NCHW, /** N(Batches), C(Channels), H(Height), W(Width) from slow to fast moving dimension */ |
| 87 | NHWC /** N(Batches), H(Height), W(Width), C(Channels) from slow to fast moving dimension */ |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 88 | }; |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 89 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 90 | /**< Device target types */ |
| 91 | enum class Target |
| 92 | { |
| 93 | UNSPECIFIED, /**< Unspecified Target */ |
| 94 | NEON, /**< NEON capable target device */ |
| 95 | CL, /**< OpenCL capable target device */ |
| 96 | GC, /**< GLES compute capable target device */ |
| 97 | }; |
| 98 | |
| 99 | /** Supported Element-wise operations */ |
| 100 | enum class EltwiseOperation |
| 101 | { |
| 102 | ADD, /**< Arithmetic addition */ |
| 103 | SUB, /**< Arithmetic subtraction */ |
| 104 | MUL /**< Arithmetic multiplication */ |
| 105 | }; |
| 106 | |
| 107 | /** Supported Convolution layer methods */ |
| 108 | enum class ConvolutionMethod |
| 109 | { |
| 110 | DEFAULT, /**< Default approach using internal heuristics */ |
| 111 | GEMM, /**< GEMM based convolution */ |
| 112 | DIRECT, /**< Deep direct convolution */ |
| 113 | WINOGRAD /**< Winograd based convolution */ |
| 114 | }; |
| 115 | |
| 116 | /** Supported Depthwise Convolution layer methods */ |
| 117 | enum class DepthwiseConvolutionMethod |
| 118 | { |
| 119 | DEFAULT, /**< Default approach using internal heuristics */ |
| 120 | GEMV, /**< Generic GEMV based depthwise convolution */ |
| 121 | OPTIMIZED_3x3, /**< Optimized 3x3 direct depthwise convolution */ |
| 122 | }; |
| 123 | |
| 124 | /** Supported nodes */ |
| 125 | enum class NodeType |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 126 | { |
| 127 | ActivationLayer, |
| 128 | BatchNormalizationLayer, |
| 129 | ConvolutionLayer, |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 130 | DepthConcatenateLayer, |
Michalis Spyrou | 7bfe4c5 | 2017-11-24 09:54:20 +0000 | [diff] [blame] | 131 | DepthwiseConvolutionLayer, |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 132 | EltwiseLayer, |
Michalis Spyrou | 27c9efb | 2017-10-09 15:46:30 +0100 | [diff] [blame] | 133 | FlattenLayer, |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 134 | FullyConnectedLayer, |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 135 | NormalizationLayer, |
| 136 | PoolingLayer, |
Michalis Spyrou | 27c9efb | 2017-10-09 15:46:30 +0100 | [diff] [blame] | 137 | ReshapeLayer, |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 138 | SoftmaxLayer, |
| 139 | SplitLayer, |
| 140 | |
| 141 | Input, |
| 142 | Output, |
| 143 | Const, |
Georgios Pinitas | 407c3e6 | 2017-10-25 18:26:46 +0100 | [diff] [blame] | 144 | }; |
| 145 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 146 | /** Backend Memory Manager affinity **/ |
| 147 | enum class MemoryManagerAffinity |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 148 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 149 | Buffer, /**< Affinity at buffer level */ |
| 150 | Offset /**< Affinity at offset level */ |
| 151 | }; |
| 152 | |
| 153 | /** NodeID-index struct |
| 154 | * |
| 155 | * Used to describe connections |
| 156 | */ |
| 157 | struct NodeIdxPair |
| 158 | { |
| 159 | NodeID node_id; /**< Node ID */ |
| 160 | size_t index; /**< Index */ |
| 161 | }; |
| 162 | |
| 163 | /** Common node parameters */ |
| 164 | struct NodeParams |
| 165 | { |
| 166 | std::string name; /**< Node name */ |
| 167 | Target target; /**< Node target */ |
Georgios Pinitas | e2c82fe | 2017-10-02 18:51:47 +0100 | [diff] [blame] | 168 | }; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 169 | } // namespace graph |
| 170 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 171 | #endif /* __ARM_COMPUTE_GRAPH_TYPES_H__ */ |