SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +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 | #include "GpuKernelComponentGraph.h" |
| 25 | |
| 26 | #include "arm_compute/dynamic_fusion/sketch/MemoryDescriptor.h" |
| 27 | |
| 28 | namespace arm_compute |
| 29 | { |
| 30 | namespace experimental |
| 31 | { |
| 32 | namespace dynamic_fusion |
| 33 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 34 | std::vector<DependencyGraph::TensorId> |
| 35 | GpuKernelComponentGraph::get_tensor_ids(const std::vector<const ITensorInfo *> tensors) |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 36 | { |
| 37 | std::vector<DependencyGraph::TensorId> tensor_ids{}; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 38 | std::transform(std::begin(tensors), std::end(tensors), std::back_inserter(tensor_ids), |
| 39 | [](const auto &t) { return t->id(); }); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 40 | return tensor_ids; |
| 41 | } |
| 42 | |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 43 | GpuKernelComponentGraph::GpuKernelComponentGraph(GpuWorkloadContext *context, GpuComponentServices *services) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 44 | : _context{context}, _services{services}, _components{}, _tensors{}, _dependency_graph{} |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 48 | GpuKernelComponentStream GpuKernelComponentGraph::fuse(const MemoryDescriptorMap &mem_map) const |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 49 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | GpuKernelComponentStream stream{_context, _services, mem_map}; |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 51 | const auto op_seq = _dependency_graph.build_operators_sequence(); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 52 | |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 53 | stream.new_component_group(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 54 | for (auto op : op_seq) |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 55 | { |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 56 | const auto component = _components.at(op.op).get(); |
SiCong Li | 5a2bc01 | 2023-01-12 12:54:49 +0000 | [diff] [blame] | 57 | const auto success = stream.add_component(component); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 58 | if (!success) // Assume first failure was because the root component is unfusable |
Ramy Elgammal | 002e653 | 2023-01-11 18:48:04 +0000 | [diff] [blame] | 59 | { |
| 60 | stream.new_component_group(); |
| 61 | const auto success = stream.add_component(component); |
| 62 | ARM_COMPUTE_ERROR_ON(!success); |
| 63 | ARM_COMPUTE_UNUSED(success); |
| 64 | } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 65 | } |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 66 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 67 | return stream; |
| 68 | } |
| 69 | } // namespace dynamic_fusion |
| 70 | } // namespace experimental |
| 71 | } // namespace arm_compute |