… | |
… | |
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 | static void * |
|
|
109 | tmpbuf (size_t size) |
|
|
110 | { |
|
|
111 | static void *buf; |
|
|
112 | static size_t len; |
|
|
113 | |
|
|
114 | if (len < size) |
|
|
115 | { |
|
|
116 | free (buf); |
|
|
117 | len = ((size + 31) & ~4095) + 4096 - 32; |
|
|
118 | buf = malloc (len); |
|
|
119 | } |
|
|
120 | |
|
|
121 | return buf; |
|
|
122 | } |
|
|
123 | |
|
|
124 | MODULE = OpenCL PACKAGE = OpenCL |
160 | MODULE = OpenCL PACKAGE = OpenCL |
125 | |
161 | |
126 | PROTOTYPES: ENABLE |
162 | PROTOTYPES: ENABLE |
127 | |
163 | |
128 | BOOT: |
164 | BOOT: |
129 | { |
165 | { |
130 | HV *stash = gv_stashpv ("OpenCL", 1); |
166 | HV *stash = gv_stashpv ("OpenCL", 1); |
131 | static const ivstr *civ, const_iv[] = { |
167 | static const ivstr *civ, const_iv[] = { |
132 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
168 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
133 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
169 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
134 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
170 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
135 | { sizeof (cl_ushort), "SIZEOF_USHORT"}, |
171 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
136 | { sizeof (cl_int ), "SIZEOF_INT" }, |
172 | { sizeof (cl_int ), "SIZEOF_INT" }, |
137 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
173 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
138 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
174 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
139 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
175 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
140 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
176 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
141 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
177 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
|
|
178 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
142 | #include "constiv.h" |
179 | #include "constiv.h" |
143 | }; |
180 | }; |
144 | 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--) |
145 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
182 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
146 | } |
183 | } |
147 | |
184 | |
|
|
185 | cl_int |
|
|
186 | errno () |
|
|
187 | CODE: |
|
|
188 | errno = res; |
|
|
189 | |
148 | const char * |
190 | const char * |
149 | err2str (cl_int err) |
191 | err2str (cl_int err) |
150 | |
192 | |
151 | const char * |
193 | const char * |
152 | enum2str (cl_uint value) |
194 | enum2str (cl_uint value) |
… | |
… | |
167 | for (i = 0; i < count; ++i) |
209 | for (i = 0; i < count; ++i) |
168 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
210 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
169 | } |
211 | } |
170 | |
212 | |
171 | void |
213 | void |
172 | 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) |
173 | PPCODE: |
215 | PPCODE: |
174 | { |
|
|
175 | cl_int res; |
|
|
176 | cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); |
216 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); |
177 | |
|
|
178 | if (res) |
|
|
179 | FAIL (CreateContextFromType, res); |
|
|
180 | |
|
|
181 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
217 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
182 | } |
218 | |
|
|
219 | void |
|
|
220 | context (FUTURE properties, FUTURE devices, FUTURE notify = 0) |
|
|
221 | PPCODE: |
|
|
222 | /* der Gipfel der Kunst */ |
183 | |
223 | |
184 | void |
224 | void |
185 | wait_for_events (...) |
225 | wait_for_events (...) |
186 | CODE: |
226 | CODE: |
187 | { |
227 | { |
… | |
… | |
214 | for (i = 0; i < count; ++i) |
254 | for (i = 0; i < count; ++i) |
215 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
255 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
216 | } |
256 | } |
217 | |
257 | |
218 | 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 |
219 | 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) |
220 | PPCODE: |
277 | PPCODE: |
221 | { |
|
|
222 | cl_int res; |
|
|
223 | 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 }; |
224 | cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); |
279 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
225 | |
|
|
226 | if (res) |
|
|
227 | FAIL (CreateContextFromType, res); |
|
|
228 | |
|
|
229 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
280 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
230 | } |
|
|
231 | |
281 | |
232 | MODULE = OpenCL PACKAGE = OpenCL::Device |
282 | MODULE = OpenCL PACKAGE = OpenCL::Device |
233 | |
283 | |
234 | void |
284 | void |
235 | info (OpenCL::Device this, cl_device_info name) |
285 | info (OpenCL::Device this, cl_device_info name) |
236 | PPCODE: |
286 | PPCODE: |
237 | INFO (Device) |
287 | INFO (Device) |
238 | |
288 | |
239 | void |
|
|
240 | context_simple (OpenCL::Device this) |
|
|
241 | PPCODE: |
|
|
242 | { |
|
|
243 | cl_int res; |
|
|
244 | cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res); |
|
|
245 | |
|
|
246 | if (res) |
|
|
247 | FAIL (CreateContext, res); |
|
|
248 | |
|
|
249 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
|
|
250 | } |
|
|
251 | |
|
|
252 | MODULE = OpenCL PACKAGE = OpenCL::Context |
289 | MODULE = OpenCL PACKAGE = OpenCL::Context |
253 | |
290 | |
254 | void |
291 | void |
255 | DESTROY (OpenCL::Context context) |
292 | DESTROY (OpenCL::Context context) |
256 | CODE: |
293 | CODE: |
… | |
… | |
260 | info (OpenCL::Context this, cl_context_info name) |
297 | info (OpenCL::Context this, cl_context_info name) |
261 | PPCODE: |
298 | PPCODE: |
262 | INFO (Context) |
299 | INFO (Context) |
263 | |
300 | |
264 | void |
301 | void |
265 | command_queue_simple (OpenCL::Context this, OpenCL::Device device) |
302 | queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0) |
266 | PPCODE: |
303 | PPCODE: |
267 | { |
|
|
268 | cl_int res; |
|
|
269 | cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); |
304 | NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res)); |
270 | |
|
|
271 | if (res) |
|
|
272 | FAIL (CreateCommandQueue, res); |
|
|
273 | |
|
|
274 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
305 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
275 | } |
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); |
276 | |
312 | |
277 | void |
313 | void |
278 | buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) |
314 | buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) |
279 | PPCODE: |
315 | PPCODE: |
280 | { |
|
|
281 | cl_int res; |
|
|
282 | cl_mem mem; |
|
|
283 | |
|
|
284 | 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)) |
285 | 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?"); |
286 | |
318 | |
287 | mem = clCreateBuffer (this, flags, len, 0, &res); |
319 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res)); |
288 | |
|
|
289 | if (res) |
|
|
290 | FAIL (CreateBuffer, res); |
|
|
291 | |
|
|
292 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
320 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
293 | } |
|
|
294 | |
321 | |
295 | void |
322 | void |
296 | buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) |
323 | buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) |
297 | PPCODE: |
324 | PPCODE: |
298 | { |
|
|
299 | STRLEN len; |
325 | STRLEN len; |
300 | char *ptr = SvPVbyte (data, len); |
326 | char *ptr = SvPVbyte (data, len); |
301 | cl_int res; |
|
|
302 | cl_mem mem; |
|
|
303 | |
327 | |
304 | 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))) |
305 | 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?"); |
306 | |
330 | |
307 | mem = clCreateBuffer (this, flags, len, ptr, &res); |
331 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); |
308 | |
|
|
309 | if (res) |
|
|
310 | FAIL (CreateBuffer, res); |
|
|
311 | |
|
|
312 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
332 | XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); |
313 | } |
|
|
314 | |
333 | |
315 | void |
334 | void |
316 | 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) |
317 | PPCODE: |
336 | PPCODE: |
318 | { |
|
|
319 | STRLEN len; |
337 | STRLEN len; |
320 | char *ptr = SvPVbyte (data, len); |
338 | char *ptr = SvPVbyte (data, len); |
321 | const cl_image_format format = { channel_order, channel_type }; |
339 | const cl_image_format format = { channel_order, channel_type }; |
322 | cl_int res; |
|
|
323 | 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)); |
324 | |
|
|
325 | if (res) |
|
|
326 | FAIL (CreateImage2D, res); |
|
|
327 | |
|
|
328 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
341 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
329 | } |
|
|
330 | |
342 | |
331 | void |
343 | void |
332 | 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) |
333 | PPCODE: |
345 | PPCODE: |
334 | { |
|
|
335 | STRLEN len; |
346 | STRLEN len; |
336 | char *ptr = SvPVbyte (data, len); |
347 | char *ptr = SvPVbyte (data, len); |
337 | const cl_image_format format = { channel_order, channel_type }; |
348 | const cl_image_format format = { channel_order, channel_type }; |
338 | cl_int res; |
|
|
339 | cl_mem mem = clCreateImage3D (this, flags, &format, width, height, |
349 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, |
340 | depth, len / (height * slice_pitch), slice_pitch, ptr, &res); |
350 | depth, len / (height * slice_pitch), slice_pitch, ptr, &res)); |
341 | |
|
|
342 | if (res) |
|
|
343 | FAIL (CreateImage3D, res); |
|
|
344 | |
|
|
345 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
351 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
346 | } |
|
|
347 | |
352 | |
348 | void |
353 | void |
349 | 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) |
350 | PPCODE: |
355 | PPCODE: |
351 | { |
356 | { |
… | |
… | |
368 | } |
373 | } |
369 | |
374 | |
370 | void |
375 | void |
371 | 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) |
372 | PPCODE: |
377 | PPCODE: |
373 | { |
|
|
374 | cl_int res; |
|
|
375 | 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)); |
376 | |
|
|
377 | if (res) |
|
|
378 | FAIL (CreateSampler, res); |
|
|
379 | |
|
|
380 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
379 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
381 | } |
|
|
382 | |
380 | |
383 | void |
381 | void |
384 | program_with_source (OpenCL::Context this, SV *program) |
382 | program_with_source (OpenCL::Context this, SV *program) |
385 | PPCODE: |
383 | PPCODE: |
386 | { |
|
|
387 | STRLEN len; |
384 | STRLEN len; |
388 | size_t len2; |
385 | size_t len2; |
389 | const char *ptr = SvPVbyte (program, len); |
386 | const char *ptr = SvPVbyte (program, len); |
390 | cl_int res; |
|
|
391 | cl_program prog; |
|
|
392 | |
387 | |
393 | len2 = len; |
388 | len2 = len; |
394 | prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); |
389 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res)); |
395 | |
|
|
396 | if (res) |
|
|
397 | FAIL (CreateProgramWithSource, res); |
|
|
398 | |
|
|
399 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
390 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
400 | } |
|
|
401 | |
391 | |
402 | MODULE = OpenCL PACKAGE = OpenCL::Queue |
392 | MODULE = OpenCL PACKAGE = OpenCL::Queue |
403 | |
393 | |
404 | void |
394 | void |
405 | DESTROY (OpenCL::Queue this) |
395 | DESTROY (OpenCL::Queue this) |
… | |
… | |
579 | cl_event ev = 0; |
569 | cl_event ev = 0; |
580 | size_t *gwo = 0, *gws, *lws = 0; |
570 | size_t *gwo = 0, *gws, *lws = 0; |
581 | int gws_len; |
571 | int gws_len; |
582 | size_t *lists; |
572 | size_t *lists; |
583 | int i; |
573 | int i; |
584 | EVENT_LIST (2, items - 2); |
574 | EVENT_LIST (5, items - 5); |
585 | |
575 | |
586 | if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) |
576 | if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) |
587 | croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); |
577 | croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); |
588 | |
578 | |
589 | gws_len = AvFILLp (SvRV (global_work_size)) + 1; |
579 | gws_len = AvFILLp (SvRV (global_work_size)) + 1; |
… | |
… | |
716 | } |
706 | } |
717 | |
707 | |
718 | void |
708 | void |
719 | kernel (OpenCL::Program program, SV *function) |
709 | kernel (OpenCL::Program program, SV *function) |
720 | PPCODE: |
710 | PPCODE: |
721 | { |
|
|
722 | cl_int res; |
|
|
723 | cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); |
711 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
724 | |
|
|
725 | if (res) |
|
|
726 | FAIL (CreateKernel, res); |
|
|
727 | |
|
|
728 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
712 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
729 | } |
|
|
730 | |
713 | |
731 | MODULE = OpenCL PACKAGE = OpenCL::Kernel |
714 | MODULE = OpenCL PACKAGE = OpenCL::Kernel |
732 | |
715 | |
733 | void |
716 | void |
734 | DESTROY (OpenCL::Kernel this) |
717 | DESTROY (OpenCL::Kernel this) |
… | |
… | |
789 | set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) |
772 | set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) |
790 | CODE: |
773 | CODE: |
791 | clSetKernelArg (this, idx, sizeof (value), &value); |
774 | clSetKernelArg (this, idx, sizeof (value), &value); |
792 | |
775 | |
793 | 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 |
794 | 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) |
795 | CODE: |
783 | CODE: |
796 | clSetKernelArg (this, idx, sizeof (value), &value); |
784 | clSetKernelArg (this, idx, sizeof (value), &value); |
797 | |
785 | |
798 | void |
786 | void |
… | |
… | |
835 | void |
823 | void |
836 | wait (OpenCL::Event this) |
824 | wait (OpenCL::Event this) |
837 | CODE: |
825 | CODE: |
838 | clWaitForEvents (1, &this); |
826 | clWaitForEvents (1, &this); |
839 | |
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 | |