blob: a2b6623370afc24657368c8ddf273fc51bb20b60 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
SiCong Li23882a92023-06-28 09:49:45 +01002 * Copyright (c) 2022-2023 Arm Limited.
SiCong Lif44bbc52022-08-29 18:25:51 +01003 *
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
30namespace arm_compute
31{
32namespace experimental
33{
34namespace dynamic_fusion
35{
SiCong Li23882a92023-06-28 09:49:45 +010036GpuKernelComponentStream::GpuKernelComponentStream(GpuWorkloadContext *context, GpuComponentServices *services, const MemoryDescriptorMap &mem_map)
37 : _context{ context }, _services{ services }, _component_groups{}, _mem_map{ mem_map }
SiCong Lif44bbc52022-08-29 18:25:51 +010038{
39}
40
41GpuWorkloadSourceCode 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 Do04f46202022-12-14 14:49:56 +000047 group.finalize();
48
SiCong Lif44bbc52022-08-29 18:25:51 +010049 // 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 Li23882a92023-06-28 09:49:45 +010054 source_code.add_unit_workload(kernel_code, unit_workload_stage, _mem_map, _context);
SiCong Lif44bbc52022-08-29 18:25:51 +010055 }
56 return source_code;
57}
58
59void GpuKernelComponentStream::new_component_group()
60{
61 _component_groups.emplace_back();
62}
63
64bool 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