SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 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 "GpuKernelVariableTable.h" |
| 25 | #include "arm_compute/core/CL/CLHelpers.h" |
| 26 | #include "arm_compute/core/ITensorInfo.h" |
| 27 | |
| 28 | namespace arm_compute |
| 29 | { |
| 30 | namespace experimental |
| 31 | { |
| 32 | namespace dynamic_fusion |
| 33 | { |
| 34 | void GpuKernelVariableTable::declare_variable(const ITensorInfo *tensor, GpuKernelArgumentInfo argument_info, bool is_interm, const std::string &alias) |
| 35 | { |
| 36 | ARM_COMPUTE_ERROR_ON_MSG(!tensor->has_valid_id(), "Tensor info with valid id expected"); |
| 37 | // Do not re-declare if the variable associated with the tensor has already been declared |
| 38 | if(get_variable(tensor).has_valid_id()) |
| 39 | { |
| 40 | ARM_COMPUTE_ERROR_ON(!(get_variable(tensor).kernel_argument_info == argument_info)); |
| 41 | return; |
| 42 | } |
| 43 | // Declare variable associated with the tensor |
| 44 | std::stringstream ss; |
| 45 | ss << alias << "_t" << tensor->id(); |
| 46 | const auto uniq_name = ss.str(); |
| 47 | TensorVariable var{ tensor->id(), uniq_name, argument_info }; |
| 48 | |
| 49 | if(is_interm) |
| 50 | { |
| 51 | _interm_var = var; |
| 52 | _interm_tensors.insert(tensor->id()); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | _vars.emplace(tensor->id(), var); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | GpuKernelVariableTable::TensorVariable GpuKernelVariableTable::get_variable(const ITensorInfo *tensor) const |
| 61 | { |
| 62 | const TensorVariable empty_var{}; |
| 63 | if(_vars.find(tensor->id()) != _vars.end()) |
| 64 | { |
| 65 | return _vars.at(tensor->id()); |
| 66 | } |
| 67 | if(_interm_tensors.find(tensor->id()) != _interm_tensors.end()) |
| 68 | { |
| 69 | return _interm_var; |
| 70 | } |
| 71 | return empty_var; |
| 72 | } |
| 73 | |
| 74 | GpuKernelVariableTable::VariableList GpuKernelVariableTable::get_variable_list(const std::vector<const ITensorInfo *> &tensors) const |
| 75 | { |
| 76 | VariableList vars{}; |
| 77 | for(const auto &tensor : tensors) |
| 78 | { |
| 79 | if(!tensor->has_valid_id()) |
| 80 | { |
| 81 | continue; |
| 82 | } |
| 83 | vars.push_back(get_variable(tensor)); |
| 84 | } |
| 85 | return vars; |
| 86 | } |
| 87 | |
| 88 | TagVal::TagVal(const GpuKernelVariableTable::TensorVariable &var) |
| 89 | : value{ var.uniq_name } |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | TagVal::TagVal(const std::string &val) |
| 94 | : value{ val } |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | TagVal::TagVal(const char *val) |
| 99 | : value{ std::string(val) } |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | TagVal::TagVal(const DataType &data_type) |
| 104 | : value{ get_cl_type_from_data_type(data_type) } |
| 105 | { |
| 106 | } |
| 107 | } // namespace dynamic_fusion |
| 108 | } // namespace experimental |
| 109 | } // namespace arm_compute |