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 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 25 | #include "ckw/KernelWriter.h" |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 26 | #include "ckw/Error.h" |
Gunes Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 27 | #include "ckw/TileOperand.h" |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 28 | #include "ckw/types/TargetArchitecture.h" |
| 29 | #include "ckw/types/TargetLanguage.h" |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 30 | #include "src/cl/CLKernelWriter.h" |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 31 | #include "src/cl/CLTensorArgument.h" |
| 32 | #include "src/cl/CLTile.h" |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 33 | |
| 34 | namespace ckw |
| 35 | { |
| 36 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 37 | KernelWriter::~KernelWriter() = default; |
| 38 | |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 39 | std::unique_ptr<KernelWriter> KernelWriter::create_instance(TargetArchitecture architecture, TargetLanguage language) |
| 40 | { |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 41 | CKW_UNUSED(architecture); |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 42 | switch(language) |
| 43 | { |
| 44 | case TargetLanguage::OpenCL: |
| 45 | // Currently this is the oldest and the only supported GPU architecture. |
| 46 | CKW_ASSERT(architecture == TargetArchitecture::GpuArmMaliValhall); |
| 47 | return std::make_unique<CLKernelWriter>(); |
| 48 | |
| 49 | default: |
| 50 | CKW_THROW_MSG("Language not supported!"); |
| 51 | } |
| 52 | } |
| 53 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 54 | int32_t KernelWriter::id_space() const |
| 55 | { |
| 56 | return _id_space; |
| 57 | } |
| 58 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 59 | std::string KernelWriter::generate_full_name(const std::string &name) const |
| 60 | { |
| 61 | return "G" + std::to_string(id_space()) + "__" + name; |
| 62 | } |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 63 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 64 | TileOperand KernelWriter::create_tile_operand(ITile &tile) |
| 65 | { |
| 66 | return TileOperand(tile); |
| 67 | } |
| 68 | |
| 69 | ITile &KernelWriter::get_tile(const TileOperand &operand) |
| 70 | { |
| 71 | return operand._tile; |
| 72 | } |
| 73 | |
Viet-Hoa Do | 0b23e0e | 2023-07-25 14:00:46 +0100 | [diff] [blame] | 74 | TensorOperand KernelWriter::create_tensor_operand(ITensor &tensor) |
| 75 | { |
| 76 | return TensorOperand(tensor); |
| 77 | } |
| 78 | |
| 79 | ITensor &KernelWriter::get_tensor(const TensorOperand &operand) |
| 80 | { |
| 81 | return operand._tensor; |
| 82 | } |
| 83 | |
Gunes Bayir | 806b8e8 | 2023-08-23 23:28:31 +0100 | [diff] [blame^] | 84 | const std::vector<std::vector<std::string>> &KernelWriter::get_values(const ConstantData &data) |
| 85 | { |
| 86 | return data.values(); |
| 87 | } |
| 88 | |
| 89 | DataType KernelWriter::get_data_type(const ConstantData &data) |
| 90 | { |
| 91 | return data.data_type(); |
| 92 | } |
| 93 | |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 94 | } // namespace ckw |