… | |
… | |
144 | return 0; |
144 | return 0; |
145 | |
145 | |
146 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
146 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
147 | { |
147 | { |
148 | AV *av = (AV *)SvRV (sv); |
148 | AV *av = (AV *)SvRV (sv); |
149 | int i, len = av_len (av); |
149 | int i, len = av_len (av) + 1; |
150 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
150 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
151 | cl_context_properties *l = p; |
151 | cl_context_properties *l = p; |
152 | |
152 | |
153 | if (len & 1) |
153 | if (len & 1) |
154 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
154 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
155 | |
155 | |
156 | while (extracount--) |
156 | while (extracount--) |
157 | *l++ = *extra++; |
157 | *l++ = *extra++; |
158 | |
158 | |
159 | for (i = 0; i < len; i += 2) |
159 | for (i = 0; i < len; ++i) |
160 | { |
160 | { |
161 | cl_context_properties t = SvIV (*av_fetch (av, i, 0)); |
161 | cl_context_properties t = SvIV (*av_fetch (av, i, 0)); |
162 | cl_context_properties v; |
162 | cl_context_properties v; |
|
|
163 | |
|
|
164 | ++i; |
163 | |
165 | |
164 | switch (t) |
166 | switch (t) |
165 | { |
167 | { |
166 | default: |
168 | default: |
167 | /* unknown property, treat as int */ |
169 | /* unknown property, treat as int */ |
… | |
… | |
336 | |
338 | |
337 | void |
339 | void |
338 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
340 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
339 | PPCODE: |
341 | PPCODE: |
340 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
342 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
341 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
343 | croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); |
342 | |
344 | |
343 | AV *av = (AV *)SvRV (devices); |
345 | AV *av = (AV *)SvRV (devices); |
344 | cl_uint num_devices = av_len (av) + 1; |
346 | cl_uint num_devices = av_len (av) + 1; |
345 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
347 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
346 | int i; |
348 | int i; |
… | |
… | |
616 | |
618 | |
617 | void |
619 | void |
618 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
620 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
619 | PPCODE: |
621 | PPCODE: |
620 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
622 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
621 | croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
623 | croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
622 | |
624 | |
623 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
625 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
624 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
626 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
625 | |
627 | |
626 | void |
628 | void |
627 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
629 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
628 | PPCODE: |
630 | PPCODE: |
629 | STRLEN len; |
631 | STRLEN len; |
630 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
632 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
631 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
633 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
632 | croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
634 | croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
633 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
635 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
634 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
636 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
635 | |
637 | |
636 | void |
638 | void |
637 | image2d (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef) |
639 | image2d (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef) |
… | |
… | |
1037 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1039 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1038 | |
1040 | |
1039 | if (ev) |
1041 | if (ev) |
1040 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1042 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1041 | |
1043 | |
1042 | #if 0 |
|
|
1043 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
1044 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
1044 | |
1045 | |
1045 | void |
1046 | void |
1046 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
1047 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1048 | ALIAS: |
|
|
1049 | enqueue_release_gl_objects = 1 |
1047 | CODE: |
1050 | CODE: |
|
|
1051 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
|
|
1052 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
|
|
1053 | |
1048 | cl_event ev = 0; |
1054 | cl_event ev = 0; |
1049 | EVENT_LIST (2, items - 2); |
1055 | EVENT_LIST (2, items - 2); |
|
|
1056 | AV *av = (AV *)SvRV (objects); |
|
|
1057 | cl_uint num_objects = av_len (av) + 1; |
|
|
1058 | cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); |
|
|
1059 | int i; |
1050 | |
1060 | |
|
|
1061 | for (i = num_objects; i--; ) |
|
|
1062 | object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); |
|
|
1063 | |
|
|
1064 | if (ix) |
|
|
1065 | NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1066 | else |
1051 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, ..., event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1067 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1052 | |
1068 | |
1053 | if (ev) |
1069 | if (ev) |
1054 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1070 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1055 | |
1071 | |
1056 | void |
|
|
1057 | enqueue_release_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1058 | CODE: |
|
|
1059 | cl_event ev = 0; |
|
|
1060 | EVENT_LIST (2, items - 2); |
|
|
1061 | |
|
|
1062 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, ..., event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1063 | |
|
|
1064 | if (ev) |
|
|
1065 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1066 | |
|
|
1067 | #endif |
|
|
1068 | #endif |
1072 | #endif |
1069 | |
1073 | |
1070 | void |
1074 | void |
1071 | enqueue_marker (OpenCL::Queue self) |
1075 | enqueue_marker (OpenCL::Queue self) |
1072 | PPCODE: |
1076 | PPCODE: |