… | |
… | |
20 | typedef cl_mem OpenCL__Image3D_ornull; |
20 | typedef cl_mem OpenCL__Image3D_ornull; |
21 | typedef cl_sampler OpenCL__Sampler; |
21 | typedef cl_sampler OpenCL__Sampler; |
22 | typedef cl_program OpenCL__Program; |
22 | typedef cl_program OpenCL__Program; |
23 | typedef cl_kernel OpenCL__Kernel; |
23 | typedef cl_kernel OpenCL__Kernel; |
24 | typedef cl_event OpenCL__Event; |
24 | typedef cl_event OpenCL__Event; |
|
|
25 | typedef cl_event OpenCL__UserEvent; |
|
|
26 | |
|
|
27 | typedef SV *FUTURE; |
|
|
28 | |
|
|
29 | /*****************************************************************************/ |
|
|
30 | |
|
|
31 | /* up to two temporary buffers */ |
|
|
32 | static void * |
|
|
33 | tmpbuf (size_t size) |
|
|
34 | { |
|
|
35 | static int idx; |
|
|
36 | static void *buf [2]; |
|
|
37 | static size_t len [2]; |
|
|
38 | |
|
|
39 | idx ^= 1; |
|
|
40 | |
|
|
41 | if (len [idx] < size) |
|
|
42 | { |
|
|
43 | free (buf [idx]); |
|
|
44 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
|
|
45 | buf [idx] = malloc (len [idx]); |
|
|
46 | } |
|
|
47 | |
|
|
48 | return buf [idx]; |
|
|
49 | } |
|
|
50 | |
|
|
51 | /*****************************************************************************/ |
25 | |
52 | |
26 | typedef struct |
53 | typedef struct |
27 | { |
54 | { |
28 | IV iv; |
55 | IV iv; |
29 | const char *name; |
56 | const char *name; |
… | |
… | |
63 | }; |
90 | }; |
64 | |
91 | |
65 | return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); |
92 | return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); |
66 | } |
93 | } |
67 | |
94 | |
|
|
95 | /*****************************************************************************/ |
|
|
96 | |
|
|
97 | static cl_int res; |
|
|
98 | |
68 | #define FAIL(name,res) \ |
99 | #define FAIL(name) \ |
69 | croak ("cl" # name ": %s", err2str (res)); |
100 | croak ("cl" # name ": %s", err2str (res)); |
70 | |
101 | |
71 | #define NEED_SUCCESS(name,args) \ |
102 | #define NEED_SUCCESS(name,args) \ |
72 | do { \ |
103 | do { \ |
73 | cl_int res = cl ## name args; \ |
104 | res = cl ## name args; \ |
74 | \ |
105 | \ |
75 | if (res) \ |
106 | if (res) \ |
76 | FAIL (name, res); \ |
107 | FAIL (name); \ |
77 | } while (0) |
108 | } while (0) |
|
|
109 | |
|
|
110 | #define NEED_SUCCESS_ARG(retdecl, name, args) \ |
|
|
111 | retdecl = cl ## name args; \ |
|
|
112 | if (res) \ |
|
|
113 | FAIL (name); |
|
|
114 | |
|
|
115 | /*****************************************************************************/ |
78 | |
116 | |
79 | #define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) |
117 | #define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) |
80 | #define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) |
118 | #define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) |
81 | |
119 | |
82 | /*TODO*/ |
120 | static void * |
83 | #define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 |
121 | SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg) |
|
|
122 | { |
|
|
123 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
|
|
124 | return (void *)SvIV (SvRV (sv)); |
|
|
125 | |
|
|
126 | croak ("%s: %s is not of type %s", func, svname, pkg); |
|
|
127 | } |
|
|
128 | |
|
|
129 | /*****************************************************************************/ |
|
|
130 | |
|
|
131 | static cl_event * |
|
|
132 | event_list (SV **items, int count) |
|
|
133 | { |
|
|
134 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
|
|
135 | |
|
|
136 | while (count--) |
|
|
137 | list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
|
|
138 | |
|
|
139 | return list; |
|
|
140 | } |
|
|
141 | |
|
|
142 | #define EVENT_LIST(items,count) \ |
|
|
143 | cl_uint event_list_count = (count); \ |
|
|
144 | cl_event *event_list_ptr = event_list (&ST (items), event_list_count) |
84 | |
145 | |
85 | #define INFO(class) \ |
146 | #define INFO(class) \ |
86 | { \ |
147 | { \ |
87 | size_t size; \ |
148 | size_t size; \ |
88 | SV *sv; \ |
149 | SV *sv; \ |
89 | \ |
150 | \ |
90 | NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ |
151 | NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ |
91 | sv = sv_2mortal (newSV (size)); \ |
152 | sv = sv_2mortal (newSV (size)); \ |
92 | SvUPGRADE (sv, SVt_PV); \ |
153 | SvUPGRADE (sv, SVt_PV); \ |
93 | SvPOK_only (sv); \ |
154 | SvPOK_only (sv); \ |
94 | SvCUR_set (sv, size); \ |
155 | SvCUR_set (sv, size); \ |
95 | NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ |
156 | NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ |
96 | XPUSHs (sv); \ |
157 | XPUSHs (sv); \ |
97 | } |
158 | } |
98 | |
159 | |
99 | static void * |
|
|
100 | SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg) |
|
|
101 | { |
|
|
102 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
|
|
103 | return (void *)SvIV (SvRV (sv)); |
|
|
104 | |
|
|
105 | croak ("%s: %s is not of type %s", func, svname, pkg); |
|
|
106 | } |
|
|
107 | |
|
|
108 | MODULE = OpenCL PACKAGE = OpenCL |
160 | MODULE = OpenCL PACKAGE = OpenCL |
109 | |
161 | |
110 | PROTOTYPES: ENABLE |
162 | PROTOTYPES: ENABLE |
111 | |
163 | |
112 | BOOT: |
164 | BOOT: |
113 | { |
165 | { |
114 | HV *stash = gv_stashpv ("OpenCL", 1); |
166 | HV *stash = gv_stashpv ("OpenCL", 1); |
115 | static const ivstr *civ, const_iv[] = { |
167 | static const ivstr *civ, const_iv[] = { |
116 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
168 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
117 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
169 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
118 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
170 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
119 | { sizeof (cl_ushort), "SIZEOF_USHORT"}, |
171 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
120 | { sizeof (cl_int ), "SIZEOF_INT" }, |
172 | { sizeof (cl_int ), "SIZEOF_INT" }, |
121 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
173 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
122 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
174 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
123 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
175 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
124 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
176 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
125 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
177 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
|
|
178 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
126 | #include "constiv.h" |
179 | #include "constiv.h" |
127 | }; |
180 | }; |
128 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
181 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
129 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
182 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
130 | } |
183 | } |
131 | |
184 | |
|
|
185 | cl_int |
|
|
186 | errno () |
|
|
187 | CODE: |
|
|
188 | errno = res; |
|
|
189 | |
132 | const char * |
190 | const char * |
133 | err2str (cl_int err) |
191 | err2str (cl_int err) |
134 | |
192 | |
135 | const char * |
193 | const char * |
136 | enum2str (cl_uint value) |
194 | enum2str (cl_uint value) |
… | |
… | |
142 | cl_platform_id *list; |
200 | cl_platform_id *list; |
143 | cl_uint count; |
201 | cl_uint count; |
144 | int i; |
202 | int i; |
145 | |
203 | |
146 | NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); |
204 | NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); |
147 | Newx (list, count, cl_platform_id); |
205 | list = tmpbuf (sizeof (*list) * count); |
148 | NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); |
206 | NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); |
149 | |
207 | |
150 | EXTEND (SP, count); |
208 | EXTEND (SP, count); |
151 | for (i = 0; i < count; ++i) |
209 | for (i = 0; i < count; ++i) |
152 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
210 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
153 | |
|
|
154 | Safefree (list); |
|
|
155 | } |
211 | } |
156 | |
212 | |
157 | void |
213 | void |
158 | context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) |
214 | context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
159 | PPCODE: |
215 | PPCODE: |
160 | { |
|
|
161 | cl_int res; |
|
|
162 | cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); |
216 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); |
163 | |
|
|
164 | if (res) |
|
|
165 | FAIL (CreateContextFromType, res); |
|
|
166 | |
|
|
167 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
217 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
168 | } |
218 | |
|
|
219 | void |
|
|
220 | context (FUTURE properties, FUTURE devices, FUTURE notify = 0) |
|
|
221 | PPCODE: |
|
|
222 | /* der Gipfel der Kunst */ |
169 | |
223 | |
170 | void |
224 | void |
171 | wait_for_events (...) |
225 | wait_for_events (...) |
172 | CODE: |
226 | CODE: |
173 | { |
227 | { |
… | |
… | |
191 | cl_device_id *list; |
245 | cl_device_id *list; |
192 | cl_uint count; |
246 | cl_uint count; |
193 | int i; |
247 | int i; |
194 | |
248 | |
195 | NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); |
249 | NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); |
196 | Newx (list, count, cl_device_id); |
250 | list = tmpbuf (sizeof (*list) * count); |
197 | NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); |
251 | NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); |
198 | |
252 | |
199 | EXTEND (SP, count); |
253 | EXTEND (SP, count); |
200 | for (i = 0; i < count; ++i) |
254 | for (i = 0; i < count; ++i) |
201 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
255 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
202 | |
|
|
203 | Safefree (list); |
|
|
204 | } |
256 | } |
205 | |
257 | |
206 | void |
258 | void |
|
|
259 | context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0) |
|
|
260 | PPCODE: |
|
|
261 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
|
|
262 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
|
|
263 | |
|
|
264 | AV *av = (SV *)SvRV (devices); |
|
|
265 | cl_uint num_devices = av_len (av) + 1; |
|
|
266 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
|
|
267 | int i; |
|
|
268 | |
|
|
269 | for (i = num_devices; i--; ) |
|
|
270 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
|
|
271 | |
|
|
272 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); |
|
|
273 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
|
|
274 | |
|
|
275 | void |
207 | context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) |
276 | context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
208 | PPCODE: |
277 | PPCODE: |
209 | { |
|
|
210 | cl_int res; |
|
|
211 | cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; |
278 | cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; |
212 | cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); |
279 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
213 | |
|
|
214 | if (res) |
|
|
215 | FAIL (CreateContextFromType, res); |
|
|
216 | |
|
|
217 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
280 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
218 | } |
|
|
219 | |
281 | |
220 | MODULE = OpenCL PACKAGE = OpenCL::Device |
282 | MODULE = OpenCL PACKAGE = OpenCL::Device |
221 | |
283 | |
222 | void |
284 | void |
223 | info (OpenCL::Device this, cl_device_info name) |
285 | info (OpenCL::Device this, cl_device_info name) |
224 | PPCODE: |
286 | PPCODE: |
225 | INFO (Device) |
287 | INFO (Device) |
226 | |
288 | |
227 | void |
|
|
228 | context_simple (OpenCL::Device this) |
|
|
229 | PPCODE: |
|
|
230 | { |
|
|
231 | cl_int res; |
|
|
232 | cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res); |
|
|
233 | |
|
|
234 | if (res) |
|
|
235 | FAIL (CreateContext, res); |
|
|
236 | |
|
|
237 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
|
|
238 | } |
|
|
239 | |
|
|
240 | MODULE = OpenCL PACKAGE = OpenCL::Context |
289 | MODULE = OpenCL PACKAGE = OpenCL::Context |
241 | |
290 | |
242 | void |
291 | void |
243 | DESTROY (OpenCL::Context context) |
292 | DESTROY (OpenCL::Context context) |
244 | CODE: |
293 | CODE: |
… | |
… | |
248 | info (OpenCL::Context this, cl_context_info name) |
297 | info (OpenCL::Context this, cl_context_info name) |
249 | PPCODE: |
298 | PPCODE: |
250 | INFO (Context) |
299 | INFO (Context) |
251 | |
300 | |
252 | void |
301 | void |
253 | command_queue_simple (OpenCL::Context this, OpenCL::Device device) |
302 | queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0) |
254 | PPCODE: |
303 | PPCODE: |
255 | { |
|
|
256 | cl_int res; |
|
|
257 | cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); |
304 | NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res)); |
258 | |
|
|
259 | if (res) |
|
|
260 | FAIL (CreateCommandQueue, res); |
|
|
261 | |
|
|
262 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
305 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
263 | } |
306 | |
|
|
307 | void |
|
|
308 | user_event (OpenCL::Context this) |
|
|
309 | PPCODE: |
|
|
310 | NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res)); |
|
|
311 | XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); |
264 | |
312 | |
265 | void |
313 | void |
266 | buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) |
314 | buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) |
267 | PPCODE: |
315 | PPCODE: |
268 | { |
|
|
269 | cl_int res; |
|
|
270 | cl_mem mem; |
|
|
271 | |
|
|
272 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
316 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
273 | croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
317 | croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
274 | |
318 | |
275 | mem = clCreateBuffer (this, flags, len, 0, &res); |
319 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res)); |
276 | |
|
|
277 | if (res) |
|
|
278 | FAIL (CreateBuffer, res); |
|
|
279 | |
|
|
280 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
320 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
281 | } |
|
|
282 | |
321 | |
283 | void |
322 | void |
284 | buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) |
323 | buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) |
285 | PPCODE: |
324 | PPCODE: |
286 | { |
|
|
287 | STRLEN len; |
325 | STRLEN len; |
288 | char *ptr = SvPVbyte (data, len); |
326 | char *ptr = SvPVbyte (data, len); |
289 | cl_int res; |
|
|
290 | cl_mem mem; |
|
|
291 | |
327 | |
292 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
328 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
293 | croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
329 | croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
294 | |
330 | |
295 | mem = clCreateBuffer (this, flags, len, ptr, &res); |
331 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); |
296 | |
|
|
297 | if (res) |
|
|
298 | FAIL (CreateBuffer, res); |
|
|
299 | |
|
|
300 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
332 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
301 | } |
|
|
302 | |
333 | |
303 | void |
334 | void |
304 | image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, SV *data) |
335 | image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, SV *data) |
305 | PPCODE: |
336 | PPCODE: |
306 | { |
|
|
307 | STRLEN len; |
337 | STRLEN len; |
308 | char *ptr = SvPVbyte (data, len); |
338 | char *ptr = SvPVbyte (data, len); |
309 | const cl_image_format format = { channel_order, channel_type }; |
339 | const cl_image_format format = { channel_order, channel_type }; |
310 | cl_int res; |
|
|
311 | cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res); |
340 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, len / height, ptr, &res)); |
312 | |
|
|
313 | if (res) |
|
|
314 | FAIL (CreateImage2D, res); |
|
|
315 | |
|
|
316 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
341 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
317 | } |
|
|
318 | |
342 | |
319 | void |
343 | void |
320 | image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t slice_pitch, SV *data) |
344 | image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t slice_pitch, SV *data) |
321 | PPCODE: |
345 | PPCODE: |
322 | { |
|
|
323 | STRLEN len; |
346 | STRLEN len; |
324 | char *ptr = SvPVbyte (data, len); |
347 | char *ptr = SvPVbyte (data, len); |
325 | const cl_image_format format = { channel_order, channel_type }; |
348 | const cl_image_format format = { channel_order, channel_type }; |
326 | cl_int res; |
|
|
327 | cl_mem mem = clCreateImage3D (this, flags, &format, width, height, |
349 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, |
328 | depth, len / (height * slice_pitch), slice_pitch, ptr, &res); |
350 | depth, len / (height * slice_pitch), slice_pitch, ptr, &res)); |
329 | |
|
|
330 | if (res) |
|
|
331 | FAIL (CreateImage3D, res); |
|
|
332 | |
|
|
333 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
351 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
334 | } |
|
|
335 | |
352 | |
336 | void |
353 | void |
337 | supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) |
354 | supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) |
338 | PPCODE: |
355 | PPCODE: |
339 | { |
356 | { |
… | |
… | |
356 | } |
373 | } |
357 | |
374 | |
358 | void |
375 | void |
359 | sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) |
376 | sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) |
360 | PPCODE: |
377 | PPCODE: |
361 | { |
|
|
362 | cl_int res; |
|
|
363 | cl_sampler sampler = clCreateSampler (this, normalized_coords, addressing_mode, filter_mode, &res); |
378 | NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res)); |
364 | |
|
|
365 | if (res) |
|
|
366 | FAIL (CreateSampler, res); |
|
|
367 | |
|
|
368 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
379 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
369 | } |
|
|
370 | |
380 | |
371 | void |
381 | void |
372 | program_with_source (OpenCL::Context this, SV *program) |
382 | program_with_source (OpenCL::Context this, SV *program) |
373 | PPCODE: |
383 | PPCODE: |
374 | { |
|
|
375 | STRLEN len; |
384 | STRLEN len; |
376 | size_t len2; |
385 | size_t len2; |
377 | const char *ptr = SvPVbyte (program, len); |
386 | const char *ptr = SvPVbyte (program, len); |
378 | cl_int res; |
|
|
379 | cl_program prog; |
|
|
380 | |
387 | |
381 | len2 = len; |
388 | len2 = len; |
382 | prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); |
389 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res)); |
383 | |
|
|
384 | if (res) |
|
|
385 | FAIL (CreateProgramWithSource, res); |
|
|
386 | |
|
|
387 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
390 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
388 | } |
|
|
389 | |
391 | |
390 | MODULE = OpenCL PACKAGE = OpenCL::Queue |
392 | MODULE = OpenCL PACKAGE = OpenCL::Queue |
391 | |
393 | |
392 | void |
394 | void |
393 | DESTROY (OpenCL::Queue this) |
395 | DESTROY (OpenCL::Queue this) |
… | |
… | |
558 | |
560 | |
559 | if (ev) |
561 | if (ev) |
560 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
562 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
561 | } |
563 | } |
562 | |
564 | |
563 | /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html */ |
565 | void |
|
|
566 | enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) |
|
|
567 | PPCODE: |
|
|
568 | { |
|
|
569 | cl_event ev = 0; |
|
|
570 | size_t *gwo = 0, *gws, *lws = 0; |
|
|
571 | int gws_len; |
|
|
572 | size_t *lists; |
|
|
573 | int i; |
|
|
574 | EVENT_LIST (5, items - 5); |
|
|
575 | |
|
|
576 | if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) |
|
|
577 | croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); |
|
|
578 | |
|
|
579 | gws_len = AvFILLp (SvRV (global_work_size)) + 1; |
|
|
580 | |
|
|
581 | lists = tmpbuf (sizeof (size_t) * 3 * gws_len); |
|
|
582 | |
|
|
583 | gws = lists + gws_len * 0; |
|
|
584 | for (i = 0; i < gws_len; ++i) |
|
|
585 | gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]); |
|
|
586 | |
|
|
587 | if (SvOK (global_work_offset)) |
|
|
588 | { |
|
|
589 | if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV) |
|
|
590 | croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference"); |
|
|
591 | |
|
|
592 | if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len) |
|
|
593 | croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size"); |
|
|
594 | |
|
|
595 | gwo = lists + gws_len * 1; |
|
|
596 | for (i = 0; i < gws_len; ++i) |
|
|
597 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
|
|
598 | } |
|
|
599 | |
|
|
600 | if (SvOK (local_work_size)) |
|
|
601 | { |
|
|
602 | if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
|
|
603 | croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); |
|
|
604 | |
|
|
605 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
|
|
606 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
|
|
607 | |
|
|
608 | lws = lists + gws_len * 2; |
|
|
609 | for (i = 0; i < gws_len; ++i) |
|
|
610 | lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]); |
|
|
611 | } |
|
|
612 | |
|
|
613 | NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
614 | |
|
|
615 | if (ev) |
|
|
616 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
617 | } |
564 | |
618 | |
565 | void |
619 | void |
566 | enqueue_marker (OpenCL::Queue this) |
620 | enqueue_marker (OpenCL::Queue this) |
567 | PPCODE: |
621 | PPCODE: |
568 | { |
622 | { |
… | |
… | |
652 | } |
706 | } |
653 | |
707 | |
654 | void |
708 | void |
655 | kernel (OpenCL::Program program, SV *function) |
709 | kernel (OpenCL::Program program, SV *function) |
656 | PPCODE: |
710 | PPCODE: |
657 | { |
|
|
658 | cl_int res; |
|
|
659 | cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); |
711 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
660 | |
|
|
661 | if (res) |
|
|
662 | FAIL (CreateKernel, res); |
|
|
663 | |
|
|
664 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
712 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
665 | } |
|
|
666 | |
713 | |
667 | MODULE = OpenCL PACKAGE = OpenCL::Kernel |
714 | MODULE = OpenCL PACKAGE = OpenCL::Kernel |
668 | |
715 | |
669 | void |
716 | void |
670 | DESTROY (OpenCL::Kernel this) |
717 | DESTROY (OpenCL::Kernel this) |
… | |
… | |
725 | set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) |
772 | set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) |
726 | CODE: |
773 | CODE: |
727 | clSetKernelArg (this, idx, sizeof (value), &value); |
774 | clSetKernelArg (this, idx, sizeof (value), &value); |
728 | |
775 | |
729 | void |
776 | void |
|
|
777 | set_double (OpenCL::Kernel this, cl_uint idx, cl_double value) |
|
|
778 | CODE: |
|
|
779 | clSetKernelArg (this, idx, sizeof (value), &value); |
|
|
780 | |
|
|
781 | void |
730 | set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value) |
782 | set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value) |
731 | CODE: |
783 | CODE: |
732 | clSetKernelArg (this, idx, sizeof (value), &value); |
784 | clSetKernelArg (this, idx, sizeof (value), &value); |
733 | |
785 | |
734 | void |
786 | void |
… | |
… | |
771 | void |
823 | void |
772 | wait (OpenCL::Event this) |
824 | wait (OpenCL::Event this) |
773 | CODE: |
825 | CODE: |
774 | clWaitForEvents (1, &this); |
826 | clWaitForEvents (1, &this); |
775 | |
827 | |
|
|
828 | MODULE = OpenCL PACKAGE = OpenCL::UserEvent |
|
|
829 | |
|
|
830 | void |
|
|
831 | set_status (OpenCL::UserEvent this, cl_int execution_status) |
|
|
832 | CODE: |
|
|
833 | clSetUserEventStatus (this, execution_status); |
|
|
834 | |