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 "ClTemplateStore.h" |
| 25 | |
| 26 | #include "src/dynamic_fusion/sketch/gpu/GpuKernelComponentGroup.h" |
| 27 | |
| 28 | namespace arm_compute |
| 29 | { |
| 30 | namespace experimental |
| 31 | { |
| 32 | namespace dynamic_fusion |
| 33 | { |
| 34 | ClTemplateStore::ClTemplateStore(ComponentId id, const ArgumentPack<ITensorInfo> &tensors) |
| 35 | : IGpuTemplateComponentWriter{ id, tensors }, _src{}, _dst{} |
| 36 | { |
| 37 | _src = this->tensors().get_const_tensor(TensorType::ACL_SRC_0); |
| 38 | _dst = this->tensors().get_const_tensor(TensorType::ACL_DST_0); |
| 39 | } |
| 40 | |
| 41 | std::string ClTemplateStore::get_name() const |
| 42 | { |
| 43 | return "store"; |
| 44 | } |
| 45 | |
| 46 | std::string ClTemplateStore::get_component_code(const ComponentGroup &comp_group) const |
| 47 | { |
| 48 | ARM_COMPUTE_UNUSED(comp_group); |
Gunes Bayir | 7dc0234 | 2022-11-21 21:46:50 +0000 | [diff] [blame] | 49 | |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 50 | return R"_( |
| 51 | //------------------ START KERNEL {{meta_kernel_id}} STORE --------------------- |
| 52 | { |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 53 | bool x_cond = PARTIAL_N0 != 0 && get_global_id(0) == 0; |
| 54 | |
Gunes Bayir | 7dc0234 | 2022-11-21 21:46:50 +0000 | [diff] [blame] | 55 | T_STORE_INDIRECT_WIDTH_SELECT({{DST_DATA_TYPE}}, M0, N0, PARTIAL_N0, {{DST_TENSOR_TYPE}}, {{dst}}, g_ind_0, {{dst}}_stride_y, x_cond, {{src}}, g_dst_indirect_y); |
| 56 | //------------------ END KERNEL {{meta_kernel_id}} STORE --------------------- |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | )_"; |
| 60 | } |
| 61 | |
| 62 | void ClTemplateStore::declare_variables(GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const |
| 63 | { |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 64 | vtable.declare_variable( |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 65 | comp_group, |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 66 | _src, |
| 67 | GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer), |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 68 | "src"); |
| 69 | vtable.declare_variable( |
Viet-Hoa Do | 3558c58 | 2022-12-16 14:45:57 +0000 | [diff] [blame] | 70 | comp_group, |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 71 | _dst, |
| 72 | GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer), |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 73 | "dst"); |
| 74 | } |
| 75 | |
| 76 | TagLUT ClTemplateStore::get_tag_lut(const GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const |
| 77 | { |
| 78 | TagLUT lut{}; |
| 79 | |
| 80 | // Arguments and global shared variables |
| 81 | lut["src"] = vtable.get_variable(_src); |
| 82 | lut["dst"] = vtable.get_variable(_dst); |
| 83 | |
| 84 | // Local build options |
| 85 | lut["meta_kernel_id"] = id(); |
| 86 | lut["DST_TENSOR_TYPE"] = "BUFFER"; |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 87 | lut["DST_DATA_TYPE"] = _dst->data_type(); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 88 | |
Viet-Hoa Do | 04f4620 | 2022-12-14 14:49:56 +0000 | [diff] [blame] | 89 | ARM_COMPUTE_UNUSED(comp_group); |
SiCong Li | f44bbc5 | 2022-08-29 18:25:51 +0100 | [diff] [blame] | 90 | return lut; |
| 91 | } |
| 92 | |
| 93 | } // namespace dynamic_fusion |
| 94 | } // namespace experimental |
| 95 | } // namespace arm_compute |