blob: d5c03c60c574397eb1cc1879b1a5d2042c43e213 [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"
33
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010034#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h"
35#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h"
SiCong Li19844f62023-05-16 16:46:34 +010036
37using namespace ckw;
38namespace arm_compute
39{
40namespace experimental
41{
42namespace dynamic_fusion
43{
44GpuCkwDriver::GpuCkwDriver(const GpuKernelComponentGroup &components)
45 : _components{ components }
46{
47}
48
49std::string GpuCkwDriver::get_name()
50{
51 ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO"));
52 return "todo_get_name";
53}
54
55std::string GpuCkwDriver::get_code()
56{
57 ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO"));
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010058 ckw::Kernel kernel(get_name().c_str(), GpuTargetLanguage::OpenCL);
59 GpuCkwKernelWriter root_writer(kernel);
60 GpuCkwScopedKernelWriter writer(&root_writer);
61 GpuCkwVariableTable vtable{};
SiCong Li19844f62023-05-16 16:46:34 +010062
63 // Global Kernel Writer Driver code
64
65 // The following is just an incomplete example of using the kernel writer
66
67 // Iterate over component specific Ckw Driver; generate component code and concatenate them
68 for(auto &comp : _components)
69 {
70 auto ckw_driver = comp->ckw_component_driver();
71 ARM_COMPUTE_ERROR_ON(ckw_driver == nullptr);
72 ckw_driver->write_component_code(_components, vtable, writer);
73 }
74
75 std::string code = root_writer.generate_code();
76
77 return code;
78}
79
80CLBuildOptions GpuCkwDriver::get_build_options()
81{
82 ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TO REMOVE"));
83 return CLBuildOptions{};
84}
85
86std::string GpuCkwDriver::get_config_id()
87{
88 ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO"));
89 return "";
90}
91
92Window GpuCkwDriver::get_window() const
93{
94 const auto root_comp = _components.get_root_component();
95 ARM_COMPUTE_ERROR_ON_MSG(root_comp == nullptr, "No root component found");
96 return root_comp->ckw_component_driver()->get_window();
97}
98
99std::map<ITensorInfo::Id, GpuKernelArgument> GpuCkwDriver::get_tensors()
100{
101 ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO"));
102 // Assemble GpuKernelArguments
103 std::map<ITensorInfo::Id, GpuKernelArgument> tensors;
104 for(const auto t : _components.get_argument_tensors())
105 {
106 tensors.emplace(
107 t->id(),
108 GpuKernelArgument{ *t, { GpuKernelArgumentInfo::Type::Tensor_Special_0 } });
109 }
110 return tensors;
111}
112
113} // namespace dynamic_fusion
114} // namespace experimental
115} // namespace arm_compute