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 | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 25 | #include "ckw/Error.h" |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 26 | #include "ckw/ITileOperand.h" |
| 27 | #include "ckw/KernelWriter.h" |
| 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" |
| 31 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 32 | #include <iterator> |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 33 | namespace ckw |
| 34 | { |
| 35 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 36 | KernelWriter::~KernelWriter() = default; |
| 37 | |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 38 | std::unique_ptr<KernelWriter> KernelWriter::create_instance(TargetArchitecture architecture, TargetLanguage language) |
| 39 | { |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 40 | CKW_UNUSED(architecture); |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 41 | switch(language) |
| 42 | { |
| 43 | case TargetLanguage::OpenCL: |
| 44 | // Currently this is the oldest and the only supported GPU architecture. |
| 45 | CKW_ASSERT(architecture == TargetArchitecture::GpuArmMaliValhall); |
| 46 | return std::make_unique<CLKernelWriter>(); |
| 47 | |
| 48 | default: |
| 49 | CKW_THROW_MSG("Language not supported!"); |
| 50 | } |
| 51 | } |
| 52 | |
Gunes Bayir | ab0b750 | 2023-07-11 14:57:36 +0100 | [diff] [blame] | 53 | int32_t KernelWriter::id_space() const |
| 54 | { |
| 55 | return _id_space; |
| 56 | } |
| 57 | |
| 58 | ITileOperand &KernelWriter::add_operand(std::unique_ptr<ITileOperand> &operand_ptr) |
| 59 | { |
| 60 | auto it = _operands.insert(std::move(operand_ptr)); |
| 61 | return *it.first->get(); |
| 62 | } |
| 63 | |
| 64 | std::string KernelWriter::generate_full_name(const std::string &name) const |
| 65 | { |
| 66 | return "G" + std::to_string(id_space()) + "__" + name; |
| 67 | } |
Viet-Hoa Do | 3389f53 | 2023-07-05 17:36:40 +0100 | [diff] [blame] | 68 | |
| 69 | } // namespace ckw |