1 /*
2  * Copyright (c) 2021 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_GRAPH_FUSED_CONVOLUTION_BATCH_NORMALIZATION_WITH_POST_OPS_NODE_H
25 #define ARM_COMPUTE_GRAPH_FUSED_CONVOLUTION_BATCH_NORMALIZATION_WITH_POST_OPS_NODE_H
26 
27 #include "arm_compute/graph/INode.h"
28 
29 namespace arm_compute
30 {
31 namespace graph
32 {
33 /** Batch Normalization node */
34 class FusedConvolutionBatchNormalizationWithPostOpsNode final : public INode
35 {
36 public:
37     /** Constructor
38      *
39      * @param[in] epsilon        Epsilon parameter.
40      * @param[in] info           Convolution layer attributes.
41      * @param[in] num_groups     (Optional) Number of groups (Defaults to 1)
42      * @param[in] method         (Optional) Convolution method to use
43      * @param[in] fast_math_hint (Optional) Fast math hint
44      */
45     FusedConvolutionBatchNormalizationWithPostOpsNode(float epsilon, PadStrideInfo info,
46                                                       unsigned int      num_groups     = 1,
47                                                       ConvolutionMethod method         = ConvolutionMethod::Default,
48                                                       FastMathHint      fast_math_hint = FastMathHint::Disabled);
49 
50     /** Epsilon parameter accessor
51      *
52      * @return Epsilon parameter
53      */
54     float epsilon() const;
55 
56     /** Computes convolution output descriptor
57      *
58      * @param[in] input_descriptor   Input descriptor
59      * @param[in] weights_descriptor Weights descriptor
60      * @param[in] info               Convolution operation attributes
61      *
62      * @return Output descriptor
63      */
64     static TensorDescriptor compute_output_descriptor(const TensorDescriptor &input_descriptor,
65                                                       const TensorDescriptor &weights_descriptor,
66                                                       const PadStrideInfo    &info);
67 
68     /** Sets the convolution layer method to use
69      *
70      * @param[in] method Method to use for convolution
71      */
72     void set_convolution_method(ConvolutionMethod method);
73 
74     /** Number of groups in convolution accessor
75      *
76      * @return Number of groups in convolution
77      */
78     unsigned int num_groups() const;
79 
80     /** Convolution layer method accessor
81      *
82      * @note This is an indication on which convolution layer implementation to use,
83      *       if it fails to be created the library's heuristic approach will be used
84      *
85      * @return Convolution layer method to be used by the node
86      */
87     ConvolutionMethod convolution_method() const;
88 
89     /** Sets the fast math hint
90      *
91      * @param[in] hint Hint to use for convolution
92      */
93     void set_fast_math_hint(FastMathHint hint);
94 
95     /** Fast math hint accessor
96      *
97      * @return Fast math hint to be used by the node
98      */
99     FastMathHint fast_math_hint() const;
100 
101     /** Convolution metadata accessor
102      *
103      * @return Convolution information
104      */
105     PadStrideInfo convolution_info() const;
106 
107     // Inherited overridden methods:
108     NodeType         type() const override;
109     bool             forward_descriptors() override;
110     TensorDescriptor configure_output(size_t idx) const override;
111     void accept(INodeVisitor &v) override;
112 
113 public:
114     static constexpr NodeType node_type = NodeType::FusedConvolutionBatchNormalizationLayerWithPostOpsLayer;
115 
116 private:
117     float _epsilon;
118 
119     PadStrideInfo     _info;
120     unsigned int      _num_groups;
121     ConvolutionMethod _method;
122     FastMathHint      _fast_math_hint;
123 };
124 
125 } // namespace graph
126 } // namespace arm_compute
127 #endif /* ARM_COMPUTE_GRAPH_BATCH_NORMALIZATION_LAYER_NODE_H */
128