blob: a24a172d773157bd0d2bbea046c8077bcc1c5f6a [file] [log] [blame]
SiCong Li19844f62023-05-16 16:46:34 +01001/*
2 * Copyright (c) 2023 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 "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwDriver.h"
25
26#include "src/dynamic_fusion/sketch/gpu/ckw_driver/IGpuCkwComponentDriver.h"
27#include "src/dynamic_fusion/sketch/gpu/components/IGpuKernelComponent.h"
28
29#include "arm_compute/core/Error.h"
30#include "arm_compute/core/Window.h"
31#include "src/common/utils/Log.h"
32#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwVariableTable.h"
SiCong Li16b37522023-07-18 17:56:49 +010033#include "src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/type_converter/Common.h"
SiCong Li19844f62023-05-16 16:46:34 +010034
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010035#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h"
36#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h"
SiCong Li19844f62023-05-16 16:46:34 +010037
38using namespace ckw;
39namespace arm_compute
40{
41namespace experimental
42{
43namespace dynamic_fusion
44{
45GpuCkwDriver::GpuCkwDriver(const GpuKernelComponentGroup &components)
SiCong Li16b37522023-07-18 17:56:49 +010046 : _components{ components }, _kernel{ GpuTargetLanguage::OpenCL }, _code{}
SiCong Li19844f62023-05-16 16:46:34 +010047{
SiCong Li16b37522023-07-18 17:56:49 +010048 // Generate kernel name
49 std::string name = "";
50 for(auto &comp : _components)
51 {
52 auto ckw_driver = comp->ckw_component_driver();
53 ARM_COMPUTE_ERROR_ON(ckw_driver == nullptr);
54 name += ckw_driver->get_name(_components) + "__";
55 }
SiCong Li19844f62023-05-16 16:46:34 +010056
SiCong Li16b37522023-07-18 17:56:49 +010057 // Generate kernel code
58 _kernel.name(name);
SiCong Li23882a92023-06-28 09:49:45 +010059 GpuCkwKernelWriter root_writer(_kernel);
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010060 GpuCkwScopedKernelWriter writer(&root_writer);
61 GpuCkwVariableTable vtable{};
SiCong Li19844f62023-05-16 16:46:34 +010062
SiCong Li19844f62023-05-16 16:46:34 +010063 for(auto &comp : _components)
64 {
65 auto ckw_driver = comp->ckw_component_driver();
66 ARM_COMPUTE_ERROR_ON(ckw_driver == nullptr);
67 ckw_driver->write_component_code(_components, vtable, writer);
68 }
SiCong Li16b37522023-07-18 17:56:49 +010069 _code = root_writer.generate_code();
SiCong Li19844f62023-05-16 16:46:34 +010070}
71
SiCong Li16b37522023-07-18 17:56:49 +010072std::string GpuCkwDriver::get_name()
SiCong Li19844f62023-05-16 16:46:34 +010073{
SiCong Li16b37522023-07-18 17:56:49 +010074 return _kernel.name();
75}
76
77std::string GpuCkwDriver::get_code()
78{
79 return _code;
SiCong Li19844f62023-05-16 16:46:34 +010080}
81
82std::string GpuCkwDriver::get_config_id()
83{
SiCong Li16b37522023-07-18 17:56:49 +010084 std::string id = "";
85 for(auto &comp : _components)
86 {
87 auto ckw_driver = comp->ckw_component_driver();
88 ARM_COMPUTE_ERROR_ON(ckw_driver == nullptr);
89 id = ckw_driver->get_tuner_id(_components) + "__";
90 }
91 return id;
SiCong Li19844f62023-05-16 16:46:34 +010092}
93
94Window GpuCkwDriver::get_window() const
95{
96 const auto root_comp = _components.get_root_component();
97 ARM_COMPUTE_ERROR_ON_MSG(root_comp == nullptr, "No root component found");
98 return root_comp->ckw_component_driver()->get_window();
99}
100
SiCong Li23882a92023-06-28 09:49:45 +0100101GpuKernelArgumentList GpuCkwDriver::get_kernel_arguments()
SiCong Li19844f62023-05-16 16:46:34 +0100102{
SiCong Li23882a92023-06-28 09:49:45 +0100103 GpuKernelArgumentList args{};
104 for(const auto &arg : _kernel.arguments())
SiCong Li19844f62023-05-16 16:46:34 +0100105 {
SiCong Li23882a92023-06-28 09:49:45 +0100106 switch(arg.type())
107 {
108 case KernelArgument::Type::TensorStorage:
109 {
110 args.emplace_back(static_cast<ITensorInfo::Id>(arg.id()), from_ckw(arg.tensor_storage_type()));
111 break;
112 }
113 case KernelArgument::Type::TensorComponent:
114 {
115 args.emplace_back(static_cast<ITensorInfo::Id>(arg.id()), from_ckw(arg.tensor_component_type()));
116 break;
117 }
118 default:
119 {
120 ARM_COMPUTE_ERROR("Unsupported KernelArgument Type");
121 break;
122 }
123 }
SiCong Li19844f62023-05-16 16:46:34 +0100124 }
SiCong Li23882a92023-06-28 09:49:45 +0100125 return args;
SiCong Li19844f62023-05-16 16:46:34 +0100126}
127
128} // namespace dynamic_fusion
129} // namespace experimental
130} // namespace arm_compute