blob: 6c42c132d9b70f9eef30e3af69a3405a57c53c63 [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;
Gunes Bayir2b9fa592024-01-17 16:07:03 +000038template <class CLTile>
39class TileView;
Gunes Bayir038fe912023-08-11 12:50:31 +010040enum class MemoryOperation;
41
42/** Helper class to write memory operations (like load/store) in OpenCL for Image2d type */
43class CLMemoryOpImage2dHelper : public ICLMemoryOpHelper
44{
45public:
46 /** Constructor similar to @ref ICLMemoryOpHelper() */
Gunes Bayir2b9fa592024-01-17 16:07:03 +000047 CLMemoryOpImage2dHelper(CLKernelWriter *writer,
48 ITensor *tensor,
49 TensorSampler *sampler,
50 MemoryOperation op,
51 const TileView<CLTile> &dst)
52 : ICLMemoryOpHelper(writer, tensor, sampler, op, dst)
Gunes Bayir038fe912023-08-11 12:50:31 +010053 {
54 }
55
56 /** Copy constructor */
Gunes Bayir2b9fa592024-01-17 16:07:03 +000057 CLMemoryOpImage2dHelper(const CLMemoryOpImage2dHelper &) = delete;
Gunes Bayir038fe912023-08-11 12:50:31 +010058
59 /** Assignment operator overload */
Gunes Bayir2b9fa592024-01-17 16:07:03 +000060 CLMemoryOpImage2dHelper &operator=(const CLMemoryOpImage2dHelper &) = delete;
Gunes Bayir038fe912023-08-11 12:50:31 +010061
62 // Methods overridden
Gunes Bayir2b9fa592024-01-17 16:07:03 +000063 void initialize(const CLTile *x, const CLTile *z, const CLTile *b) override;
Gunes Bayir038fe912023-08-11 12:50:31 +010064 void write_row(int32_t row_id, const std::string &coord_y) override;
65 void finalize() override;
66
67private:
Gunes Bayir2b9fa592024-01-17 16:07:03 +000068 static bool validate(const CLKernelWriter *writer,
69 const ITensor *tensor,
70 const TensorSampler *sampler,
71 const Tensor3dMapper *mapper,
72 MemoryOperation op,
73 const TileView<CLTile> &dst);
Gunes Bayir038fe912023-08-11 12:50:31 +010074
75 void out_of_bound_initialize_y(const std::string &coord);
76 void out_of_bound_finalize_y();
77
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010078 std::string to_ls_image2d(MemoryOperation op,
79 int32_t vector_width,
80 const std::string &data,
81 const std::string &sampler,
82 const std::string &address) const;
Gunes Bayir038fe912023-08-11 12:50:31 +010083 std::string to_ls_image2d_sampler() const;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010084 std::string
85 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 +010086};
87} // namespace ckw
88
89#endif // CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H