… | |
… | |
23 | kernel_arg_info Kernel |
23 | kernel_arg_info Kernel |
24 | command_queue Queue |
24 | command_queue Queue |
25 | ); |
25 | ); |
26 | |
26 | |
27 | my %typemap = ( |
27 | my %typemap = ( |
|
|
28 | # getinfo.txt c type, constructor, pod |
28 | cl_bool => ['cl_bool', 'value [i] ? &PL_sv_yes : &PL_sv_no', 'boolean'], |
29 | cl_bool => ['cl_bool', 'value [i] ? &PL_sv_yes : &PL_sv_no', 'boolean'], |
29 | #char => ['char', 'newSVpvn (value, size)', 'string'], |
30 | #char => ['char', 'newSVpvn (value, size)', 'string'], |
30 | char => ['char', 'newSVpv (value, 0)', 'string'], # all these are 0-terminated strings, and the driver often appends a \0 |
31 | char => ['char', 'newSVpv (value, 0)', 'string'], # all these are 0-terminated strings, and the driver often appends a \0 |
31 | size_t => ['size_t', 'newSVuv (value [i])', 'int'], |
32 | size_t => ['size_t', 'newSVuv (value [i])', 'int'], |
32 | "void*" => ['void *', 'newSVuv ((IV)(intptr_t)value [i])', 'ptr_value'], |
33 | "void*" => ['void *', 'newSVuv ((IV)(intptr_t)value [i])', 'ptr_value'], |
… | |
… | |
36 | cl_device_id => ['cl_device_id', 'OpenCL::Device', 'device'], |
37 | cl_device_id => ['cl_device_id', 'OpenCL::Device', 'device'], |
37 | Memory => ['cl_mem', 'OpenCL::Memory', 'mem'], |
38 | Memory => ['cl_mem', 'OpenCL::Memory', 'mem'], |
38 | Program => ['cl_program', 'OpenCL::Program', 'program'], |
39 | Program => ['cl_program', 'OpenCL::Program', 'program'], |
39 | CommandQueue => ['cl_command_queue', 'OpenCL::Queue', 'queue'], |
40 | CommandQueue => ['cl_command_queue', 'OpenCL::Queue', 'queue'], |
40 | cl_context_properties => ['cl_context_properties', 'newSVuv ((UV)value [i])', 'property_int'], |
41 | cl_context_properties => ['cl_context_properties', 'newSVuv ((UV)value [i])', 'property_int'], |
|
|
42 | cl_program_binary_type => ['cl_program_binary_type', 'newSVuv ((UV)value [i])', 'binary_type'], |
41 | ); |
43 | ); |
|
|
44 | |
|
|
45 | |
|
|
46 | # try to re-use types with same representation in C - if we |
|
|
47 | # ever overload bitfields etc. then we need to remove all |
|
|
48 | # typesimplify code. |
|
|
49 | my %typesimplify; |
|
|
50 | { |
|
|
51 | open my $h, "<CL/cl.h" or die "CL/cl.h: $!"; |
|
|
52 | |
|
|
53 | while (<$h>) { |
|
|
54 | $typesimplify{$2} = $1 |
|
|
55 | if /typedef\s+(cl_\S+)\s+(cl_\S+);/; |
|
|
56 | } |
|
|
57 | } |
42 | |
58 | |
43 | { |
59 | { |
44 | my %tmap = ( |
60 | my %tmap = ( |
45 | T_IV => "newSViv (value [i])", |
61 | T_IV => "newSViv (value [i])", |
46 | T_UV => "newSVuv (value [i])", |
62 | T_UV => "newSVuv (value [i])", |
… | |
… | |
175 | |
191 | |
176 | $XS1 = "void\n" |
192 | $XS1 = "void\n" |
177 | . "XXXNAMEXXX (OpenCL::$classmap{$real_class} self$extra_xs_args)\n"; |
193 | . "XXXNAMEXXX (OpenCL::$classmap{$real_class} self$extra_xs_args)\n"; |
178 | $XS2 = " PPCODE:\n"; |
194 | $XS2 = " PPCODE:\n"; |
179 | |
195 | |
|
|
196 | my $stype = $type->[0]; # simplified type |
|
|
197 | $stype = $typesimplify{$stype} while exists $typesimplify{$stype}; |
|
|
198 | |
180 | if ($dynamic) { |
199 | if ($dynamic) { |
181 | $XS2 .= " size_t size;\n" |
200 | $XS2 .= " size_t size;\n" |
182 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, 0, 0, &size));\n" |
201 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, 0, 0, &size));\n" |
183 | . " $type->[0] *value = tmpbuf (size);\n" |
202 | . " $stype *value = tmpbuf (size);\n" |
184 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, size, value, 0));\n"; |
203 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, size, value, 0));\n"; |
185 | } else { |
204 | } else { |
186 | $XS2 .= " $type->[0] value [1];\n" |
205 | $XS2 .= " $stype value [1];\n" |
187 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, sizeof (value), value, 0));\n"; |
206 | . " NEED_SUCCESS (Get${cbase}Info, (self$extra_args, ix, sizeof (value), value, 0));\n"; |
188 | } |
207 | } |
189 | |
208 | |
190 | if ($array && $nelem ne "1") { |
209 | if ($array && $nelem ne "1") { |
191 | $XS2 .= " int i, n = $nelem;\n" |
210 | $XS2 .= " int i, n = $nelem;\n" |
… | |
… | |
203 | |
222 | |
204 | my $stash = lc $type->[1]; |
223 | my $stash = lc $type->[1]; |
205 | $stash =~ s/opencl:://; |
224 | $stash =~ s/opencl:://; |
206 | $stash =~ s/::/_/g; |
225 | $stash =~ s/::/_/g; |
207 | |
226 | |
208 | $XS2 .= " {\n"; |
|
|
209 | $XS2 .= " NEED_SUCCESS (Retain$oclass, (value [i]));\n" unless $oclass eq "Platform" || $oclass eq "Device"; |
227 | $XS2 .= " NEED_SUCCESS (Retain$oclass, (value [i]));\n" unless $oclass eq "Platform" || $oclass eq "Device"; |
210 | $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n"; |
228 | $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n"; |
211 | $XS2 .= " }\n"; |
|
|
212 | } else { |
229 | } else { |
213 | $XS2 .= " PUSHs (sv_2mortal ($type->[1]));\n"; |
230 | $XS2 .= " PUSHs (sv_2mortal ($type->[1]));\n"; |
214 | } |
231 | } |
215 | |
232 | |
216 | $XS2 .= "\n"; |
233 | $XS2 .= "\n"; |
… | |
… | |
231 | |
248 | |
232 | if (@{ $_->[1] } == 1) { # undo ALIAS |
249 | if (@{ $_->[1] } == 1) { # undo ALIAS |
233 | $_->[2] =~ s/\bix\b/$_->[1][0][1]/g; |
250 | $_->[2] =~ s/\bix\b/$_->[1][0][1]/g; |
234 | $_->[1] = ""; |
251 | $_->[1] = ""; |
235 | } else { |
252 | } else { |
236 | $_->[1] = " ALIAS:\n" . join "", map " $_->[0] = $_->[1]\n", @{ $_->[1] }; |
253 | $_->[1] = " ALIAS:\n" . join "", sort, map " $_->[0] = $_->[1]\n", @{ $_->[1] }; |
237 | } |
254 | } |
238 | $XS .= join "", @$_; |
255 | $XS .= join "", @$_; |
239 | } |
256 | } |
240 | |
257 | |
241 | warn "patching class $CLASS\n"; |
258 | warn "patching class $CLASS\n"; |