ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
(Generate patch)

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.17 by root, Tue Nov 22 10:39:47 2011 UTC vs.
Revision 1.21 by root, Mon Apr 16 06:39:54 2012 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#ifdef __APPLE__
6 #include <OpenCL/opencl.h>
7#else
5#include <CL/opencl.h> 8 #include <CL/opencl.h>
9#endif
6 10
7typedef cl_platform_id OpenCL__Platform; 11typedef cl_platform_id OpenCL__Platform;
8typedef cl_device_id OpenCL__Device; 12typedef cl_device_id OpenCL__Device;
9typedef cl_context OpenCL__Context; 13typedef cl_context OpenCL__Context;
10typedef cl_command_queue OpenCL__Queue; 14typedef cl_command_queue OpenCL__Queue;
11typedef cl_mem OpenCL__Memory; 15typedef cl_mem OpenCL__Memory;
12typedef cl_mem OpenCL__Buffer; 16typedef cl_mem OpenCL__Buffer;
17typedef cl_mem OpenCL__BufferObj;
13typedef cl_mem OpenCL__Image; 18typedef cl_mem OpenCL__Image;
14typedef cl_mem OpenCL__Image2D; 19typedef cl_mem OpenCL__Image2D;
15typedef cl_mem OpenCL__Image3D; 20typedef cl_mem OpenCL__Image3D;
16typedef cl_mem OpenCL__Memory_ornull; 21typedef cl_mem OpenCL__Memory_ornull;
17typedef cl_mem OpenCL__Buffer_ornull; 22typedef cl_mem OpenCL__Buffer_ornull;
137} 142}
138 143
139static cl_event * 144static cl_event *
140event_list (SV **items, int count) 145event_list (SV **items, int count)
141{ 146{
147 if (!count)
148 return 0;
149
142 cl_event *list = tmpbuf (sizeof (cl_event) * count); 150 cl_event *list = tmpbuf (sizeof (cl_event) * count);
143 151
144 while (count--) 152 while (count--)
145 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 153 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
146 154
560 PPCODE: 568 PPCODE:
561 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 569 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
562 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 570 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
563 571
564 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res)); 572 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res));
565 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 573 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
566 574
567void 575void
568buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 576buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
569 PPCODE: 577 PPCODE:
570 STRLEN len; 578 STRLEN len;
571 char *ptr = SvPVbyte (data, len); 579 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
572
573 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 580 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
574 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 581 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
575
576 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); 582 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
577 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 583 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
578 584
579void 585void
580image2d (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 row_pitch = 0, SV *data = &PL_sv_undef) 586image2d (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 row_pitch = 0, SV *data = &PL_sv_undef)
581 PPCODE: 587 PPCODE:
582 STRLEN len; 588 STRLEN len;
583 char *ptr = SvPVbyte (data, len); 589 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
584 const cl_image_format format = { channel_order, channel_type }; 590 const cl_image_format format = { channel_order, channel_type };
585 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res)); 591 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
586 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 592 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
587 593
588void 594void
589image3d (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 row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef) 595image3d (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 row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef)
590 PPCODE: 596 PPCODE:
591 STRLEN len; 597 STRLEN len;
592 char *ptr = SvPVbyte (data, len); 598 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
593 const cl_image_format format = { channel_order, channel_type }; 599 const cl_image_format format = { channel_order, channel_type };
594 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 600 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
595 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 601 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
596 602
597void 603void
785 791
786 if (ev) 792 if (ev)
787 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 793 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
788 794
789void 795void
796enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...)
797 PPCODE:
798 cl_event ev = 0;
799 const size_t src_origin[3] = { src_x, src_y, src_z };
800 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
801 const size_t region[3] = { width, height, depth };
802 EVENT_LIST (16, items - 16);
803
804 NEED_SUCCESS (EnqueueCopyBufferRect, (this, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
805
806 if (ev)
807 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
808
809void
790enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 810enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
791 PPCODE: 811 PPCODE:
792 cl_event ev = 0; 812 cl_event ev = 0;
793 const size_t src_origin[3] = { src_x, src_y, src_z }; 813 const size_t src_origin[3] = { src_x, src_y, src_z };
794 const size_t region[3] = { width, height, depth }; 814 const size_t region[3] = { width, height, depth };
836 856
837 if (ev) 857 if (ev)
838 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 858 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
839 859
840void 860void
841enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...)
842 PPCODE:
843 cl_event ev = 0;
844 const size_t src_origin[3] = { src_x, src_y, src_z };
845 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
846 const size_t region[3] = { width, height, depth };
847 EVENT_LIST (16, items - 16);
848
849 NEED_SUCCESS (EnqueueCopyBufferRect, (this, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
850
851 if (ev)
852 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
853
854void
855enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
856 PPCODE:
857 cl_event ev = 0;
858 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
859 const size_t region[3] = { width, height, depth };
860 EVENT_LIST (10, items - 10);
861
862 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
863
864 if (ev)
865 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
866
867void
868enqueue_copy_image (OpenCL::Queue this, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 861enqueue_copy_image (OpenCL::Queue this, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
869 PPCODE: 862 PPCODE:
870 cl_event ev = 0; 863 cl_event ev = 0;
871 const size_t src_origin[3] = { src_x, src_y, src_z }; 864 const size_t src_origin[3] = { src_x, src_y, src_z };
872 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 865 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
885 const size_t src_origin[3] = { src_x, src_y, src_z }; 878 const size_t src_origin[3] = { src_x, src_y, src_z };
886 const size_t region[3] = { width, height, depth }; 879 const size_t region[3] = { width, height, depth };
887 EVENT_LIST (10, items - 10); 880 EVENT_LIST (10, items - 10);
888 881
889 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 882 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
883
884 if (ev)
885 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
886
887void
888enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
889 PPCODE:
890 cl_event ev = 0;
891 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
892 const size_t region[3] = { width, height, depth };
893 EVENT_LIST (10, items - 10);
894
895 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
890 896
891 if (ev) 897 if (ev)
892 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 898 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
893 899
894void 900void
1120 NEED_SUCCESS (RetainMemObject, (value [i])); 1126 NEED_SUCCESS (RetainMemObject, (value [i]));
1121 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 1127 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1122 } 1128 }
1123 1129
1124#END:mem 1130#END:mem
1131
1132MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1133
1134void
1135sub_buffer_region (OpenCL::BufferObj this, cl_mem_flags flags, size_t origin, size_t size)
1136 PPCODE:
1137 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1138 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1139
1140 cl_buffer_region crdata = { origin, size };
1141
1142 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (this, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1143 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
1125 1144
1126MODULE = OpenCL PACKAGE = OpenCL::Image 1145MODULE = OpenCL PACKAGE = OpenCL::Image
1127 1146
1128void 1147void
1129image_info (OpenCL::Image this, cl_image_info name) 1148image_info (OpenCL::Image this, cl_image_info name)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines