Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +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 | #include "src/cl/CLKernelWriter.h" |
| 26 | #include "ckw/Error.h" |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 27 | #include "src/cl/CLTile.h" |
| 28 | #include "src/cl/CLHelpers.h" |
| 29 | #include <cstdint> |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 30 | |
| 31 | namespace ckw |
| 32 | { |
| 33 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 34 | CLKernelWriter::CLKernelWriter() = default; |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 35 | CLKernelWriter::~CLKernelWriter() = default; |
| 36 | |
| 37 | std::unique_ptr<Kernel> CLKernelWriter::emit_kernel(const std::string &name) |
| 38 | { |
| 39 | CKW_UNUSED(name); |
| 40 | CKW_THROW_MSG("Not implemented!"); |
| 41 | } |
| 42 | |
| 43 | void CLKernelWriter::comment(const std::string &text) |
| 44 | { |
| 45 | #ifdef COMPUTE_KERNEL_WRITER_DEBUG_ENABLED |
| 46 | |
| 47 | CKW_ASSERT(text.find("\n") == text.npos); |
| 48 | CKW_ASSERT(text.find("\r") == text.npos); |
| 49 | |
| 50 | append_code("// ", text, "\n"); |
| 51 | |
| 52 | #else // COMPUTE_KERNEL_WRITER_DEBUG_ENABLED |
| 53 | |
| 54 | CKW_UNUSED(text); |
| 55 | |
| 56 | #endif // COMPUTE_KERNEL_WRITER_DEBUG_ENABLED |
| 57 | } |
| 58 | |
| 59 | const std::string &CLKernelWriter::body_source_code() const |
| 60 | { |
| 61 | return _body_source_code; |
| 62 | } |
| 63 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 64 | ITileOperand &CLKernelWriter::declare_tile(const std::string &name, const TileInfo &tile_info) |
| 65 | { |
| 66 | const std::string fullname = generate_full_name(name); |
| 67 | |
| 68 | const int32_t height = tile_info.height(); |
| 69 | const int32_t width = tile_info.width(); |
| 70 | const DataType data_type = tile_info.data_type(); |
| 71 | |
| 72 | for(int32_t row = 0; row < height; ++row) |
| 73 | { |
| 74 | const std::string cl_type = cl_get_variable_datatype_as_string(data_type, width); |
| 75 | append_code(cl_type, " ", fullname, std::to_string(row), ";\n"); |
| 76 | } |
| 77 | |
| 78 | return add_operand(fullname, tile_info); |
| 79 | } |
| 80 | |
| 81 | ITileOperand &CLKernelWriter::add_operand(const std::string &name, const TileInfo &tile_info) |
| 82 | { |
| 83 | std::unique_ptr<ITileOperand> operand = std::make_unique<CLTile>(name, tile_info); |
| 84 | return KernelWriter::add_operand(operand); |
| 85 | } |
| 86 | |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 87 | } // namespace ckw |