forked from hughperkins/EasyCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLKernel.h
More file actions
113 lines (91 loc) · 3.78 KB
/
CLKernel.h
File metadata and controls
113 lines (91 loc) · 3.78 KB
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
// Copyright Hugh Perkins 2013, 2014, 2015 hughperkins at gmail
//
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include "CLArrayInt.h"
#include "CLArrayFloat.h"
#include "EasyCL_export.h"
#include "mystdint.h"
class EasyCL_EXPORT CLKernel {
EasyCL *easycl; // NOT owned by this object, dont delete!
#ifdef _WIN32
#pragma warning(disable: 4251)
#endif
std::string sourceFilename; // just for info really
std::string kernelName; // this too
cl_program program;
cl_kernel kernel;
cl_int error;
std::string source;
int nextArg;
std::vector<cl_mem> buffers;
// std::vector<int> inputArgInts;
// std::vector<unsigned int> inputArgUInts;
// std::vector<long long> inputArgLongLongs;
// std::vector<unsigned long long> inputArgULongLongs;
std::vector<int32_t> inputArgInt32s;
std::vector<uint32_t> inputArgUInt32s;
std::vector<int64_t> inputArgInt64s;
std::vector<uint64_t> inputArgUInt64s;
std::vector<float> inputArgFloats;
std::vector<cl_mem> outputArgBuffers;
std::vector<void *> outputArgPointers;
std::vector<size_t> outputArgSizes;
std::vector< CLWrapper * > wrappersToDirty; // we will mark these dirty
// on 'run'
// only wrappers passed as `out` or
// or `inout` will be marked dirty
// on run
template<typename T>
static std::string toString(T val);
#ifdef _WIN32
#pragma warning(default: 4251)
#endif
public:
CLKernel(EasyCL *easycl, std::string sourceFilename, std::string kernelName, std::string source, cl_program program, cl_kernel kernel);
CLKernel(const CLKernel &kernel);
CLKernel &operator=(const CLKernel &kernel);
~CLKernel();
CLKernel *input(CLArray *clarray1d);
CLKernel *inout(CLArray *clarray1d);
CLKernel *output(CLArray *clarray1d);
// synonyms, in case you prefer `in` instead of `input`:
CLKernel *in(CLArray *clarray1d) { return input(clarray1d); }
CLKernel *out(CLArray *clarray1d) { return output(clarray1d); }
CLKernel *input(CLWrapper *wrapper);
CLKernel *output(CLWrapper *wrapper);
CLKernel *inout(CLWrapper *wrapper);
// synonyms, in case you prefer `in` instead of `input`:
CLKernel *in(CLWrapper *wrapper) { return input(wrapper); }
CLKernel *out(CLWrapper *wrapper) { return output(wrapper); }
CLKernel *localFloats(int count);
CLKernel *localInts(int count);
CLKernel *local(int N);
template<typename T> CLKernel *input(int N, const T *data);
template<typename T> CLKernel *in(int N, const T *data);
// CLKernel *input(int value);
// CLKernel *in(int value);
// CLKernel *input(unsigned int value);
// CLKernel *in(unsigned int value);
// CLKernel *input(long long value);
// CLKernel *in(long long value);
// CLKernel *input(unsigned long long value);
// CLKernel *in(unsigned long long value);
CLKernel *input(float value);
CLKernel *in(float value);
CLKernel *input(int32_t value);
CLKernel *in(int32_t value);
CLKernel *input(int64_t value);
CLKernel *in(int64_t value);
CLKernel *input(uint64_t value);
CLKernel *in(uint64_t value);
CLKernel *input(uint32_t value);
CLKernel *in(uint32_t value);
template<typename T> CLKernel *output(int N, T *data);
template<typename T> CLKernel *out(int N, T *data);
template<typename T> CLKernel *inout(int N, T *data);
void run_1d(int global_worksize, int local_worksize);
void run(int ND, const size_t *global_ws, const size_t *local_ws);
};