blob: fd9b097a24f9502b0789c4e689f517717cec0ad8 [file] [log] [blame]
Gunes Bayir038fe912023-08-11 12:50:31 +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
25#ifndef CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H
26#define CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H
27
28#include "src/cl/helpers/ICLMemoryOpHelper.h"
29
30#include <string>
31
32namespace ckw
33{
34
35// Forward Declarations
36class CLKernelWriter;
37class CLTile;
38enum class MemoryOperation;
39
40/** Helper class to write memory operations (like load/store) in OpenCL for Image2d type */
41class CLMemoryOpImage2dHelper : public ICLMemoryOpHelper
42{
43public:
44 /** Constructor similar to @ref ICLMemoryOpHelper() */
45 CLMemoryOpImage2dHelper(CLKernelWriter *writer, ITensor *tensor, TensorSampler *sampler, MemoryOperation op)
46 : ICLMemoryOpHelper(writer, tensor, sampler, op)
47 {
48 }
49
50 /** Copy constructor */
51 CLMemoryOpImage2dHelper(const CLMemoryOpImage2dHelper &) = default;
52
53 /** Assignment operator overload */
54 CLMemoryOpImage2dHelper &operator=(const CLMemoryOpImage2dHelper &) = default;
55
56 // Methods overridden
57 void initialize(const CLTile *dst, const CLTile *x, const CLTile *z, const CLTile *b) override;
58 void write_row(int32_t row_id, const std::string &coord_y) override;
59 void finalize() override;
60
61private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 static bool validate(const CLKernelWriter *writer,
63 const ITensor *tensor,
64 const TensorSampler *sampler,
65 const Tensor3dMapper *mapper,
66 MemoryOperation op,
67 const CLTile *dst);
Gunes Bayir038fe912023-08-11 12:50:31 +010068
69 void out_of_bound_initialize_y(const std::string &coord);
70 void out_of_bound_finalize_y();
71
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 std::string to_ls_image2d(MemoryOperation op,
73 int32_t vector_width,
74 const std::string &data,
75 const std::string &sampler,
76 const std::string &address) const;
Gunes Bayir038fe912023-08-11 12:50:31 +010077 std::string to_ls_image2d_sampler() const;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010078 std::string
79 to_ls_image2d_address(const std::string &x, const std::string &y, const std::string &z, const std::string &b) const;
Gunes Bayir038fe912023-08-11 12:50:31 +010080};
81} // namespace ckw
82
83#endif // CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H