blob: ba31a29ba7d882c0e2c1597a763aeb2df861951b [file] [log] [blame]
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +01001/*
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 Doce3c48c2023-07-03 13:44:43 +010025#ifndef CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H
26#define CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010027
Viet-Hoa Doc8e16172023-06-27 14:09:46 +010028#include "ckw/KernelArgument.h"
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010029#include "ckw/OperandBase.h"
Nikolaj Jensen5ff48022023-06-27 14:13:24 +010030#include "ckw/types/GpuTargetLanguage.h"
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010031
32#include <map>
33#include <memory>
34#include <string>
Viet-Hoa Doc8e16172023-06-27 14:09:46 +010035#include <vector>
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010036
37namespace ckw
38{
39
Viet-Hoa Doc8e16172023-06-27 14:09:46 +010040class TileOperand;
41
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010042namespace prototype
43{
44class GpuKernelWriterDataHolder;
45} // namespace prototype
46
47/** The target for kernel writer to write into. */
48class Kernel
49{
50public:
51 /** Constructor
52 *
SiCong Li23882a92023-06-28 09:49:45 +010053 * @param[in] language The programming language to write the kernel.
54 */
55 Kernel(GpuTargetLanguage language);
56 /** Constructor
57 *
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010058 * @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 Li23882a92023-06-28 09:49:45 +010069 /** 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 Doc8e16172023-06-27 14:09:46 +010075 /** Get the list of kernel arguments. */
76 ::std::vector<KernelArgument> arguments() const;
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010077
Viet-Hoa Doc8e16172023-06-27 14:09:46 +010078 /** (Internal use only) Register the tile operand.
79 *
80 * @param operand The tile operand to be registered.
81 */
82 TileOperand &register_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 &register_operand(::std::unique_ptr<TensorOperand> operand);
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010089
90 /** (Internal use only) Get the implementation data. */
91 prototype::GpuKernelWriterDataHolder *impl();
92
93private:
94 ::std::string _name;
95 ::std::unique_ptr<prototype::GpuKernelWriterDataHolder> _kernel;
96 ::std::map<::std::string, ::std::unique_ptr<OperandBase>> _operands;
Viet-Hoa Doc8e16172023-06-27 14:09:46 +010097 ::std::map<int32_t, TensorOperand *> _tensor_id_operands;
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010098};
99
100} // namespace ckw
101
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100102#endif // CKW_PROTOTYPE_INCLUDE_CKW_KERNEL_H