SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 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 "GpuKernelVariableTable.h" |
| 25 | #include "arm_compute/core/CL/CLHelpers.h" |
| 26 | #include "arm_compute/core/ITensorInfo.h" |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 27 | #include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGroup.h" |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace experimental |
| 32 | { |
| 33 | namespace dynamic_fusion |
| 34 | { |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 35 | void GpuKernelVariableTable::declare_variable(const GpuKernelComponentGroup &comp_group, const ITensorInfo *tensor, GpuKernelArgumentInfo argument_info, const std::string &alias) |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 36 | { |
| 37 | ARM_COMPUTE_ERROR_ON_MSG(!tensor->has_valid_id(), "Tensor info with valid id expected"); |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 38 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 39 | // Do not re-declare if the variable associated with the tensor has already been declared |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 40 | auto it = _vars.find(tensor->id()); |
| 41 | |
| 42 | if(it != _vars.end()) |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 43 | { |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 44 | ARM_COMPUTE_ERROR_ON(!(it->second.kernel_argument_info == argument_info)); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 45 | return; |
| 46 | } |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 47 | |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 48 | const auto target = comp_group.get_tile_for_tensor(tensor); |
| 49 | |
| 50 | if(target != tensor) |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 51 | { |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 52 | // If the tensor uses a shared tile, don't declare another variable. |
| 53 | it = _vars.find(target->id()); |
| 54 | |
| 55 | ARM_COMPUTE_ERROR_ON_MSG( |
| 56 | it == _vars.end(), |
| 57 | "The variable used for this tensor must have been declared."); |
| 58 | |
| 59 | _vars[tensor->id()] = it->second; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 60 | } |
| 61 | else |
| 62 | { |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 63 | // Declare variable associated with the tensor |
| 64 | std::stringstream ss; |
Gunes Bayir | 3a1e125 | 2023-01-03 21:26:09 +0000 | [diff] [blame] | 65 | ss << alias << "_t" << abs(tensor->id()); |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 66 | const auto uniq_name = ss.str(); |
| 67 | TensorVariable var{ tensor->id(), uniq_name, argument_info }; |
| 68 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 69 | _vars.emplace(tensor->id(), var); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | GpuKernelVariableTable::TensorVariable GpuKernelVariableTable::get_variable(const ITensorInfo *tensor) const |
| 74 | { |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 75 | const auto var = _vars.at(tensor->id()); |
| 76 | return var; |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | GpuKernelVariableTable::VariableList GpuKernelVariableTable::get_variable_list(const std::vector<const ITensorInfo *> &tensors) const |
| 80 | { |
| 81 | VariableList vars{}; |
| 82 | for(const auto &tensor : tensors) |
| 83 | { |
| 84 | if(!tensor->has_valid_id()) |
| 85 | { |
| 86 | continue; |
| 87 | } |
| 88 | vars.push_back(get_variable(tensor)); |
| 89 | } |
| 90 | return vars; |
| 91 | } |
| 92 | |
| 93 | TagVal::TagVal(const GpuKernelVariableTable::TensorVariable &var) |
| 94 | : value{ var.uniq_name } |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | TagVal::TagVal(const std::string &val) |
| 99 | : value{ val } |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | TagVal::TagVal(const char *val) |
| 104 | : value{ std::string(val) } |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | TagVal::TagVal(const DataType &data_type) |
| 109 | : value{ get_cl_type_from_data_type(data_type) } |
| 110 | { |
| 111 | } |
| 112 | } // namespace dynamic_fusion |
| 113 | } // namespace experimental |
| 114 | } // namespace arm_compute |