Gunes Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | namespace ckw |
| 33 | { |
| 34 | |
| 35 | // Forward Declarations |
| 36 | class CLKernelWriter; |
| 37 | class CLTile; |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 38 | template <class CLTile> |
| 39 | class TileView; |
Gunes Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 40 | enum class MemoryOperation; |
| 41 | |
| 42 | /** Helper class to write memory operations (like load/store) in OpenCL for Image2d type */ |
| 43 | class CLMemoryOpImage2dHelper : public ICLMemoryOpHelper |
| 44 | { |
| 45 | public: |
| 46 | /** Constructor similar to @ref ICLMemoryOpHelper() */ |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 47 | 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 Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
| 56 | /** Copy constructor */ |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 57 | CLMemoryOpImage2dHelper(const CLMemoryOpImage2dHelper &) = delete; |
Gunes Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 58 | |
| 59 | /** Assignment operator overload */ |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 60 | CLMemoryOpImage2dHelper &operator=(const CLMemoryOpImage2dHelper &) = delete; |
Gunes Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 61 | |
| 62 | // Methods overridden |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 63 | void initialize(const CLTile *x, const CLTile *z, const CLTile *b) override; |
Gunes Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 64 | void write_row(int32_t row_id, const std::string &coord_y) override; |
| 65 | void finalize() override; |
| 66 | |
| 67 | private: |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame^] | 68 | 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 Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 74 | |
| 75 | void out_of_bound_initialize_y(const std::string &coord); |
| 76 | void out_of_bound_finalize_y(); |
| 77 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | 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 Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 83 | std::string to_ls_image2d_sampler() const; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 84 | 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 Bayir | 038fe91 | 2023-08-11 12:50:31 +0100 | [diff] [blame] | 86 | }; |
| 87 | } // namespace ckw |
| 88 | |
| 89 | #endif // CKW_SRC_CL_HELPERS_CLMEMORYOPIMAGE2DHELPER_H |