SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [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 | */ |
| 24 | #ifndef SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADSKETCHIMPL |
| 25 | #define SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADSKETCHIMPL |
| 26 | |
| 27 | #include "arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | #include "arm_compute/dynamic_fusion/sketch/MemoryDescriptor.h" |
| 29 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 30 | #include "src/dynamic_fusion/sketch/gpu/GpuComponentServices.h" |
| 31 | #include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGraph.h" |
| 32 | #include "src/dynamic_fusion/sketch/gpu/GpuOperatorGroup.h" |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 33 | #include "src/dynamic_fusion/sketch/gpu/GpuWorkloadContextImpl.h" |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 34 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace experimental |
| 38 | { |
| 39 | namespace dynamic_fusion |
| 40 | { |
| 41 | /** Internal implementation of @ref GpuWorkloadSketch */ |
| 42 | class GpuWorkloadSketch::Implementation |
| 43 | { |
| 44 | public: |
| 45 | /** Constructor |
| 46 | * |
| 47 | * @param[in] context global workload creation context |
| 48 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 49 | explicit Implementation(Context *context) |
| 50 | : _context{context}, _comp_services{}, _component_graph{_context, &_comp_services}, _operator_group{} |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | /** Prevent instances of this class from being copy constructed */ |
| 54 | Implementation(const Implementation &impl) = delete; |
| 55 | /** Prevent instances of this class from being copied */ |
| 56 | Implementation &operator=(const Implementation &impl) = delete; |
| 57 | /** Allow instances of this class to be move constructed */ |
| 58 | Implementation(Implementation &&impl) = default; |
| 59 | /** Allow instances of this class to be moved */ |
| 60 | Implementation &operator=(Implementation &&impl) = default; |
| 61 | /** Get workload context */ |
| 62 | const Context *context() const |
| 63 | { |
| 64 | return _context; |
| 65 | } |
| 66 | /** Get component graph */ |
| 67 | const GpuKernelComponentGraph &component_graph() const |
| 68 | { |
| 69 | return _component_graph; |
| 70 | } |
| 71 | /** Get component graph */ |
| 72 | GpuKernelComponentGraph &component_graph() |
| 73 | { |
| 74 | return _component_graph; |
| 75 | } |
| 76 | /** Get operator group */ |
| 77 | const GpuOperatorGroup &operator_group() const |
| 78 | { |
| 79 | return _operator_group; |
| 80 | } |
| 81 | /** Get operator group */ |
| 82 | GpuOperatorGroup &operator_group() |
| 83 | { |
| 84 | return _operator_group; |
| 85 | } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 86 | /** Generate @ref GpuWorkloadSourceCode from the workload sketch |
| 87 | * @note The sketch must be valid. Any error encountered during the building of the code will be thrown. |
| 88 | * |
| 89 | * @return GpuWorkloadSourceCode The generated workload code |
| 90 | */ |
| 91 | GpuWorkloadSourceCode generate_source_code() const |
| 92 | { |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 93 | const auto mem_map = _context->implementation().mem_map(); |
| 94 | return component_graph().fuse(mem_map).write_workload_code(); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 95 | } |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 96 | /** Create a virtual (see @ref MemoryType) tensor info and save it |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 97 | * |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 98 | * @return ITensorInfo* The created virtual tensor info object pointer |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 99 | */ |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 100 | ITensorInfo *create_virtual_tensor() |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 101 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 102 | return _context->implementation().create_virtual_tensor(); |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 103 | } |
| 104 | /** Create an auxiliary (see @ref MemoryType) tensor info and save it |
| 105 | * |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 106 | * @param[in] tensor_info @ref ITensorInfo to copy from |
| 107 | * |
| 108 | * @return ITensorInfo* The created auxiliary tensor info object pointer |
| 109 | */ |
| 110 | ITensorInfo *create_auxiliary_tensor(const ITensorInfo &tensor_info) |
| 111 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 112 | return _context->implementation().create_auxiliary_tensor(tensor_info); |
| 113 | } |
| 114 | |
| 115 | ITensorInfo *get_tensor_info(ITensorInfo::Id id) |
| 116 | { |
| 117 | return _context->implementation().get_tensor_info(id); |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 118 | } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 119 | |
| 120 | private: |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 121 | Context *_context; |
| 122 | GpuComponentServices _comp_services; |
| 123 | GpuKernelComponentGraph _component_graph; |
| 124 | GpuOperatorGroup _operator_group; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 125 | }; |
| 126 | } // namespace dynamic_fusion |
| 127 | } // namespace experimental |
| 128 | } // namespace arm_compute |
| 129 | #endif /* SRC_DYNAMIC_FUSION_SKETCH_GPU_GPUWORKLOADSKETCHIMPL */ |