1*c217d954SCole Faust /* 2*c217d954SCole Faust * Copyright (c) 2018-2021 Arm Limited. 3*c217d954SCole Faust * 4*c217d954SCole Faust * SPDX-License-Identifier: MIT 5*c217d954SCole Faust * 6*c217d954SCole Faust * Permission is hereby granted, free of charge, to any person obtaining a copy 7*c217d954SCole Faust * of this software and associated documentation files (the "Software"), to 8*c217d954SCole Faust * deal in the Software without restriction, including without limitation the 9*c217d954SCole Faust * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10*c217d954SCole Faust * sell copies of the Software, and to permit persons to whom the Software is 11*c217d954SCole Faust * furnished to do so, subject to the following conditions: 12*c217d954SCole Faust * 13*c217d954SCole Faust * The above copyright notice and this permission notice shall be included in all 14*c217d954SCole Faust * copies or substantial portions of the Software. 15*c217d954SCole Faust * 16*c217d954SCole Faust * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*c217d954SCole Faust * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*c217d954SCole Faust * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*c217d954SCole Faust * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*c217d954SCole Faust * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21*c217d954SCole Faust * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*c217d954SCole Faust * SOFTWARE. 23*c217d954SCole Faust */ 24*c217d954SCole Faust #ifndef ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H 25*c217d954SCole Faust #define ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H 26*c217d954SCole Faust 27*c217d954SCole Faust #include "arm_compute/graph/ITensorAccessor.h" 28*c217d954SCole Faust #include "arm_compute/graph/LayerDescriptors.h" 29*c217d954SCole Faust #include "arm_compute/graph/Types.h" 30*c217d954SCole Faust 31*c217d954SCole Faust namespace arm_compute 32*c217d954SCole Faust { 33*c217d954SCole Faust namespace graph 34*c217d954SCole Faust { 35*c217d954SCole Faust // Forward declaration 36*c217d954SCole Faust class Graph; 37*c217d954SCole Faust 38*c217d954SCole Faust /** Graph builder class 39*c217d954SCole Faust * 40*c217d954SCole Faust * Builds and compiles a graph 41*c217d954SCole Faust */ 42*c217d954SCole Faust class GraphBuilder final 43*c217d954SCole Faust { 44*c217d954SCole Faust public: 45*c217d954SCole Faust /** Adds a Const node to the graph 46*c217d954SCole Faust * 47*c217d954SCole Faust * @param[in] g Graph to add the node to 48*c217d954SCole Faust * @param[in] params Common node parameters 49*c217d954SCole Faust * @param[in] desc Tensor descriptor of the node 50*c217d954SCole Faust * @param[in] accessor (Optional) Accessor of the const node data 51*c217d954SCole Faust * 52*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 53*c217d954SCole Faust */ 54*c217d954SCole Faust static NodeID add_const_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr); 55*c217d954SCole Faust /** Adds an input layer node to the graph 56*c217d954SCole Faust * 57*c217d954SCole Faust * @param[in] g Graph to add the node to 58*c217d954SCole Faust * @param[in] params Common node parameters 59*c217d954SCole Faust * @param[in] desc Tensor descriptor of the Tensor 60*c217d954SCole Faust * @param[in] accessor (Optional) Accessor of the input node data 61*c217d954SCole Faust * 62*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 63*c217d954SCole Faust */ 64*c217d954SCole Faust static NodeID add_input_node(Graph &g, NodeParams params, const TensorDescriptor &desc, ITensorAccessorUPtr accessor = nullptr); 65*c217d954SCole Faust /** Adds an output layer node to the graph 66*c217d954SCole Faust * 67*c217d954SCole Faust * @param[in] g Graph to add the node to 68*c217d954SCole Faust * @param[in] params Common node parameters 69*c217d954SCole Faust * @param[in] input Input to the output node as a NodeID-Index pair 70*c217d954SCole Faust * @param[in] accessor (Optional) Accessor of the output node data 71*c217d954SCole Faust * 72*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 73*c217d954SCole Faust */ 74*c217d954SCole Faust static NodeID add_output_node(Graph &g, NodeParams params, NodeIdxPair input, ITensorAccessorUPtr accessor = nullptr); 75*c217d954SCole Faust /** Adds an activation layer node to the graph 76*c217d954SCole Faust * 77*c217d954SCole Faust * @param[in] g Graph to add the node to 78*c217d954SCole Faust * @param[in] params Common node parameters 79*c217d954SCole Faust * @param[in] input Input to the activation layer node as a NodeID-Index pair 80*c217d954SCole Faust * @param[in] act_info Activation layer information 81*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 82*c217d954SCole Faust * 83*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 84*c217d954SCole Faust */ 85*c217d954SCole Faust static NodeID add_activation_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info, 86*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo()); 87*c217d954SCole Faust /** Adds an activation layer node to the graph 88*c217d954SCole Faust * 89*c217d954SCole Faust * @param[in] g Graph to add the node to 90*c217d954SCole Faust * @param[in] params Common node parameters 91*c217d954SCole Faust * @param[in] input Input to the activation layer node as a NodeID-Index pair 92*c217d954SCole Faust * @param[in] op Reduction Operation: min or max 93*c217d954SCole Faust * @param[in] axis Axis to perform reduction operation across 94*c217d954SCole Faust * @param[in] out_data_type (Optional) Output data type 95*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 96*c217d954SCole Faust * 97*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 98*c217d954SCole Faust */ 99*c217d954SCole Faust static NodeID add_arg_min_max_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, unsigned int axis, 100*c217d954SCole Faust DataType out_data_type = DataType::UNKNOWN, 101*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo()); 102*c217d954SCole Faust /** Adds a batch normalization layer node to the graph 103*c217d954SCole Faust * 104*c217d954SCole Faust * @param[in] g Graph to add the node to 105*c217d954SCole Faust * @param[in] params Common node parameters 106*c217d954SCole Faust * @param[in] input Input to the batch normalization layer node as a NodeID-Index pair 107*c217d954SCole Faust * @param[in] epsilon Epsilon parameter 108*c217d954SCole Faust * @param[in] mean_accessor Const Node ID that contains the mean values 109*c217d954SCole Faust * @param[in] var_accessor Const Node ID that contains the variance values 110*c217d954SCole Faust * @param[in] beta_accessor Const Node ID that contains the beta values. Can be EmptyNodeID 111*c217d954SCole Faust * @param[in] gamma_accessor Const Node ID that contains the gamma values. Can be EmptyNodeID 112*c217d954SCole Faust * 113*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 114*c217d954SCole Faust */ 115*c217d954SCole Faust static NodeID add_batch_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, float epsilon, 116*c217d954SCole Faust ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr var_accessor = nullptr, 117*c217d954SCole Faust ITensorAccessorUPtr beta_accessor = nullptr, ITensorAccessorUPtr gamma_accessor = nullptr); 118*c217d954SCole Faust /** Adds a bounding box transform layer node to the graph 119*c217d954SCole Faust * 120*c217d954SCole Faust * @param[in] g Graph to add the node to 121*c217d954SCole Faust * @param[in] params Common node parameters 122*c217d954SCole Faust * @param[in] input Input to the bounding box transform layer node as a NodeID-Index pair 123*c217d954SCole Faust * @param[in] deltas Deltas input to the bounding box transform layer node as a NodeID-Index pair 124*c217d954SCole Faust * @param[in] info Bounding Box Transform information 125*c217d954SCole Faust * 126*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 127*c217d954SCole Faust */ 128*c217d954SCole Faust static NodeID add_bounding_box_transform_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair deltas, BoundingBoxTransformInfo info); 129*c217d954SCole Faust /** Adds an channel shuffle layer node to the graph 130*c217d954SCole Faust * 131*c217d954SCole Faust * @param[in] g Graph to add the node to 132*c217d954SCole Faust * @param[in] params Common node parameters 133*c217d954SCole Faust * @param[in] input Input to the activation layer node as a NodeID-Index pair 134*c217d954SCole Faust * @param[in] num_groups Number of groups 135*c217d954SCole Faust * 136*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 137*c217d954SCole Faust */ 138*c217d954SCole Faust static NodeID add_channel_shuffle_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_groups); 139*c217d954SCole Faust /** Adds a convolution layer node to the graph 140*c217d954SCole Faust * 141*c217d954SCole Faust * @param[in] g Graph to add the node to 142*c217d954SCole Faust * @param[in] params Common node parameters 143*c217d954SCole Faust * @param[in] input Input to the convolution layer node as a NodeID-Index pair 144*c217d954SCole Faust * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 145*c217d954SCole Faust * @param[in] depth Number of convolution kernels 146*c217d954SCole Faust * @param[in] conv_info Convolution layer information 147*c217d954SCole Faust * @param[in] num_groups (Optional) Number of groups for a grouped convolution. Defaults to 1 148*c217d954SCole Faust * @param[in] method (Optional) Convolution method to use 149*c217d954SCole Faust * @param[in] fast_math_hint (Optional) Fast math hint 150*c217d954SCole Faust * @param[in] weights_accessor (Optional) Accessor of the weights node data 151*c217d954SCole Faust * @param[in] bias_accessor (Optional) Accessor of the bias node data 152*c217d954SCole Faust * @param[in] weights_quant_info (Optional) Weights quantization info 153*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 154*c217d954SCole Faust * 155*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 156*c217d954SCole Faust */ 157*c217d954SCole Faust static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, 158*c217d954SCole Faust Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1, 159*c217d954SCole Faust ConvolutionMethod method = ConvolutionMethod::Default, FastMathHint fast_math_hint = FastMathHint::Disabled, 160*c217d954SCole Faust ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, 161*c217d954SCole Faust const QuantizationInfo &weights_quant_info = QuantizationInfo(), 162*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo()); 163*c217d954SCole Faust /** Adds a deconvolution layer node to the graph 164*c217d954SCole Faust * 165*c217d954SCole Faust * @param[in] g Graph to add the node to 166*c217d954SCole Faust * @param[in] params Common node parameters 167*c217d954SCole Faust * @param[in] input Input to the convolution layer node as a NodeID-Index pair 168*c217d954SCole Faust * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 169*c217d954SCole Faust * @param[in] depth Number of convolution kernels 170*c217d954SCole Faust * @param[in] deconv_info Convolution layer information 171*c217d954SCole Faust * @param[in] weights_accessor (Optional) Accessor of the weights node data 172*c217d954SCole Faust * @param[in] bias_accessor (Optional) Accessor of the bias node data 173*c217d954SCole Faust * 174*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 175*c217d954SCole Faust */ 176*c217d954SCole Faust static NodeID add_deconvolution_node(Graph &g, NodeParams params, NodeIdxPair input, 177*c217d954SCole Faust Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo deconv_info, 178*c217d954SCole Faust ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); 179*c217d954SCole Faust /** Adds a depth concatenate node to the graph 180*c217d954SCole Faust * 181*c217d954SCole Faust * @param[in] g Graph to add the node to 182*c217d954SCole Faust * @param[in] params Common node parameters 183*c217d954SCole Faust * @param[in] inputs Inputs to the concatenate layer node as a NodeID-Index pair 184*c217d954SCole Faust * @param[in] concat_descriptor Concatenation layer descriptor 185*c217d954SCole Faust * 186*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 187*c217d954SCole Faust */ 188*c217d954SCole Faust static NodeID add_concatenate_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, const descriptors::ConcatLayerDescriptor &concat_descriptor); 189*c217d954SCole Faust /** Adds an depth to space layer node to the graph 190*c217d954SCole Faust * 191*c217d954SCole Faust * @param[in] g Graph to add the node to 192*c217d954SCole Faust * @param[in] params Common node parameters 193*c217d954SCole Faust * @param[in] input Input to the depth to space layer node as a NodeID-Index pair 194*c217d954SCole Faust * @param[in] block_shape Block shape to reshape tensor with 195*c217d954SCole Faust * 196*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 197*c217d954SCole Faust */ 198*c217d954SCole Faust static NodeID add_depth_to_space_node(Graph &g, NodeParams params, NodeIdxPair input, int32_t block_shape); 199*c217d954SCole Faust /** Adds a depth-wise convolution layer node to the graph 200*c217d954SCole Faust * 201*c217d954SCole Faust * @param[in] g Graph to add the node to 202*c217d954SCole Faust * @param[in] params Common node parameters 203*c217d954SCole Faust * @param[in] input Input to the depthwise convolution layer node as a NodeID-Index pair 204*c217d954SCole Faust * @param[in] kernel_spatial_extend Spatial extend of convolution kernels 205*c217d954SCole Faust * @param[in] conv_info Convolution layer information 206*c217d954SCole Faust * @param[in] depth_multiplier (Optional) Depth multiplier parameter. 207*c217d954SCole Faust * @param[in] method (Optional) Convolution method to use 208*c217d954SCole Faust * @param[in] weights_accessor (Optional) Accessor of the weights node data 209*c217d954SCole Faust * @param[in] bias_accessor (Optional) Accessor of the bias node data 210*c217d954SCole Faust * @param[in] quant_info (Optional) Weights quantization info 211*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 212*c217d954SCole Faust * 213*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 214*c217d954SCole Faust */ 215*c217d954SCole Faust static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, 216*c217d954SCole Faust Size2D kernel_spatial_extend, PadStrideInfo conv_info, int depth_multiplier = 1, 217*c217d954SCole Faust DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::Default, 218*c217d954SCole Faust ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo &quant_info = QuantizationInfo(), 219*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo()); 220*c217d954SCole Faust /** Adds an element-wise layer node to the graph 221*c217d954SCole Faust * 222*c217d954SCole Faust * @param[in] g Graph to add the node to 223*c217d954SCole Faust * @param[in] params Common node parameters 224*c217d954SCole Faust * @param[in] input0 First input to the element-wise operation layer node as a NodeID-Index pair 225*c217d954SCole Faust * @param[in] input1 Second input to the element-wise operation layer node as a NodeID-Index pair 226*c217d954SCole Faust * @param[in] operation Element-wise operation to perform 227*c217d954SCole Faust * 228*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 229*c217d954SCole Faust */ 230*c217d954SCole Faust static NodeID add_elementwise_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, EltwiseOperation operation); 231*c217d954SCole Faust /** Adds a dequantization node to the graph 232*c217d954SCole Faust * 233*c217d954SCole Faust * @param[in] g Graph to add the node to 234*c217d954SCole Faust * @param[in] params Common node parameters 235*c217d954SCole Faust * @param[in] input Input to the dequantization node as a NodeID-Index pair 236*c217d954SCole Faust * 237*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 238*c217d954SCole Faust */ 239*c217d954SCole Faust static NodeID add_dequantization_node(Graph &g, NodeParams params, NodeIdxPair input); 240*c217d954SCole Faust /** Adds a detection output layer node to the graph 241*c217d954SCole Faust * 242*c217d954SCole Faust * @param[in] g Graph to add the node to 243*c217d954SCole Faust * @param[in] params Common node parameters 244*c217d954SCole Faust * @param[in] input_loc Location input to the detection output layer node as a NodeID-Index pair 245*c217d954SCole Faust * @param[in] input_conf Confidence input to the detection output layer node as a NodeID-Index pair 246*c217d954SCole Faust * @param[in] input_priorbox PriorBox input to the detection output layer node as a NodeID-Index pair 247*c217d954SCole Faust * @param[in] detect_info Detection output layer parameters 248*c217d954SCole Faust * 249*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 250*c217d954SCole Faust */ 251*c217d954SCole Faust static NodeID add_detection_output_node(Graph &g, NodeParams params, NodeIdxPair input_loc, NodeIdxPair input_conf, NodeIdxPair input_priorbox, const DetectionOutputLayerInfo &detect_info); 252*c217d954SCole Faust /** Adds a detection post process layer node to the graph 253*c217d954SCole Faust * 254*c217d954SCole Faust * @param[in] g Graph to add the node to 255*c217d954SCole Faust * @param[in] params Common node parameters 256*c217d954SCole Faust * @param[in] input_box_encoding Boxes input to the detection output layer node as a NodeID-Index pair 257*c217d954SCole Faust * @param[in] input_class_prediction Class prediction input to the detection output layer node as a NodeID-Index pair 258*c217d954SCole Faust * @param[in] detect_info Detection output layer parameters 259*c217d954SCole Faust * @param[in] anchors_accessor (Optional) Const Node ID that contains the anchor values 260*c217d954SCole Faust * @param[in] anchor_quant_info (Optional) Anchor quantization info 261*c217d954SCole Faust * 262*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 263*c217d954SCole Faust */ 264*c217d954SCole Faust static NodeID add_detection_post_process_node(Graph &g, NodeParams params, NodeIdxPair input_box_encoding, NodeIdxPair input_class_prediction, 265*c217d954SCole Faust const DetectionPostProcessLayerInfo &detect_info, ITensorAccessorUPtr anchors_accessor = nullptr, 266*c217d954SCole Faust const QuantizationInfo &anchor_quant_info = QuantizationInfo()); 267*c217d954SCole Faust /** Adds a Dummy node to the graph 268*c217d954SCole Faust * 269*c217d954SCole Faust * @note this node if for debugging purposes. Just alters the shape of the graph pipeline as requested. 270*c217d954SCole Faust * 271*c217d954SCole Faust * @param[in] g Graph to add the node to 272*c217d954SCole Faust * @param[in] params Common node parameters 273*c217d954SCole Faust * @param[in] input Input to the dummy node as a NodeID-Index pair 274*c217d954SCole Faust * @param[in] shape Output shape 275*c217d954SCole Faust * 276*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 277*c217d954SCole Faust */ 278*c217d954SCole Faust static NodeID add_dummy_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); 279*c217d954SCole Faust /** Adds a flatten layer node to the graph 280*c217d954SCole Faust * 281*c217d954SCole Faust * @param[in] g Graph to add the node to 282*c217d954SCole Faust * @param[in] params Common node parameters 283*c217d954SCole Faust * @param[in] input Input to the flatten layer node as a NodeID-Index pair 284*c217d954SCole Faust * 285*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 286*c217d954SCole Faust */ 287*c217d954SCole Faust static NodeID add_flatten_node(Graph &g, NodeParams params, NodeIdxPair input); 288*c217d954SCole Faust /** Adds a fully connected layer node to the graph 289*c217d954SCole Faust * 290*c217d954SCole Faust * @param[in] g Graph to add the layer to 291*c217d954SCole Faust * @param[in] params Common node parameters 292*c217d954SCole Faust * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 293*c217d954SCole Faust * @param[in] num_outputs Number of output neurons 294*c217d954SCole Faust * @param[in] weights_nid Node ID of the weights node data 295*c217d954SCole Faust * @param[in] bias_nid (Optional) Node ID of the bias node data. Defaults to EmptyNodeID 296*c217d954SCole Faust * @param[in] fc_info (Optional) Fully connected layer metadata 297*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 298*c217d954SCole Faust * @param[in] fast_math_hint (Optional) Fast math hint 299*c217d954SCole Faust * 300*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 301*c217d954SCole Faust */ 302*c217d954SCole Faust static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, 303*c217d954SCole Faust NodeID weights_nid, NodeID bias_nid = EmptyNodeID, 304*c217d954SCole Faust const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), 305*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo(), 306*c217d954SCole Faust FastMathHint fast_math_hint = FastMathHint::Disabled); 307*c217d954SCole Faust /** Adds a fully connected layer node to the graph 308*c217d954SCole Faust * 309*c217d954SCole Faust * @param[in] g Graph to add the layer to 310*c217d954SCole Faust * @param[in] params Common node parameters 311*c217d954SCole Faust * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 312*c217d954SCole Faust * @param[in] num_outputs Number of output neurons 313*c217d954SCole Faust * @param[in] weights_accessor (Optional) Accessor of the weights node data 314*c217d954SCole Faust * @param[in] bias_accessor (Optional) Accessor of the bias node data 315*c217d954SCole Faust * @param[in] fc_info (Optional) Fully connected layer metadata 316*c217d954SCole Faust * @param[in] weights_quant_info (Optional) Weights quantization info 317*c217d954SCole Faust * @param[in] out_quant_info (Optional) Output quantization info 318*c217d954SCole Faust * @param[in] fast_math_hint (Optional) Fast math hint 319*c217d954SCole Faust * 320*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 321*c217d954SCole Faust */ 322*c217d954SCole Faust static NodeID add_fully_connected_layer(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_outputs, 323*c217d954SCole Faust ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, 324*c217d954SCole Faust const FullyConnectedLayerInfo fc_info = FullyConnectedLayerInfo(), 325*c217d954SCole Faust const QuantizationInfo &weights_quant_info = QuantizationInfo(), 326*c217d954SCole Faust const QuantizationInfo &out_quant_info = QuantizationInfo(), 327*c217d954SCole Faust FastMathHint fast_math_hint = FastMathHint::Disabled); 328*c217d954SCole Faust /** Adds a generate proposals layer node to the graph 329*c217d954SCole Faust * 330*c217d954SCole Faust * @param[in] g Graph to add the layer to 331*c217d954SCole Faust * @param[in] params Common node parameters 332*c217d954SCole Faust * @param[in] scores Input scores to the generate proposals layer node as a NodeID-Index pair 333*c217d954SCole Faust * @param[in] deltas Input deltas to the generate proposals layer node as a NodeID-Index pair 334*c217d954SCole Faust * @param[in] anchors Input anchors to the generate proposals layer node as a NodeID-Index pair 335*c217d954SCole Faust * @param[in] info Generate proposals operation information 336*c217d954SCole Faust * 337*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 338*c217d954SCole Faust */ 339*c217d954SCole Faust static NodeID add_generate_proposals_node(Graph &g, NodeParams params, NodeIdxPair scores, NodeIdxPair deltas, 340*c217d954SCole Faust NodeIdxPair anchors, GenerateProposalsInfo info); 341*c217d954SCole Faust /** Adds a L2 Normalize layer node to the graph 342*c217d954SCole Faust * 343*c217d954SCole Faust * @param[in] g Graph to add the node to 344*c217d954SCole Faust * @param[in] params Common node parameters 345*c217d954SCole Faust * @param[in] input Input to the normalization layer node as a NodeID-Index pair 346*c217d954SCole Faust * @param[in] axis Axis to perform normalization on 347*c217d954SCole Faust * @param[in] epsilon Lower bound value for the normalization 348*c217d954SCole Faust * 349*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 350*c217d954SCole Faust */ 351*c217d954SCole Faust static NodeID add_l2_normalize_node(Graph &g, NodeParams params, NodeIdxPair input, int axis, float epsilon); 352*c217d954SCole Faust /** Adds a normalization layer node to the graph 353*c217d954SCole Faust * 354*c217d954SCole Faust * @param[in] g Graph to add the node to 355*c217d954SCole Faust * @param[in] params Common node parameters 356*c217d954SCole Faust * @param[in] input Input to the normalization layer node as a NodeID-Index pair 357*c217d954SCole Faust * @param[in] norm_info Normalization layer information 358*c217d954SCole Faust * 359*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 360*c217d954SCole Faust */ 361*c217d954SCole Faust static NodeID add_normalization_node(Graph &g, NodeParams params, NodeIdxPair input, NormalizationLayerInfo norm_info); 362*c217d954SCole Faust /** Adds a normalize planar YUV layer node to the graph 363*c217d954SCole Faust * 364*c217d954SCole Faust * @param[in] g Graph to add the node to 365*c217d954SCole Faust * @param[in] params Common node parameters 366*c217d954SCole Faust * @param[in] input Input to the normalize planar YUV layer node as a NodeID-Index pair 367*c217d954SCole Faust * @param[in] mean_accessor Const Node ID that contains the mean values 368*c217d954SCole Faust * @param[in] std_accessor Const Node ID that contains the variance values 369*c217d954SCole Faust * 370*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 371*c217d954SCole Faust */ 372*c217d954SCole Faust static NodeID add_normalize_planar_yuv_node(Graph &g, NodeParams params, NodeIdxPair input, 373*c217d954SCole Faust ITensorAccessorUPtr mean_accessor = nullptr, ITensorAccessorUPtr std_accessor = nullptr); 374*c217d954SCole Faust /** Adds a pad layer node to the graph 375*c217d954SCole Faust * 376*c217d954SCole Faust * @param[in] g Graph to add the node to 377*c217d954SCole Faust * @param[in] params Common node parameters 378*c217d954SCole Faust * @param[in] input Input to the reshape layer node as a NodeID-Index pair 379*c217d954SCole Faust * @param[in] paddings The padding for each spatial dimension of the input tensor. The pair padding[i] 380*c217d954SCole Faust * specifies the front and the end padding in the i-th dimension. 381*c217d954SCole Faust * @param[in] pad_value Padding value to be used. Defaults to 0 382*c217d954SCole Faust * 383*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 384*c217d954SCole Faust */ 385*c217d954SCole Faust static NodeID add_pad_node(Graph &g, NodeParams params, NodeIdxPair input, const PaddingList &paddings, PixelValue pad_value = PixelValue()); 386*c217d954SCole Faust /** Adds a permute layer node to the graph 387*c217d954SCole Faust * 388*c217d954SCole Faust * @param[in] g Graph to add the node to 389*c217d954SCole Faust * @param[in] params Common node parameters 390*c217d954SCole Faust * @param[in] input Input to the reshape layer node as a NodeID-Index pair 391*c217d954SCole Faust * @param[in] perm Permutation vector 392*c217d954SCole Faust * @param[in] layout (Optional) Data layout to assign to permuted tensor. 393*c217d954SCole Faust * If UNKNOWN then the input's layout will be used. 394*c217d954SCole Faust * 395*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 396*c217d954SCole Faust */ 397*c217d954SCole Faust static NodeID add_permute_node(Graph &g, NodeParams params, NodeIdxPair input, PermutationVector perm, DataLayout layout = DataLayout::UNKNOWN); 398*c217d954SCole Faust /** Adds a pooling layer node to the graph 399*c217d954SCole Faust * 400*c217d954SCole Faust * @param[in] g Graph to add the node to 401*c217d954SCole Faust * @param[in] params Common node parameters 402*c217d954SCole Faust * @param[in] input Input to the pooling layer node as a NodeID-Index pair 403*c217d954SCole Faust * @param[in] pool_info Pooling layer information 404*c217d954SCole Faust * 405*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 406*c217d954SCole Faust */ 407*c217d954SCole Faust static NodeID add_pooling_node(Graph &g, NodeParams params, NodeIdxPair input, PoolingLayerInfo pool_info); 408*c217d954SCole Faust /** Adds a prelu layer node to the graph 409*c217d954SCole Faust * 410*c217d954SCole Faust * @param[in] g Graph to add the node to 411*c217d954SCole Faust * @param[in] params Common node parameters 412*c217d954SCole Faust * @param[in] input Input to the PRelu node as a NodeID-Index pair 413*c217d954SCole Faust * @param[in] alpha Alpha input to the PRelu node as a NodeID-Index pair 414*c217d954SCole Faust * 415*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 416*c217d954SCole Faust */ 417*c217d954SCole Faust static NodeID add_prelu_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair alpha); 418*c217d954SCole Faust /** Adds a print layer node to the graph 419*c217d954SCole Faust * 420*c217d954SCole Faust * @param[in] g Graph to add the node to 421*c217d954SCole Faust * @param[in] params Common node parameters 422*c217d954SCole Faust * @param[in] input Input to the print layer node as a NodeID-Index pair 423*c217d954SCole Faust * @param[in] stream Output stream. 424*c217d954SCole Faust * @param[in] format_info (Optional) Format info. 425*c217d954SCole Faust * @param[in] transform (Optional) Transformation function to be applied to the input tensor before printing. 426*c217d954SCole Faust * 427*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 428*c217d954SCole Faust */ 429*c217d954SCole Faust static NodeID add_print_node(Graph &g, NodeParams params, NodeIdxPair input, std::ostream &stream, const IOFormatInfo &format_info = IOFormatInfo(), 430*c217d954SCole Faust const std::function<ITensor *(ITensor *)> transform = nullptr); 431*c217d954SCole Faust /** Adds a priorbox layer node to the graph 432*c217d954SCole Faust * 433*c217d954SCole Faust * @param[in] g Graph to add the node to 434*c217d954SCole Faust * @param[in] params Common node parameters 435*c217d954SCole Faust * @param[in] input0 First input to the priorbox layer node as a NodeID-Index pair 436*c217d954SCole Faust * @param[in] input1 Second input to the priorbox layer node as a NodeID-Index pair 437*c217d954SCole Faust * @param[in] prior_info PriorBox parameters 438*c217d954SCole Faust * 439*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 440*c217d954SCole Faust */ 441*c217d954SCole Faust static NodeID add_priorbox_node(Graph &g, NodeParams params, NodeIdxPair input0, NodeIdxPair input1, const PriorBoxLayerInfo &prior_info); 442*c217d954SCole Faust /** Adds a quantization layer node to the graph 443*c217d954SCole Faust * 444*c217d954SCole Faust * @param[in] g Graph to add the node to 445*c217d954SCole Faust * @param[in] params Common node parameters 446*c217d954SCole Faust * @param[in] input Input to the quantization layer node as a NodeID-Index pair 447*c217d954SCole Faust * @param[in] out_quant_info Output quantization info 448*c217d954SCole Faust * 449*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 450*c217d954SCole Faust */ 451*c217d954SCole Faust static NodeID add_quantization_node(Graph &g, NodeParams params, NodeIdxPair input, const QuantizationInfo &out_quant_info); 452*c217d954SCole Faust /** Adds a reduction sum layer node to the graph 453*c217d954SCole Faust * 454*c217d954SCole Faust * @param[in] g Graph to add the node to 455*c217d954SCole Faust * @param[in] params Common node parameters 456*c217d954SCole Faust * @param[in] input Input to the reorg layer node as a NodeID-Index pair 457*c217d954SCole Faust * @param[in] op Reduction operation 458*c217d954SCole Faust * @param[in] axis Reduction axis 459*c217d954SCole Faust * @param[in] keep_dims (Optional) Whether to keep the reduced dimension after the operation. Defaults to true. 460*c217d954SCole Faust * 461*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 462*c217d954SCole Faust */ 463*c217d954SCole Faust static NodeID add_reduction_operation_node(Graph &g, NodeParams params, NodeIdxPair input, ReductionOperation op, int axis, bool keep_dims = true); 464*c217d954SCole Faust /** Adds a reorg layer node to the graph 465*c217d954SCole Faust * 466*c217d954SCole Faust * @param[in] g Graph to add the node to 467*c217d954SCole Faust * @param[in] params Common node parameters 468*c217d954SCole Faust * @param[in] input Input to the reorg layer node as a NodeID-Index pair 469*c217d954SCole Faust * @param[in] stride Stride value to use for reorganizing the values in the output tensor. 470*c217d954SCole Faust * 471*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 472*c217d954SCole Faust */ 473*c217d954SCole Faust static NodeID add_reorg_node(Graph &g, NodeParams params, NodeIdxPair input, int stride); 474*c217d954SCole Faust /** Adds a reshape layer node to the graph 475*c217d954SCole Faust * 476*c217d954SCole Faust * @param[in] g Graph to add the node to 477*c217d954SCole Faust * @param[in] params Common node parameters 478*c217d954SCole Faust * @param[in] input Input to the reshape layer node as a NodeID-Index pair 479*c217d954SCole Faust * @param[in] shape Output reshaped shape 480*c217d954SCole Faust * 481*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 482*c217d954SCole Faust */ 483*c217d954SCole Faust static NodeID add_reshape_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); 484*c217d954SCole Faust /** Adds a resize layer node to the graph 485*c217d954SCole Faust * 486*c217d954SCole Faust * @param[in] g Graph to add the node to 487*c217d954SCole Faust * @param[in] params Common node parameters 488*c217d954SCole Faust * @param[in] input Input to the reshape layer node as a NodeID-Index pair 489*c217d954SCole Faust * @param[in] policy Interpolation policy 490*c217d954SCole Faust * @param[in] width_scale Width scaling factor 491*c217d954SCole Faust * @param[in] height_scale Height scaling factor 492*c217d954SCole Faust * 493*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 494*c217d954SCole Faust */ 495*c217d954SCole Faust static NodeID add_resize_node(Graph &g, NodeParams params, NodeIdxPair input, InterpolationPolicy policy, float width_scale, float height_scale); 496*c217d954SCole Faust /** Adds a ROI align layer node to the graph 497*c217d954SCole Faust * 498*c217d954SCole Faust * @param[in] g Graph to add the node to 499*c217d954SCole Faust * @param[in] params Common node parameters 500*c217d954SCole Faust * @param[in] input Input to the reshape layer node as a NodeID-Index pair 501*c217d954SCole Faust * @param[in] rois Input containing the ROIs. 502*c217d954SCole Faust * @param[in] pool_info Contains pooling operation information described in @ref ROIPoolingLayerInfo. 503*c217d954SCole Faust * 504*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 505*c217d954SCole Faust */ 506*c217d954SCole Faust static NodeID add_roi_align_node(Graph &g, NodeParams params, NodeIdxPair input, NodeIdxPair rois, ROIPoolingLayerInfo pool_info); 507*c217d954SCole Faust /** Adds a scale layer node to the graph 508*c217d954SCole Faust * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor). 509*c217d954SCole Faust * output = input * mul_w + add_w 510*c217d954SCole Faust * 511*c217d954SCole Faust * @param[in] g Graph to add the layer to 512*c217d954SCole Faust * @param[in] params Common node parameters 513*c217d954SCole Faust * @param[in] input Input to the fully connected layer node as a NodeID-Index pair 514*c217d954SCole Faust * @param[in] mul_accessor (Optional) Accessor of the mul node data 515*c217d954SCole Faust * @param[in] add_accessor (Optional) Accessor of the add node data 516*c217d954SCole Faust * 517*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 518*c217d954SCole Faust */ 519*c217d954SCole Faust static NodeID add_scale_layer(Graph &g, const NodeParams ¶ms, NodeIdxPair input, 520*c217d954SCole Faust ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr); 521*c217d954SCole Faust /** Adds a softmax node to the graph 522*c217d954SCole Faust * 523*c217d954SCole Faust * @param[in] g Graph to add the node to 524*c217d954SCole Faust * @param[in] params Common node parameters 525*c217d954SCole Faust * @param[in] input Input to the softmax layer node as a NodeID-Index pair 526*c217d954SCole Faust * @param[in] beta Beta parameter 527*c217d954SCole Faust * 528*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 529*c217d954SCole Faust */ 530*c217d954SCole Faust static NodeID add_softmax_node(Graph &g, NodeParams params, NodeIdxPair input, float beta = 1.f); 531*c217d954SCole Faust /** Adds a slice node to the graph 532*c217d954SCole Faust * 533*c217d954SCole Faust * @param[in] g Graph to add the node to 534*c217d954SCole Faust * @param[in] params Common node parameters 535*c217d954SCole Faust * @param[in] input Input to the slice layer node as a NodeID-Index pair 536*c217d954SCole Faust * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 537*c217d954SCole Faust * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 538*c217d954SCole Faust * 539*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 540*c217d954SCole Faust */ 541*c217d954SCole Faust static NodeID add_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends); 542*c217d954SCole Faust /** Adds a split node to the graph 543*c217d954SCole Faust * 544*c217d954SCole Faust * @param[in] g Graph to add the node to 545*c217d954SCole Faust * @param[in] params Common node parameters 546*c217d954SCole Faust * @param[in] input Input to the split layer node as a NodeID-Index pair 547*c217d954SCole Faust * @param[in] num_splits Number of different splits 548*c217d954SCole Faust * @param[in] axis (Optional) Split axis. Defaults to 0 549*c217d954SCole Faust * 550*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 551*c217d954SCole Faust */ 552*c217d954SCole Faust static NodeID add_split_node(Graph &g, NodeParams params, NodeIdxPair input, unsigned int num_splits, unsigned int axis = 0); 553*c217d954SCole Faust /** Adds a stack layer node to the graph 554*c217d954SCole Faust * 555*c217d954SCole Faust * @param[in] g Graph to add the node to 556*c217d954SCole Faust * @param[in] params Common node parameters 557*c217d954SCole Faust * @param[in] inputs Inputs to the reorg layer node as a NodeID-Index pair 558*c217d954SCole Faust * @param[in] axis Axis along which the input tensors have to be packed 559*c217d954SCole Faust * 560*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 561*c217d954SCole Faust */ 562*c217d954SCole Faust static NodeID add_stack_node(Graph &g, NodeParams params, const std::vector<NodeIdxPair> &inputs, int axis); 563*c217d954SCole Faust /** Adds a strided slice node to the graph 564*c217d954SCole Faust * 565*c217d954SCole Faust * @param[in] g Graph to add the node to 566*c217d954SCole Faust * @param[in] params Common node parameters 567*c217d954SCole Faust * @param[in] input Input to the strided slice layer node as a NodeID-Index pair 568*c217d954SCole Faust * @param[in] starts The starts of the dimensions of the input tensor to be sliced. The length must be of rank(input). 569*c217d954SCole Faust * @param[in] ends The ends of the dimensions of the input tensor to be sliced. The length must be of rank(input). 570*c217d954SCole Faust * @param[in] strides The strides of the dimensions of the input tensor to be sliced. The length must be of rank(input). 571*c217d954SCole Faust * @param[in] info Contains masks for the starts, ends and strides 572*c217d954SCole Faust * 573*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 574*c217d954SCole Faust */ 575*c217d954SCole Faust static NodeID add_strided_slice_node(Graph &g, NodeParams params, NodeIdxPair input, Coordinates &starts, Coordinates &ends, BiStrides &strides, StridedSliceLayerInfo info); 576*c217d954SCole Faust /** Adds a yolo layer to the graph 577*c217d954SCole Faust * 578*c217d954SCole Faust * @param[in] g Graph to add the node to 579*c217d954SCole Faust * @param[in] params Common node parameters 580*c217d954SCole Faust * @param[in] input Input to the yolo layer node as a NodeID-Index pair 581*c217d954SCole Faust * @param[in] act_info Activation layer parameters 582*c217d954SCole Faust * 583*c217d954SCole Faust * @return Node ID of the created node, EmptyNodeID in case of error 584*c217d954SCole Faust */ 585*c217d954SCole Faust static NodeID add_yolo_node(Graph &g, NodeParams params, NodeIdxPair input, ActivationLayerInfo act_info); 586*c217d954SCole Faust }; 587*c217d954SCole Faust } // namespace graph 588*c217d954SCole Faust } // namespace arm_compute 589*c217d954SCole Faust #endif /* ARM_COMPUTE_GRAPH_GRAPH_BUILDER_H */ 590