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" |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 33 | #include "src/dynamic_fusion/sketch/gpu/ckw_driver/components/utils/TypeConverter.h" |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 34 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 35 | #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwKernelWriter.h" |
| 36 | #include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h" |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 37 | |
| 38 | using namespace ckw; |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace experimental |
| 42 | { |
| 43 | namespace dynamic_fusion |
| 44 | { |
| 45 | GpuCkwDriver::GpuCkwDriver(const GpuKernelComponentGroup &components) |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 46 | : _components{ components }, _kernel{ GpuTargetLanguage::OpenCL } |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 47 | { |
| 48 | } |
| 49 | |
| 50 | std::string GpuCkwDriver::get_name() |
| 51 | { |
| 52 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 53 | return "unnamed"; |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | std::string GpuCkwDriver::get_code() |
| 57 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 58 | _kernel.name(get_name()); |
| 59 | GpuCkwKernelWriter root_writer(_kernel); |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 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 |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 64 | for(auto &comp : _components) |
| 65 | { |
| 66 | auto ckw_driver = comp->ckw_component_driver(); |
| 67 | ARM_COMPUTE_ERROR_ON(ckw_driver == nullptr); |
| 68 | ckw_driver->write_component_code(_components, vtable, writer); |
| 69 | } |
| 70 | |
| 71 | std::string code = root_writer.generate_code(); |
| 72 | |
| 73 | return code; |
| 74 | } |
| 75 | |
| 76 | CLBuildOptions GpuCkwDriver::get_build_options() |
| 77 | { |
| 78 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TO REMOVE")); |
| 79 | return CLBuildOptions{}; |
| 80 | } |
| 81 | |
| 82 | std::string GpuCkwDriver::get_config_id() |
| 83 | { |
| 84 | ARM_COMPUTE_LOG_PARAMS(std::string("[V1] TODO")); |
| 85 | return ""; |
| 86 | } |
| 87 | |
| 88 | Window GpuCkwDriver::get_window() const |
| 89 | { |
| 90 | const auto root_comp = _components.get_root_component(); |
| 91 | ARM_COMPUTE_ERROR_ON_MSG(root_comp == nullptr, "No root component found"); |
| 92 | return root_comp->ckw_component_driver()->get_window(); |
| 93 | } |
| 94 | |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 95 | GpuKernelArgumentList GpuCkwDriver::get_kernel_arguments() |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 96 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 97 | GpuKernelArgumentList args{}; |
| 98 | for(const auto &arg : _kernel.arguments()) |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 99 | { |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 100 | switch(arg.type()) |
| 101 | { |
| 102 | case KernelArgument::Type::TensorStorage: |
| 103 | { |
| 104 | args.emplace_back(static_cast<ITensorInfo::Id>(arg.id()), from_ckw(arg.tensor_storage_type())); |
| 105 | break; |
| 106 | } |
| 107 | case KernelArgument::Type::TensorComponent: |
| 108 | { |
| 109 | args.emplace_back(static_cast<ITensorInfo::Id>(arg.id()), from_ckw(arg.tensor_component_type())); |
| 110 | break; |
| 111 | } |
| 112 | default: |
| 113 | { |
| 114 | ARM_COMPUTE_ERROR("Unsupported KernelArgument Type"); |
| 115 | break; |
| 116 | } |
| 117 | } |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 118 | } |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame^] | 119 | return args; |
SiCong Li | 19844f6 | 2023-05-16 16:46:34 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | } // namespace dynamic_fusion |
| 123 | } // namespace experimental |
| 124 | } // namespace arm_compute |