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 | #ifndef CKW_INCLUDE_CKW_KERNELWRITER_H |
| 26 | #define CKW_INCLUDE_CKW_KERNELWRITER_H |
| 27 | |
| 28 | #include "ckw/types/TargetArchitecture.h" |
| 29 | #include "ckw/types/TargetLanguage.h" |
| 30 | #include <memory> |
| 31 | #include <string> |
| 32 | |
| 33 | namespace ckw |
| 34 | { |
| 35 | |
| 36 | class Kernel; |
| 37 | |
| 38 | /** A kernel writer. |
| 39 | * |
| 40 | * This class is used to construct a new kernel by defining arguments, declaring variable and writing code. |
| 41 | * |
| 42 | * Use @ref KernelWriter::create_instance method to create the kernel writer for the specific target architecture and language. |
| 43 | * |
| 44 | * After having finished constructing the kernel, call @ref KernelWriter::emit_kernel to get the kernel object. |
| 45 | */ |
| 46 | class KernelWriter |
| 47 | { |
| 48 | public: |
| 49 | // ============================================================================================= |
| 50 | // Construtors and destructor |
| 51 | // ============================================================================================= |
| 52 | |
| 53 | /** Initialize a new instance of @ref KernelWriter class for the specific architecture and language. |
| 54 | * |
| 55 | * Supported target architectures and languages: |
| 56 | * |
| 57 | * Architecture | Languages | |
| 58 | * ------------------------------|------------------------------| |
| 59 | * GpuArmMaliValhall | OpenCL | |
| 60 | * |
| 61 | * @param[in] architecture The architecture on which the kernel is executed. |
| 62 | * @param[in] language The language to write the kernel. |
| 63 | */ |
| 64 | static std::unique_ptr<KernelWriter> create_instance(TargetArchitecture architecture, TargetLanguage language); |
| 65 | |
| 66 | /** Destructor */ |
| 67 | virtual ~KernelWriter(); |
| 68 | |
| 69 | // ============================================================================================= |
| 70 | // Misc |
| 71 | // ============================================================================================= |
| 72 | |
| 73 | /** Write the line comment in debug build. |
| 74 | * This function does not take effect on release build. |
| 75 | * |
| 76 | * The comment must only contain one line (i.e. no newline character is allowed). |
| 77 | * |
| 78 | * @param[in] text The comment to be written. |
| 79 | */ |
| 80 | virtual void comment(const std::string &text) = 0; |
| 81 | |
| 82 | // ============================================================================================= |
| 83 | // Code generation |
| 84 | // ============================================================================================= |
| 85 | |
| 86 | /** Emit the kernel object. |
| 87 | * |
| 88 | * @param[in] name The name of the kernel object to be generated. |
| 89 | */ |
| 90 | virtual std::unique_ptr<Kernel> emit_kernel(const std::string &name) = 0; |
| 91 | }; |
| 92 | |
| 93 | } // namespace ckw |
| 94 | |
| 95 | #endif // CKW_INCLUDE_CKW_KERNELWRITER_H |