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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.16 by root, Tue Nov 22 10:29:18 2011 UTC vs.
Revision 1.20 by root, Sat Dec 10 23:07:38 2011 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;
572 580
573 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 581 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?"); 582 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
575 583
576 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); 584 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
577 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 585 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
578 586
579void 587void
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) 588image2d (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: 589 PPCODE:
582 STRLEN len; 590 STRLEN len;
720 728
721 if (ev) 729 if (ev)
722 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 730 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
723 731
724void 732void
733enqueue_read_buffer_rect (OpenCL::Queue this, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
734 PPCODE:
735 cl_event ev = 0;
736 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
737 const size_t host_origin[3] = { host_x, host_y, host_z };
738 const size_t region[3] = { width, height, depth };
739 EVENT_LIST (17, items - 17);
740
741 if (!buf_row_pitch)
742 buf_row_pitch = region [0];
743
744 if (!buf_slice_pitch)
745 buf_slice_pitch = region [1] * buf_row_pitch;
746
747 if (!host_row_pitch)
748 host_row_pitch = region [0];
749
750 if (!host_slice_pitch)
751 host_slice_pitch = region [1] * host_row_pitch;
752
753 size_t len = host_row_pitch * host_slice_pitch * region [2];
754
755 SvUPGRADE (data, SVt_PV);
756 SvGROW (data, len);
757 SvPOK_only (data);
758 SvCUR_set (data, len);
759 NEED_SUCCESS (EnqueueReadBufferRect, (this, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
760
761 if (ev)
762 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
763
764void
765enqueue_write_buffer_rect (OpenCL::Queue this, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
766 PPCODE:
767 cl_event ev = 0;
768 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
769 const size_t host_origin[3] = { host_x, host_y, host_z };
770 const size_t region[3] = { width, height, depth };
771 STRLEN len;
772 char *ptr = SvPVbyte (data, len);
773 EVENT_LIST (17, items - 17);
774
775 if (!buf_row_pitch)
776 buf_row_pitch = region [0];
777
778 if (!buf_slice_pitch)
779 buf_slice_pitch = region [1] * buf_row_pitch;
780
781 if (!host_row_pitch)
782 host_row_pitch = region [0];
783
784 if (!host_slice_pitch)
785 host_slice_pitch = region [1] * host_row_pitch;
786
787 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
788
789 if (len < min_len)
790 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
791
792 NEED_SUCCESS (EnqueueWriteBufferRect, (this, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
793
794 if (ev)
795 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
796
797void
798enqueue_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, ...)
799 PPCODE:
800 cl_event ev = 0;
801 const size_t src_origin[3] = { src_x, src_y, src_z };
802 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
803 const size_t region[3] = { width, height, depth };
804 EVENT_LIST (16, items - 16);
805
806 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));
807
808 if (ev)
809 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
810
811void
725enqueue_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, ...) 812enqueue_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, ...)
726 PPCODE: 813 PPCODE:
727 cl_event ev = 0; 814 cl_event ev = 0;
728 const size_t src_origin[3] = { src_x, src_y, src_z }; 815 const size_t src_origin[3] = { src_x, src_y, src_z };
729 const size_t region[3] = { width, height, depth }; 816 const size_t region[3] = { width, height, depth };
771 858
772 if (ev) 859 if (ev)
773 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 860 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
774 861
775void 862void
776enqueue_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, ...)
777 PPCODE:
778 cl_event ev = 0;
779 const size_t src_origin[3] = { src_x, src_y, src_z };
780 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
781 const size_t region[3] = { width, height, depth };
782 EVENT_LIST (16, items - 16);
783
784 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));
785
786 if (ev)
787 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
788
789void
790enqueue_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, ...)
791 PPCODE:
792 cl_event ev = 0;
793 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
794 const size_t region[3] = { width, height, depth };
795 EVENT_LIST (10, items - 10);
796
797 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
798
799 if (ev)
800 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
801
802void
803enqueue_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, ...) 863enqueue_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, ...)
804 PPCODE: 864 PPCODE:
805 cl_event ev = 0; 865 cl_event ev = 0;
806 const size_t src_origin[3] = { src_x, src_y, src_z }; 866 const size_t src_origin[3] = { src_x, src_y, src_z };
807 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 867 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
820 const size_t src_origin[3] = { src_x, src_y, src_z }; 880 const size_t src_origin[3] = { src_x, src_y, src_z };
821 const size_t region[3] = { width, height, depth }; 881 const size_t region[3] = { width, height, depth };
822 EVENT_LIST (10, items - 10); 882 EVENT_LIST (10, items - 10);
823 883
824 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 884 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
885
886 if (ev)
887 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
888
889void
890enqueue_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, ...)
891 PPCODE:
892 cl_event ev = 0;
893 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
894 const size_t region[3] = { width, height, depth };
895 EVENT_LIST (10, items - 10);
896
897 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
825 898
826 if (ev) 899 if (ev)
827 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 900 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
828 901
829void 902void
1055 NEED_SUCCESS (RetainMemObject, (value [i])); 1128 NEED_SUCCESS (RetainMemObject, (value [i]));
1056 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 1129 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1057 } 1130 }
1058 1131
1059#END:mem 1132#END:mem
1133
1134MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1135
1136void
1137sub_buffer_region (OpenCL::BufferObj this, cl_mem_flags flags, size_t origin, size_t size)
1138 PPCODE:
1139 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1140 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1141
1142 cl_buffer_region crdata = { origin, size };
1143
1144 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (this, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1145 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
1060 1146
1061MODULE = OpenCL PACKAGE = OpenCL::Image 1147MODULE = OpenCL PACKAGE = OpenCL::Image
1062 1148
1063void 1149void
1064image_info (OpenCL::Image this, cl_image_info name) 1150image_info (OpenCL::Image this, cl_image_info name)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines