blob: ca1332933579cc962d401b50ab7d7b21ee6cd2ef [file] [log] [blame]
SiCong Li19844f62023-05-16 16:46:34 +01001/*
2 * Copyright (c) 2023 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#ifndef ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_COMPONENTS_UTILS_WRITERHELPER
25#define ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_COMPONENTS_UTILS_WRITERHELPER
26
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010027#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwComponentArgument.h"
28#include "src/dynamic_fusion/sketch/gpu/ckw_driver/GpuCkwScopedKernelWriter.h"
SiCong Li19844f62023-05-16 16:46:34 +010029#include "ckw/TensorTileSampler.h"
30
31#include <functional>
32
33using namespace ckw;
34namespace arm_compute
35{
36namespace experimental
37{
38namespace dynamic_fusion
39{
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010040using SamplerCreator = std::function<TensorTileSampler(GpuCkwScopedKernelWriter &, int32_t /* m0 */, int32_t /* n0 */)>;
SiCong Li19844f62023-05-16 16:46:34 +010041
42/** Load lhs and rhs tiles of dimension [m0, n0] only when not loaded and prepare the sampler
43 */
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010044inline void load_lhs_rhs_tiles_and_prepare_sampler(GpuCkwScopedKernelWriter &writer, GpuCkwComponentArgument *lhs, GpuCkwComponentArgument *rhs, int32_t m0, int32_t n0, SamplerCreator create_sampler)
SiCong Li19844f62023-05-16 16:46:34 +010045{
46 if(!lhs->has_tile() && !rhs->has_tile())
47 {
48 const auto sampler = create_sampler(writer, m0, n0);
49
50 writer->op_load_once(lhs, sampler);
51 writer->op_load_once(rhs, sampler);
52 }
53 else if(lhs->has_tile())
54 {
55 const auto &sampler = lhs->tile_sampler();
56 writer->op_load_once(rhs, sampler);
57 }
58 else
59 {
60 const auto &sampler = rhs->tile_sampler();
61 writer->op_load_once(lhs, sampler);
62 }
63}
64
65} // namespace dynamic_fusion
66} // namespace experimental
67} // namespace arm_compute
68#endif /* ACL_SRC_DYNAMIC_FUSION_SKETCH_GPU_CKW_DRIVER_COMPONENTS_UTILS_WRITERHELPER */