• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDEPTHWISECONV2D
25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDEPTHWISECONV2D
26 
27 #include "arm_compute/core/Error.h"
28 #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
29 #include <memory>
30 
31 namespace arm_compute
32 {
33 /** Forward declaration */
34 class ITensorInfo;
35 namespace experimental
36 {
37 namespace dynamic_fusion
38 {
39 /** Forward declaration */
40 template <typename T>
41 class ArgumentPack;
42 class DepthwiseConv2dAttributes;
43 
44 /** Component specific settings
45  */
46 class ClComponentDepthwiseConv2dSettings
47 {
48 public:
49     /** Set export_input_to_cl_image flag */
50     ClComponentDepthwiseConv2dSettings &export_input_to_cl_image(bool cl_image);
51     /** Get export_input_to_cl_image flag */
52     bool export_input_to_cl_image() const;
53 
54     /** Set export_weights_to_cl_image flag */
55     ClComponentDepthwiseConv2dSettings &export_weights_to_cl_image(bool cl_image);
56     /** Get export_weights_to_cl_image flag */
57     bool export_weights_to_cl_image() const;
58 
59     /** Set fast_relaxed_math flag */
60     ClComponentDepthwiseConv2dSettings &fast_relaxed_math(bool fast_relaxed_math);
61     /** Get fast_relaxed_math flag */
62     bool fast_relaxed_math() const;
63 
64     /** Set is_fma_available flag */
65     ClComponentDepthwiseConv2dSettings &is_fma_available(bool is_fma_available);
66     /** Get is_fma_available flag */
67     bool is_fma_available() const;
68 
69     /** Set N0: number of columns processed by each thread */
70     ClComponentDepthwiseConv2dSettings &n0(unsigned int n0);
71     /** Get N0: number of columns processed by each thread */
72     unsigned int n0() const;
73 
74     /** Set M0: number of rows processed by each thread */
75     ClComponentDepthwiseConv2dSettings &m0(unsigned int m0);
76     /** Set M0: number of rows processed by each thread */
77     unsigned int m0() const;
78 
79 private:
80     bool         _export_input_to_cl_image{ false };   /**< Export input to cl_image */
81     bool         _export_weights_to_cl_image{ false }; /**< Export the weights to cl_image */
82     bool         _fast_relaxed_math{ true };           /**< Enable/disable -cl-fast-relaxed-math flag */
83     bool         _is_fma_available{ false };           /**< Is fma instruction available */
84     unsigned int _n0{ 0 };                             /**< Number of columns processed by each thread */
85     unsigned int _m0{ 0 };                             /**< Number of rows processed by each thread */
86 };
87 
88 /** Forward declaration */
89 class ClTemplateDepthwiseConv2d;
90 
91 class ClComponentDepthwiseConv2d final : public IGpuKernelComponent
92 {
93 public:
94     /** Attributes are a set of backend-agnostic parameters that define what a component does */
95     using Attributes = DepthwiseConv2dAttributes;
96     /** Settings are a set of backend-specific parameters that influence the implementation of a component */
97     using Settings = ClComponentDepthwiseConv2dSettings;
98 
99 public:
100     /** Validate the component
101      *
102      * @param[in]     properties Component properties @ref Properties
103      * @param[in,out] tensors    Tensor arguments to the component
104      * @param[in]     attributes Component attributes @ref Attributes
105      * @param[in]     settings   Component settings @ref Settings
106      *
107      * @return Status       Validation results
108      *
109      * Tensor argument names:
110      * - ACL_SRC_0: Input
111      * - ACL_SRC_1: Weight
112      * - ACL_SRC_2: Bias (Optional)
113      * - ACL_DST_0: Output
114      *
115      * Tensor argument constness:
116      * - ACL_SRC_0: Const
117      * - ACL_SRC_1: Const
118      * - ACL_SRC_2: Const
119      * - ACL_DST_0: Const
120      *
121      * Valid data layouts:
122      * - NHWC
123      *
124      * Valid data type configurations:
125      * |ACL_SRC_0      |ACL_SRC_1      |ACL_SRC_2      |ACL_DST_0      |
126      * |:--------------|:--------------|:--------------|:--------------|
127      * |F16            |F16            |F16            |F16            |
128      * |F32            |F32            |F32            |F32            |
129      */
130     static Status validate(
131         const Properties                &properties,
132         const ArgumentPack<ITensorInfo> &tensors,
133         const Attributes                &attributes,
134         const Settings                  &settings);
135 
136     /** Constructor
137      *
138      * Similar to @ref ClComponentDepthwiseConv2d::validate()
139      */
140     ClComponentDepthwiseConv2d(
141         ComponentId                      id,
142         const Properties                &properties,
143         const ArgumentPack<ITensorInfo> &tensors,
144         const Attributes                &attributes,
145         const Settings                  &settings);
146 
147     /** Destructor */
148     ~ClComponentDepthwiseConv2d() override;
149     /** Prevent instances of this class from being copy constructed */
150     ClComponentDepthwiseConv2d(const ClComponentDepthwiseConv2d &component) = delete;
151     /** Prevent instances of this class from being copied */
152     ClComponentDepthwiseConv2d &operator=(const ClComponentDepthwiseConv2d &component) = delete;
153     /** Allow instances of this class to be move constructed */
154     ClComponentDepthwiseConv2d(ClComponentDepthwiseConv2d &&component) = default;
155     /** Allow instances of this class to be moved */
156     ClComponentDepthwiseConv2d &operator=(ClComponentDepthwiseConv2d &&component) = default;
157     /** Get template writer for the component */
158     const IGpuTemplateComponentWriter *template_writer() const override;
159     /** Get component type */
type()160     GpuComponentType type() const override
161     {
162         return GpuComponentType::Complex;
163     }
164 
165 private:
166     std::unique_ptr<ClTemplateDepthwiseConv2d> _component_writer;
167 };
168 } // namespace dynamic_fusion
169 } // namespace experimental
170 } // namespace arm_compute
171 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDEPTHWISECONV2D */
172