SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +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 | */ |
| 24 | #include "GpuKernelComponentStream.h" |
| 25 | |
| 26 | #include "src/dynamic_fusion/sketch/gpu/GpuLogicalKernel.h" |
| 27 | #include "src/dynamic_fusion/sketch/gpu/GpuWorkloadSourceCode.h" |
| 28 | #include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | namespace experimental |
| 33 | { |
| 34 | namespace dynamic_fusion |
| 35 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 36 | GpuKernelComponentStream::GpuKernelComponentStream(GpuWorkloadContext *context, GpuComponentServices *services, const MemoryDescriptorMap &mem_map) |
| 37 | : _context{ context }, _services{ services }, _component_groups{}, _mem_map{ mem_map } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
| 41 | GpuWorkloadSourceCode GpuKernelComponentStream::write_workload_code() |
| 42 | { |
| 43 | GpuWorkloadSourceCode source_code; |
| 44 | // Traverse through component groups and assemble workload together |
| 45 | for(auto && group : _component_groups) |
| 46 | { |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 47 | group.finalize(); |
| 48 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 49 | // Write kernel code |
| 50 | GpuLogicalKernel logical_kernel(_services, group); |
| 51 | const GpuKernelSourceCode kernel_code = logical_kernel.write_kernel_code(); |
| 52 | // The whole unit workload stage is determined by the root component |
| 53 | const auto unit_workload_stage = group.get_root_component()->properties().stage(); |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 54 | source_code.add_unit_workload(kernel_code, unit_workload_stage, _mem_map, _context); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 55 | } |
| 56 | return source_code; |
| 57 | } |
| 58 | |
| 59 | void GpuKernelComponentStream::new_component_group() |
| 60 | { |
| 61 | _component_groups.emplace_back(); |
| 62 | } |
| 63 | |
| 64 | bool GpuKernelComponentStream::add_component(IGpuKernelComponent *component) |
| 65 | { |
| 66 | ARM_COMPUTE_ERROR_ON(_component_groups.empty()); |
| 67 | return _component_groups.back().add_component(component); |
| 68 | } |
| 69 | } // namespace dynamic_fusion |
| 70 | } // namespace experimental |
| 71 | } // namespace arm_compute |