blob: fec22b84a58ffe39974a055c45b128381ee55713 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
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_CLCOMPONENTDIRECTCONV2D
25#define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D
26
27#include "arm_compute/core/Error.h"
28#include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
29#include <memory>
30
31namespace arm_compute
32{
33/** Forward declaration */
34class ITensorInfo;
35namespace experimental
36{
37namespace dynamic_fusion
38{
39/** Forward declaration */
40template <typename T>
41class ArgumentPack;
42class Conv2dAttributes;
43
44/** Component specific settings
45 */
46class ClComponentDirectConv2dSettings
47{
48public:
49 /** Set export_to_cl_image flag */
50 ClComponentDirectConv2dSettings &export_to_cl_image(bool cl_image);
51 /** Get export_to_cl_image flag */
52 bool export_to_cl_image() const;
53
54 /** Set fast_relaxed_math flag */
55 ClComponentDirectConv2dSettings &fast_relaxed_math(bool fast_relaxed_math);
56 /** Get fast_relaxed_math flag */
57 bool fast_relaxed_math() const;
58
59private:
60 bool _export_to_cl_image{ false };
61 bool _fast_relaxed_math{ true };
62};
63
64/** Forward declaration */
65class ClTemplateDirectConv2d;
66
67class ClComponentDirectConv2d final : public IGpuKernelComponent
68{
69public:
70 /** Attributes are a set of backend-agnostic parameters that define what a component does */
71 using Attributes = Conv2dAttributes;
72 /** Settings are a set of backend-specific parameters that influence the implementation of a component */
73 using Settings = ClComponentDirectConv2dSettings;
74
75public:
76 /** Validate the component
77 *
78 * @param[in] properties Component properties
79 * @param[in,out] tensors Tensor arguments to the component
80 * @param[in] attributes Component attributes
81 * @param[in] settings Component settings
82 *
83 * @return Status Validation results
84 *
85 * Tensor argument names:
86 * - ACL_SRC_0: Input
87 * - ACL_SRC_1: Weight
88 * - ACL_SRC_2: Bias (Optional)
89 * - ACL_DST_0: Output
90 *
91 * Tensor argument constness:
92 * - ACL_SRC_0: Const
93 * - ACL_SRC_1: Const
94 * - ACL_SRC_2: Const
95 * - ACL_DST_0: Const
96 *
97 * Valid data layouts:
98 * - NHWC
99 *
100 * Valid data type configurations:
101 * |ACL_SRC_0 |ACL_SRC_1 |ACL_SRC_2 |ACL_DST_0 |
102 * |:--------------|:--------------|:--------------|:--------------|
103 * |F16 |F16 |F16 |F16 |
104 * |F32 |F32 |F32 |F32 |
105 */
106 static Status validate(
107 const Properties &properties,
108 const ArgumentPack<ITensorInfo> &tensors,
109 const Attributes &attributes,
110 const Settings &settings);
111
112 /** Constructor
113 *
114 * Similar to @ref ClComponentDirectConv2d::validate()
115 */
116 ClComponentDirectConv2d(
117 ComponentId id,
118 const Properties &properties,
119 const ArgumentPack<ITensorInfo> &tensors,
120 const Attributes &attributes,
121 const Settings &settings);
122
123 /** Destructor */
124 ~ClComponentDirectConv2d() override;
125 /** Prevent instances of this class from being copy constructed */
126 ClComponentDirectConv2d(const ClComponentDirectConv2d &component) = delete;
127 /** Prevent instances of this class from being copied */
128 ClComponentDirectConv2d &operator=(const ClComponentDirectConv2d &component) = delete;
129 /** Allow instances of this class to be move constructed */
130 ClComponentDirectConv2d(ClComponentDirectConv2d &&component) = default;
131 /** Allow instances of this class to be moved */
132 ClComponentDirectConv2d &operator=(ClComponentDirectConv2d &&component) = default;
133 /** Get template writer for the component */
134 const IGpuTemplateComponentWriter *template_writer() const override;
135 /** Get component type */
136 GpuComponentType type() const override
137 {
138 return GpuComponentType::Complex;
139 }
140
141private:
142 std::unique_ptr<ClTemplateDirectConv2d> _component_writer;
143};
144} // namespace dynamic_fusion
145} // namespace experimental
146} // namespace arm_compute
147#endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTDIRECTCONV2D */