summaryrefslogtreecommitdiff
path: root/src/core/kernel.h
blob: 9d4375b5b36c08852eac96ad57158c2dcac2ca53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef __KERNEL_H__
#define __KERNEL_H__

#include "object.h"

#include <CL/cl.h>

#include <vector>
#include <string>

namespace llvm
{
    class Function;
    class Module;
}

namespace Coal
{

class Program;
class DeviceInterface;
class DeviceKernel;

class Kernel : public Object
{
    public:
        Kernel(Program *program);
        ~Kernel();

        class Arg
        {
            public:
                enum File
                {
                    Private = 0,
                    Global = 1,
                    Local = 2,
                    Constant = 3
                };
                enum Kind
                {
                    Invalid,
                    Int8,
                    Int16,
                    Int32,
                    Int64,
                    Float,
                    Double,
                    Buffer,
                    Image2D,
                    Image3D,
                    Sampler
                };

                Arg(unsigned short vec_dim, File file, Kind kind);
                ~Arg();

                void alloc();
                void loadData(const void *data);
                void setAllocAtKernelRuntime(size_t size);

                bool operator !=(const Arg &b);

                size_t valueSize() const;
                unsigned short vecDim() const;
                File file() const;
                Kind kind() const;
                bool defined() const;
                size_t allocAtKernelRuntime() const;
                const void *value(unsigned short index) const;

            private:
                unsigned short p_vec_dim;
                File p_file;
                Kind p_kind;
                void *p_data;
                bool p_defined;
                size_t p_runtime_alloc;
        };

        cl_int addFunction(DeviceInterface *device, llvm::Function *function,
                           llvm::Module *module);
        llvm::Function *function(DeviceInterface *device) const;
        cl_int setArg(cl_uint index, size_t size, const void *value);
        unsigned int numArgs() const;
        const Arg &arg(unsigned int index) const;

        DeviceKernel *deviceDependentKernel(DeviceInterface *device) const;

        bool argsSpecified() const;
        bool needsLocalAllocation() const;  /*!< One or more arguments is __local */

        cl_int info(cl_kernel_info param_name,
                    size_t param_value_size,
                    void *param_value,
                    size_t *param_value_size_ret) const;
        cl_int workGroupInfo(DeviceInterface *device,
                             cl_kernel_work_group_info param_name,
                             size_t param_value_size,
                             void *param_value,
                             size_t *param_value_size_ret) const;

    private:
        std::string p_name;
        bool p_local_args;

        struct DeviceDependent
        {
            DeviceInterface *device;
            DeviceKernel *kernel;
            llvm::Function *function;
            llvm::Module *module;
        };

        std::vector<DeviceDependent> p_device_dependent;
        std::vector<Arg> p_args;
        DeviceDependent null_dep;

        const DeviceDependent &deviceDependent(DeviceInterface *device) const;
        DeviceDependent &deviceDependent(DeviceInterface *device);
};

}

class _cl_kernel : public Coal::Kernel
{};

#endif