SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 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 | */ |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 24 | #ifndef ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_IGPUKERNELCOMPONENT |
| 25 | #define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_IGPUKERNELCOMPONENT |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 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: |
| 42 | KernelProperties &stage(const UnitWorkloadStage &stage) |
| 43 | { |
| 44 | _stage = stage; |
| 45 | return *this; |
| 46 | } |
| 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; |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 63 | class IGpuCkwComponentDriver; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 64 | |
| 65 | /** An abstract interface of a component. It enables manipulation by the component graph for purposes like fusion |
| 66 | */ |
| 67 | class IGpuKernelComponent |
| 68 | { |
| 69 | public: |
| 70 | using Properties = KernelProperties; |
| 71 | |
| 72 | public: |
| 73 | /** Constructor |
| 74 | * |
| 75 | * @param[in] id Component id |
| 76 | * @param[in] properties Kernel component properties |
| 77 | * @param[in] tensors Tensor arguments to the components |
| 78 | */ |
| 79 | IGpuKernelComponent( |
| 80 | ComponentId id, |
| 81 | const Properties &properties, |
| 82 | const ArgumentPack<ITensorInfo> &tensors) |
| 83 | : _id{ id }, |
| 84 | _properties{ properties }, |
| 85 | _tensors{ tensors } |
| 86 | { |
| 87 | } |
| 88 | /** Destructor */ |
| 89 | virtual ~IGpuKernelComponent() |
| 90 | { |
| 91 | } |
| 92 | /** Get component id */ |
| 93 | ComponentId id() const |
| 94 | { |
| 95 | return _id; |
| 96 | } |
| 97 | /** Get tensor arguments */ |
| 98 | ArgumentPack<ITensorInfo> tensors() const |
| 99 | { |
| 100 | return _tensors; |
| 101 | } |
| 102 | /** Get properties */ |
| 103 | Properties properties() const |
| 104 | { |
| 105 | return _properties; |
| 106 | } |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 107 | /** Get writer for the component */ |
| 108 | virtual const IGpuTemplateComponentWriter *template_writer() const |
| 109 | { |
| 110 | return nullptr; |
| 111 | } |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 112 | virtual const IGpuCkwComponentDriver *ckw_component_driver() const |
| 113 | { |
| 114 | return nullptr; |
| 115 | } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 116 | /** Get component type */ |
| 117 | virtual GpuComponentType type() const = 0; |
| 118 | |
| 119 | private: |
| 120 | ComponentId _id{ -1 }; |
| 121 | Properties _properties{}; |
| 122 | ArgumentPack<ITensorInfo> _tensors{}; |
| 123 | }; |
| 124 | } // namespace dynamic_fusion |
| 125 | } // namespace experimental |
| 126 | } // namespace arm_compute |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 127 | #endif /* ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_COMPONENTS_IGPUKERNELCOMPONENT */ |