blob: 24acb1b2c155ae91e2d5655e4fb7ea86845d3045 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
Viet-Hoa Doe2e6d742023-03-01 15:46:10 +00002 * Copyright (c) 2022-2023 Arm Limited.
SiCong Lif44bbc52022-08-29 18:25:51 +01003 *
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_CLCOMPONENTDIRECTCONV2D
25#define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D
26
27#include "arm_compute/core/Error.h"
Ramy Elgammaldf6a3b02022-11-30 16:23:10 +000028#include "arm_compute/core/KernelDescriptors.h"
SiCong Lif44bbc52022-08-29 18:25:51 +010029#include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
30#include <memory>
31
32namespace arm_compute
33{
34/** Forward declaration */
35class ITensorInfo;
36namespace experimental
37{
38namespace dynamic_fusion
39{
40/** Forward declaration */
41template <typename T>
42class ArgumentPack;
43class Conv2dAttributes;
44
45/** Component specific settings
46 */
47class ClComponentDirectConv2dSettings
48{
49public:
SiCong Lif44bbc52022-08-29 18:25:51 +010050 /** Get export_to_cl_image flag */
51 bool export_to_cl_image() const;
52
53 /** Set fast_relaxed_math flag */
54 ClComponentDirectConv2dSettings &fast_relaxed_math(bool fast_relaxed_math);
55 /** Get fast_relaxed_math flag */
56 bool fast_relaxed_math() const;
57
Ramy Elgammaldf6a3b02022-11-30 16:23:10 +000058 /** Set direct convolution descriptor */
59 ClComponentDirectConv2dSettings &direct_conv_descriptor(const DirectConvComputeKernelInfo &desc);
60 /** Get direct convolution descriptor */
61 DirectConvComputeKernelInfo direct_conv_descriptor() const;
62
SiCong Lif44bbc52022-08-29 18:25:51 +010063private:
Ramy Elgammaldf6a3b02022-11-30 16:23:10 +000064 bool _fast_relaxed_math{ true };
65 DirectConvComputeKernelInfo _desc{}; // Direct convolution descriptor
SiCong Lif44bbc52022-08-29 18:25:51 +010066};
67
68/** Forward declaration */
Jakub Sujake1c96e72023-07-31 13:36:58 +010069#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +010070class ClTemplateDirectConv2d;
Jakub Sujake1c96e72023-07-31 13:36:58 +010071#else // ACL_INTERNAL_TEST_CKW_IN_DF
72class GpuCkwDirectConv2d;
73#endif // ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +010074
75class ClComponentDirectConv2d final : public IGpuKernelComponent
76{
77public:
78 /** Attributes are a set of backend-agnostic parameters that define what a component does */
79 using Attributes = Conv2dAttributes;
80 /** Settings are a set of backend-specific parameters that influence the implementation of a component */
81 using Settings = ClComponentDirectConv2dSettings;
82
83public:
84 /** Validate the component
85 *
86 * @param[in] properties Component properties
87 * @param[in,out] tensors Tensor arguments to the component
88 * @param[in] attributes Component attributes
89 * @param[in] settings Component settings
90 *
91 * @return Status Validation results
92 *
93 * Tensor argument names:
94 * - ACL_SRC_0: Input
95 * - ACL_SRC_1: Weight
96 * - ACL_SRC_2: Bias (Optional)
97 * - ACL_DST_0: Output
98 *
99 * Tensor argument constness:
100 * - ACL_SRC_0: Const
101 * - ACL_SRC_1: Const
102 * - ACL_SRC_2: Const
103 * - ACL_DST_0: Const
104 *
105 * Valid data layouts:
106 * - NHWC
107 *
108 * Valid data type configurations:
109 * |ACL_SRC_0 |ACL_SRC_1 |ACL_SRC_2 |ACL_DST_0 |
110 * |:--------------|:--------------|:--------------|:--------------|
111 * |F16 |F16 |F16 |F16 |
112 * |F32 |F32 |F32 |F32 |
113 */
114 static Status validate(
115 const Properties &properties,
116 const ArgumentPack<ITensorInfo> &tensors,
117 const Attributes &attributes,
118 const Settings &settings);
119
120 /** Constructor
121 *
122 * Similar to @ref ClComponentDirectConv2d::validate()
123 */
124 ClComponentDirectConv2d(
125 ComponentId id,
126 const Properties &properties,
127 const ArgumentPack<ITensorInfo> &tensors,
128 const Attributes &attributes,
129 const Settings &settings);
130
131 /** Destructor */
132 ~ClComponentDirectConv2d() override;
133 /** Prevent instances of this class from being copy constructed */
134 ClComponentDirectConv2d(const ClComponentDirectConv2d &component) = delete;
135 /** Prevent instances of this class from being copied */
136 ClComponentDirectConv2d &operator=(const ClComponentDirectConv2d &component) = delete;
137 /** Allow instances of this class to be move constructed */
138 ClComponentDirectConv2d(ClComponentDirectConv2d &&component) = default;
139 /** Allow instances of this class to be moved */
140 ClComponentDirectConv2d &operator=(ClComponentDirectConv2d &&component) = default;
Jakub Sujake1c96e72023-07-31 13:36:58 +0100141 /** Get writer for the component */
142#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +0100143 const IGpuTemplateComponentWriter *template_writer() const override;
Jakub Sujake1c96e72023-07-31 13:36:58 +0100144#else // ACL_INTERNAL_TEST_CKW_IN_DF
145 const IGpuCkwComponentDriver *ckw_component_driver() const override;
146#endif // ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +0100147 /** Get component type */
148 GpuComponentType type() const override
149 {
150 return GpuComponentType::Complex;
151 }
152
153private:
Jakub Sujake1c96e72023-07-31 13:36:58 +0100154#ifndef ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +0100155 std::unique_ptr<ClTemplateDirectConv2d> _component_writer;
Jakub Sujake1c96e72023-07-31 13:36:58 +0100156#else // ACL_INTERNAL_TEST_CKW_IN_DF
157 std::unique_ptr<GpuCkwDirectConv2d> _component_writer;
158#endif // ACL_INTERNAL_TEST_CKW_IN_DF
SiCong Lif44bbc52022-08-29 18:25:51 +0100159};
160} // namespace dynamic_fusion
161} // namespace experimental
162} // namespace arm_compute
163#endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D */