blob: 73bede77890dd62619ea9dfe39b91c68097897e8 [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:
62 static bool validate(const CLKernelWriter *writer, const ITensor *tensor, const TensorSampler *sampler, const Tensor3dMapper *mapper, MemoryOperation op, const CLTile *dst);
63
64 void out_of_bound_initialize_y(const std::string &coord);
65 void out_of_bound_finalize_y();
66
67 std::string to_ls_image2d(MemoryOperation op, int32_t vector_width, const std::string &data, const std::string &sampler, const std::string &address) const;
68 std::string to_ls_image2d_sampler() const;
69 std::string to_ls_image2d_address(const std::string &x, const std::string &y, const std::string &z, const std::string &b) const;
70};
71} // namespace ckw
72
73#endif // CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H