Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +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 | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 25 | #ifndef CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H |
| 26 | #define CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 27 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 28 | #include "ckw/KernelArgument.h" |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 29 | #include "ckw/OperandBase.h" |
Nikolaj Jensen | 5ff4802 | 2023-06-27 14:13:24 +0100 | [diff] [blame] | 30 | #include "ckw/types/GpuTargetLanguage.h" |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 31 | |
| 32 | #include <map> |
| 33 | #include <memory> |
| 34 | #include <string> |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 35 | #include <vector> |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 36 | |
| 37 | namespace ckw |
| 38 | { |
| 39 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 40 | class TileOperand; |
| 41 | |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 42 | namespace prototype |
| 43 | { |
| 44 | class GpuKernelWriterDataHolder; |
| 45 | } // namespace prototype |
| 46 | |
| 47 | /** The target for kernel writer to write into. */ |
| 48 | class Kernel |
| 49 | { |
| 50 | public: |
| 51 | /** Constructor |
| 52 | * |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 53 | * @param[in] language The programming language to write the kernel. |
| 54 | */ |
| 55 | Kernel(GpuTargetLanguage language); |
| 56 | /** Constructor |
| 57 | * |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 58 | * @param[in] name The name of the kernel function. |
| 59 | * @param[in] language The programming language to write the kernel. |
| 60 | */ |
| 61 | Kernel(const char *name, GpuTargetLanguage language); |
| 62 | |
| 63 | /** Destructor */ |
| 64 | ~Kernel(); |
| 65 | |
| 66 | /** Get the name of the kernel function. */ |
| 67 | const std::string &name() const; |
| 68 | |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 69 | /** Set the name of the kernel function. |
| 70 | * |
| 71 | * @param[in] name The name of the kernel function. |
| 72 | */ |
| 73 | void name(const std::string &name); |
| 74 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 75 | /** Get the list of kernel arguments. */ |
| 76 | ::std::vector<KernelArgument> arguments() const; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 77 | |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 78 | /** (Internal use only) Register the tile operand. |
| 79 | * |
| 80 | * @param operand The tile operand to be registered. |
| 81 | */ |
| 82 | TileOperand ®ister_operand(::std::unique_ptr<TileOperand> operand); |
| 83 | |
| 84 | /** (Internal use only) Register the tensor operand. |
| 85 | * |
| 86 | * @param operand The tensor operand to be registered. |
| 87 | */ |
| 88 | TensorOperand ®ister_operand(::std::unique_ptr<TensorOperand> operand); |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 89 | |
| 90 | /** (Internal use only) Get the implementation data. */ |
| 91 | prototype::GpuKernelWriterDataHolder *impl(); |
| 92 | |
| 93 | private: |
| 94 | ::std::string _name; |
| 95 | ::std::unique_ptr<prototype::GpuKernelWriterDataHolder> _kernel; |
| 96 | ::std::map<::std::string, ::std::unique_ptr<OperandBase>> _operands; |
Viet-Hoa Do | c8e1617 | 2023-06-27 14:09:46 +0100 | [diff] [blame] | 97 | ::std::map<int32_t, TensorOperand *> _tensor_id_operands; |
Viet-Hoa Do | bd4f6b9 | 2023-05-30 09:34:32 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | } // namespace ckw |
| 101 | |
Viet-Hoa Do | ce3c48c | 2023-07-03 13:44:43 +0100 | [diff] [blame] | 102 | #endif // CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H |