SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 1 | /* |
| 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 Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 34 | #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" |
| 35 | #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 36 | |
| 37 | using namespace ckw; |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace experimental |
| 41 | { |
| 42 | namespace dynamic_fusion |
| 43 | { |
| 44 | GpuCkwDriver::GpuCkwDriver(const GpuKernelComponentGroup &components) |
| 45 | : _components{ components } |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | std::string GpuCkwDriver::get_name() |
| 50 | { |
| 51 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); |
| 52 | return "todo_get_name"; |
| 53 | } |
| 54 | |
| 55 | std::string GpuCkwDriver::get_code() |
| 56 | { |
| 57 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 58 | ckw::Kernel kernel(get_name().c_str(), GpuTargetLanguage::OpenCL); |
| 59 | GpuCkwKernelWriter root_writer(kernel); |
| 60 | GpuCkwScopedKernelWriter writer(&root_writer); |
| 61 | GpuCkwVariableTable vtable{}; |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 62 | |
| 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 | |
| 80 | CLBuildOptions GpuCkwDriver::get_build_options() |
| 81 | { |
| 82 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TO REMOVE")); |
| 83 | return CLBuildOptions{}; |
| 84 | } |
| 85 | |
| 86 | std::string GpuCkwDriver::get_config_id() |
| 87 | { |
| 88 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); |
| 89 | return ""; |
| 90 | } |
| 91 | |
| 92 | Window 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 | |
| 99 | std::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 |