xref: /aosp_15_r20/external/ComputeLibrary/src/dynamic_fusion/sketch/gpu/components/cl/ClComponentCast.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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_CLCOMPONENTCAST
25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTCAST
26 
27 #include "arm_compute/dynamic_fusion/sketch/attributes/CastAttributes.h"
28 #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
29 
30 namespace arm_compute
31 {
32 /** Forward declaration */
33 class ITensorInfo;
34 namespace experimental
35 {
36 namespace dynamic_fusion
37 {
38 /** Forward declaration */
39 template <typename T>
40 class ArgumentPack;
41 
42 /** Component specific settings
43  */
44 class ClComponentCastSettings
45 {
46 public:
47 private:
48 };
49 
50 /** Forward declaration */
51 class ClTemplateCast;
52 
53 class ClComponentCast final : public IGpuKernelComponent
54 {
55 public:
56     /** Attributes are a set of backend-agnostic parameters that define what a component does */
57     using Attributes = CastAttributes;
58     /** Settings are a set of backend-specific parameters that influence the implementation of a component */
59     using Settings = ClComponentCastSettings;
60 
61     /** Validate the component
62      *
63      * @param[in]     properties Component properties @ref Properties
64      * @param[in,out] tensors    Tensor arguments to the component
65      * @param[in]     attributes Component attributes @ref Attributes
66      * @param[in]     settings   Component settings @ref Settings
67      *
68      * @return Status        Validation results
69      *
70      * Tensor argument names:
71      * - ACL_SRC_0: Input
72      * - ACL_DST_0: Output
73      *
74      * Tensor argument constness:
75      * - ACL_SRC_0: Const
76      * - ACL_DST_0: Const
77      *
78      * Valid data layouts:
79      * - All
80      *
81      ** Valid data type configurations:
82      * |ACL_SRC_0      |ACL_DST_0                              |
83      * |:--------------|:--------------------------------------|
84      * |U8             | S8, U16, S16, U32, S32, F16, F32      |
85      * |U16            | U8, S8, S16, U32, S32, F16, F32       |
86      * |S16            | U8, S8, U16, U32, S32, F16, F32       |
87      * |U32            | U8, S8, U16, S16, S32, F16, F32       |
88      * |S32            | U8, S8, U16, S16, U32, F16, F32       |
89      * |F16            | U8, S8, U16, S16, U32, S32, F32       |
90      * |F32            | U8, S8, U16, S16, U32, S32, F16       |
91      */
92     static Status validate(
93         const Properties                &properties,
94         const ArgumentPack<ITensorInfo> &tensors,
95         const Attributes                &attributes,
96         const Settings                  &settings);
97 
98     /** Constructor
99      *
100      * Similar to @ref ClComponentCast::validate()
101      */
102     ClComponentCast(ComponentId                      id,
103                     const Properties                &properties,
104                     const ArgumentPack<ITensorInfo> &tensors,
105                     const Attributes                &attributes,
106                     const Settings                  &settings);
107 
108     /** Destructor */
109     ~ClComponentCast() override;
110     /** Prevent instances of this class from being copy constructed */
111     ClComponentCast(const ClComponentCast &component) = delete;
112     /** Prevent instances of this class from being copied */
113     ClComponentCast &operator=(const ClComponentCast &component) = delete;
114     /** Allow instances of this class to be move constructed */
115     ClComponentCast(ClComponentCast &&component) = default;
116     /** Allow instances of this class to be moved */
117     ClComponentCast &operator=(ClComponentCast &&component) = default;
118     /** Get template writer for the component */
119     const IGpuTemplateComponentWriter *template_writer() const override;
120     /** Get component type */
type()121     GpuComponentType type() const override
122     {
123         return GpuComponentType::Simple;
124     }
125 
126 private:
127     std::unique_ptr<ClTemplateCast> _component_writer;
128 };
129 } // namespace dynamic_fusion
130 } // namespace experimental
131 } // namespace arm_compute
132 
133 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_CL_CLCOMPONENTCAST */
134