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 {
ClTemplateStore(ComponentId id,const ArgumentPack<ITensorInfo> & tensors)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
get_name() const41 std::string ClTemplateStore::get_name() const
42 {
43 return "store";
44 }
45
get_component_code(const ComponentGroup & comp_group) const46 std::string ClTemplateStore::get_component_code(const ComponentGroup &comp_group) const
47 {
48 ARM_COMPUTE_UNUSED(comp_group);
49
50 return R"_(
51 //------------------ START KERNEL {{meta_kernel_id}} STORE ---------------------
52 {
53 bool x_cond = PARTIAL_N0 != 0 && get_global_id(0) == 0;
54
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 ---------------------
57 }
58
59 )_";
60 }
61
declare_variables(GpuKernelVariableTable & vtable,const ComponentGroup & comp_group) const62 void ClTemplateStore::declare_variables(GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const
63 {
64 vtable.declare_variable(
65 comp_group,
66 _src,
67 GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer),
68 "src");
69 vtable.declare_variable(
70 comp_group,
71 _dst,
72 GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer),
73 "dst");
74 }
75
get_tag_lut(const GpuKernelVariableTable & vtable,const ComponentGroup & comp_group) const76 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";
87 lut["DST_DATA_TYPE"] = _dst->data_type();
88
89 ARM_COMPUTE_UNUSED(comp_group);
90 return lut;
91 }
92
93 } // namespace dynamic_fusion
94 } // namespace experimental
95 } // namespace arm_compute
96