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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines