… | |
… | |
28 | #if PREFER_1_1 |
28 | #if PREFER_1_1 |
29 | #define CL_USE_DEPRECATED_OPENCL_1_1_APIS |
29 | #define CL_USE_DEPRECATED_OPENCL_1_1_APIS |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | #ifdef __APPLE__ |
32 | #ifdef __APPLE__ |
33 | #include <OpenCL/opencl.h> |
33 | #define CLHDR(name) <OpenCL/name> |
34 | #else |
34 | #else |
|
|
35 | #define CLHDR(name) <CL/name> |
|
|
36 | #endif |
|
|
37 | |
35 | #include <CL/opencl.h> |
38 | #include CLHDR(opencl.h) |
|
|
39 | |
|
|
40 | #ifndef CL_VERSION_1_2 |
|
|
41 | #include CLHDR(cl_d3d9.h) |
|
|
42 | #endif |
|
|
43 | |
|
|
44 | #if _WIN32 |
|
|
45 | #include CLHDR(cl_d3d10.h) |
|
|
46 | #if CL_VERSION_1_2 |
|
|
47 | #include CLHDR<cl_d3d11.h> |
|
|
48 | #endif |
|
|
49 | #include CLHDR<cl_dx9_media_sharing.h.h> |
36 | #endif |
50 | #endif |
37 | |
51 | |
38 | #ifndef CL_VERSION_1_2 |
52 | #ifndef CL_VERSION_1_2 |
39 | #undef PREFER_1_1 |
53 | #undef PREFER_1_1 |
40 | #define PREFER_1_1 1 |
54 | #define PREFER_1_1 1 |
41 | #endif |
55 | #endif |
|
|
56 | |
|
|
57 | // make sure all constants we might use are actually defined |
|
|
58 | #include "default.h" |
42 | |
59 | |
43 | typedef cl_platform_id OpenCL__Platform; |
60 | typedef cl_platform_id OpenCL__Platform; |
44 | typedef cl_device_id OpenCL__Device; |
61 | typedef cl_device_id OpenCL__Device; |
45 | typedef cl_device_id OpenCL__SubDevice; |
62 | typedef cl_device_id OpenCL__SubDevice; |
46 | typedef cl_context OpenCL__Context; |
63 | typedef cl_context OpenCL__Context; |
… | |
… | |
175 | IV iv; |
192 | IV iv; |
176 | const char *name; |
193 | const char *name; |
177 | #define const_iv(name) { (IV)CL_ ## name, # name }, |
194 | #define const_iv(name) { (IV)CL_ ## name, # name }, |
178 | } ivstr; |
195 | } ivstr; |
179 | |
196 | |
|
|
197 | typedef struct |
|
|
198 | { |
|
|
199 | NV nv; |
|
|
200 | const char *name; |
|
|
201 | #define const_nv(name) { (NV)CL_ ## name, # name }, |
|
|
202 | } nvstr; |
|
|
203 | |
180 | static const char * |
204 | static const char * |
181 | iv2str (IV value, const ivstr *base, int count, const char *fallback) |
205 | iv2str (IV value, const ivstr *base, int count, const char *fallback) |
182 | { |
206 | { |
183 | int i; |
207 | int i; |
184 | static char strbuf [32]; |
208 | static char strbuf [32]; |
… | |
… | |
778 | eq_signal_arg = (void*)arg; |
802 | eq_signal_arg = (void*)arg; |
779 | |
803 | |
780 | BOOT: |
804 | BOOT: |
781 | { |
805 | { |
782 | HV *stash = gv_stashpv ("OpenCL", 1); |
806 | HV *stash = gv_stashpv ("OpenCL", 1); |
|
|
807 | |
783 | static const ivstr *civ, const_iv[] = { |
808 | static const ivstr *civ, const_iv[] = { |
784 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
809 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
785 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
810 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
786 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
811 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
787 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
812 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
… | |
… | |
796 | #include "constiv.h" |
821 | #include "constiv.h" |
797 | }; |
822 | }; |
798 | |
823 | |
799 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
824 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
800 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
825 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
|
|
826 | |
|
|
827 | static const nvstr *cnv, const_nv[] = { |
|
|
828 | #include "constnv.h" |
|
|
829 | }; |
|
|
830 | |
|
|
831 | for (cnv = const_nv + sizeof (const_nv) / sizeof (const_nv [0]); cnv > const_nv; cnv--) |
|
|
832 | newCONSTSUB (stash, (char *)cnv[-1].name, newSVnv (cnv[-1].nv)); |
|
|
833 | |
|
|
834 | newCONSTSUB (stash, "NAN", newSVnv (CL_NAN)); // CL_NAN might be a function call |
801 | |
835 | |
802 | stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD); |
836 | stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD); |
803 | stash_device = gv_stashpv ("OpenCL::Device", GV_ADD); |
837 | stash_device = gv_stashpv ("OpenCL::Device", GV_ADD); |
804 | stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD); |
838 | stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD); |
805 | stash_context = gv_stashpv ("OpenCL::Context", GV_ADD); |
839 | stash_context = gv_stashpv ("OpenCL::Context", GV_ADD); |
… | |
… | |
2517 | PPCODE: |
2551 | PPCODE: |
2518 | cl_program_binary_type value [1]; |
2552 | cl_program_binary_type value [1]; |
2519 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0)); |
2553 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0)); |
2520 | EXTEND (SP, 1); |
2554 | EXTEND (SP, 1); |
2521 | const int i = 0; |
2555 | const int i = 0; |
2522 | PUSHs (sv_2mortal (newSVuv (UV)value [i]))); |
2556 | PUSHs (sv_2mortal (newSVuv ((UV)value [i]))); |
2523 | |
2557 | |
2524 | #END:program_build |
2558 | #END:program_build |
2525 | |
2559 | |
2526 | void |
2560 | void |
2527 | kernel (OpenCL::Program program, SV *function) |
2561 | kernel (OpenCL::Program program, SV *function) |
… | |
… | |
2777 | CODE: |
2811 | CODE: |
2778 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2812 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2779 | |
2813 | |
2780 | void |
2814 | void |
2781 | set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) |
2815 | set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) |
2782 | ALIAS: |
|
|
2783 | set_image2d = 0 |
|
|
2784 | set_image3d = 0 |
|
|
2785 | CODE: |
2816 | CODE: |
2786 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2817 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2787 | |
2818 | |
2788 | void |
2819 | void |
2789 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
2820 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |