xref: /aosp_15_r20/external/ComputeLibrary/src/dynamic_fusion/sketch/gpu/GpuKernelComponentStream.cpp (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 #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 {
GpuKernelComponentStream(GpuComponentServices * services,const MemoryDescriptorMap & mem_map)36 GpuKernelComponentStream::GpuKernelComponentStream(GpuComponentServices *services, const MemoryDescriptorMap &mem_map)
37     : _services{ services }, _component_groups{}, _mem_map{ mem_map }
38 {
39 }
40 
write_workload_code()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     {
47         group.finalize();
48 
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();
54         source_code.add_unit_workload(kernel_code, unit_workload_stage, _mem_map);
55     }
56     return source_code;
57 }
58 
new_component_group()59 void GpuKernelComponentStream::new_component_group()
60 {
61     _component_groups.emplace_back();
62 }
63 
add_component(IGpuKernelComponent * component)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
72