xref: /aosp_15_r20/external/ComputeLibrary/src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.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_IGPUKERNELCOMPONENT
25 #define SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_IGPUKERNELCOMPONENT
26 
27 #include "Types.h"
28 
29 #include "src/dynamic_fusion/sketch/ArgumentPack.h"
30 #include "src/dynamic_fusion/sketch/gpu/GpuWorkloadSourceCode.h"
31 
32 namespace arm_compute
33 {
34 namespace experimental
35 {
36 namespace dynamic_fusion
37 {
38 /** Properties common to all kernel component types */
39 class KernelProperties
40 {
41 public:
stage(const UnitWorkloadStage & stage)42     KernelProperties &stage(const UnitWorkloadStage &stage)
43     {
44         _stage = stage;
45         return *this;
46     }
stage()47     UnitWorkloadStage stage() const
48     {
49         return _stage;
50     }
51 
52 private:
53     UnitWorkloadStage _stage{};
54 };
55 
56 inline bool operator==(const KernelProperties &config0, const KernelProperties &config1)
57 {
58     return config0.stage() == config1.stage();
59 }
60 
61 /** Forward declaration */
62 class IGpuTemplateComponentWriter;
63 
64 /** An abstract interface of a component. It enables manipulation by the component graph for purposes like fusion
65  */
66 class IGpuKernelComponent
67 {
68 public:
69     using Properties = KernelProperties;
70 
71 public:
72     /** Constructor
73      *
74      * @param[in] id         Component id
75      * @param[in] properties Kernel component properties
76      * @param[in] tensors    Tensor arguments to the components
77      */
IGpuKernelComponent(ComponentId id,const Properties & properties,const ArgumentPack<ITensorInfo> & tensors)78     IGpuKernelComponent(
79         ComponentId                      id,
80         const Properties                &properties,
81         const ArgumentPack<ITensorInfo> &tensors)
82         : _id{ id },
83           _properties{ properties },
84           _tensors{ tensors }
85     {
86     }
87     /** Destructor */
~IGpuKernelComponent()88     virtual ~IGpuKernelComponent()
89     {
90     }
91     /** Get component id */
id()92     ComponentId id() const
93     {
94         return _id;
95     }
96     /** Get tensor arguments */
tensors()97     ArgumentPack<ITensorInfo> tensors() const
98     {
99         return _tensors;
100     }
101     /** Get properties */
properties()102     Properties properties() const
103     {
104         return _properties;
105     }
106     /** Get template writer for the component */
107     virtual const IGpuTemplateComponentWriter *template_writer() const = 0;
108     /** Get component type */
109     virtual GpuComponentType type() const = 0;
110 
111 private:
112     ComponentId               _id{ -1 };
113     Properties                _properties{};
114     ArgumentPack<ITensorInfo> _tensors{};
115 };
116 } // namespace dynamic_fusion
117 } // namespace experimental
118 } // namespace arm_compute
119 #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_IGPUKERNELCOMPONENT */
120