blob: 217214ced3ea4dfe6b956588321190ec02508919 [file] [log] [blame]
SiCong Lif44bbc52022-08-29 18:25:51 +01001/*
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
28namespace arm_compute
29{
30namespace experimental
31{
32namespace dynamic_fusion
33{
34ClTemplateStore::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
41std::string ClTemplateStore::get_name() const
42{
43 return "store";
44}
45
46std::string ClTemplateStore::get_component_code(const ComponentGroup &comp_group) const
47{
48 ARM_COMPUTE_UNUSED(comp_group);
Gunes Bayir7dc02342022-11-21 21:46:50 +000049
SiCong Lif44bbc52022-08-29 18:25:51 +010050 return R"_(
51//------------------ START KERNEL {{meta_kernel_id}} STORE ---------------------
52{
SiCong Lif44bbc52022-08-29 18:25:51 +010053 bool x_cond = PARTIAL_N0 != 0 && get_global_id(0) == 0;
54
Gunes Bayir7dc02342022-11-21 21:46:50 +000055 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 Lif44bbc52022-08-29 18:25:51 +010057}
58
59)_";
60}
61
62void ClTemplateStore::declare_variables(GpuKernelVariableTable &vtable, const ComponentGroup &comp_group) const
63{
SiCong Lif44bbc52022-08-29 18:25:51 +010064 vtable.declare_variable(
Viet-Hoa Do3558c582022-12-16 14:45:57 +000065 comp_group,
SiCong Lif44bbc52022-08-29 18:25:51 +010066 _src,
67 GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer),
SiCong Lif44bbc52022-08-29 18:25:51 +010068 "src");
69 vtable.declare_variable(
Viet-Hoa Do3558c582022-12-16 14:45:57 +000070 comp_group,
SiCong Lif44bbc52022-08-29 18:25:51 +010071 _dst,
72 GpuKernelArgumentInfo(GpuKernelArgumentInfo::Type::Tensor_4D_t_Buffer),
SiCong Lif44bbc52022-08-29 18:25:51 +010073 "dst");
74}
75
76TagLUT 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 Do04f46202022-12-14 14:49:56 +000087 lut["DST_DATA_TYPE"] = _dst->data_type();
SiCong Lif44bbc52022-08-29 18:25:51 +010088
Viet-Hoa Do04f46202022-12-14 14:49:56 +000089 ARM_COMPUTE_UNUSED(comp_group);
SiCong Lif44bbc52022-08-29 18:25:51 +010090 return lut;
91}
92
93} // namespace dynamic_fusion
94} // namespace experimental
95} // namespace arm_compute