xref: /aosp_15_r20/external/angle/src/libANGLE/CLKernel.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CLKernel.h: Defines the cl::Kernel class, which is a function declared in an OpenCL program.
7 
8 #ifndef LIBANGLE_CLKERNEL_H_
9 #define LIBANGLE_CLKERNEL_H_
10 
11 #include "libANGLE/CLObject.h"
12 #include "libANGLE/renderer/CLKernelImpl.h"
13 
14 namespace cl
15 {
16 
17 class Kernel final : public _cl_kernel, public Object
18 {
19   public:
20     // Front end entry functions, only called from OpenCL entry points
21 
22     angle::Result setArg(cl_uint argIndex, size_t argSize, const void *argValue);
23 
24     angle::Result getInfo(KernelInfo name,
25                           size_t valueSize,
26                           void *value,
27                           size_t *valueSizeRet) const;
28 
29     angle::Result getWorkGroupInfo(cl_device_id device,
30                                    KernelWorkGroupInfo name,
31                                    size_t valueSize,
32                                    void *value,
33                                    size_t *valueSizeRet) const;
34 
35     angle::Result getArgInfo(cl_uint argIndex,
36                              KernelArgInfo name,
37                              size_t valueSize,
38                              void *value,
39                              size_t *valueSizeRet) const;
40 
getName()41     const std::string &getName() const { return mInfo.functionName; }
42 
areAllArgsSet()43     bool areAllArgsSet() const
44     {
45         return std::all_of(mSetArguments.begin(), mSetArguments.end(),
46                            [](KernelArg arg) { return arg.isSet == true; });
47     }
48 
49     Kernel *clone() const;
50 
51   public:
52     ~Kernel() override;
53 
54     const Program &getProgram() const;
55     const rx::CLKernelImpl::Info &getInfo() const;
56 
57     template <typename T = rx::CLKernelImpl>
58     T &getImpl() const;
59 
60   private:
61     Kernel(Program &program, const char *name);
62     Kernel(Program &program, const rx::CLKernelImpl::CreateFunc &createFunc);
63 
64     void initImpl();
65 
66     const ProgramPtr mProgram;
67     rx::CLKernelImpl::Ptr mImpl;
68     rx::CLKernelImpl::Info mInfo;
69 
70     std::vector<KernelArg> mSetArguments;
71 
72     friend class Object;
73     friend class Program;
74 };
75 
getProgram()76 inline const Program &Kernel::getProgram() const
77 {
78     return *mProgram;
79 }
80 
getInfo()81 inline const rx::CLKernelImpl::Info &Kernel::getInfo() const
82 {
83     return mInfo;
84 }
85 
86 template <typename T>
getImpl()87 inline T &Kernel::getImpl() const
88 {
89     return static_cast<T &>(*mImpl);
90 }
91 
92 }  // namespace cl
93 
94 #endif  // LIBANGLE_CLKERNEL_H_
95