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

Comparing OpenCL/gengetinfo (file contents):
Revision 1.15 by root, Fri May 4 14:49:42 2012 UTC vs.
Revision 1.19 by root, Sat May 5 15:43:02 2012 UTC

23 kernel_arg_info Kernel 23 kernel_arg_info Kernel
24 command_queue Queue 24 command_queue Queue
25); 25);
26 26
27my %typemap = ( 27my %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.
49my %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])",
78 } 94 }
79 95
80 rename "$file~", $file; 96 rename "$file~", $file;
81} 97}
82 98
83for my $CLASS (qw(platform device context command_queue mem image sampler program program_build kernel kernel_work_group event profiling gl_texture)) { 99for my $CLASS (qw(platform device context command_queue mem image sampler program program_build kernel kernel_work_group kernel_arg event profiling gl_texture)) {
84 open my $fh, "<getinfo.txt" 100 open my $fh, "<getinfo.txt"
85 or die "getinfo.txt: $!"; 101 or die "getinfo.txt: $!";
86 102
87 my $POD; 103 my $POD;
88 my @funcs; 104 my @funcs;
107 $cbase = "EventProfiling" if $cbase eq "Profiling"; 123 $cbase = "EventProfiling" if $cbase eq "Profiling";
108 124
109 my $real_class = $CLASS; 125 my $real_class = $CLASS;
110 $real_class = "program" if $real_class eq "program_build"; 126 $real_class = "program" if $real_class eq "program_build";
111 $real_class = "kernel" if $real_class eq "kernel_work_group"; 127 $real_class = "kernel" if $real_class eq "kernel_work_group";
128 $real_class = "kernel" if $real_class eq "kernel_arg";
112 $real_class = "event" if $real_class eq "profiling"; 129 $real_class = "event" if $real_class eq "profiling";
113 130
114 my $perl_name = lc $name; 131 my $perl_name = lc $name;
115 $perl_name =~ s/^cl_//; 132 $perl_name =~ s/^cl_//;
116 $perl_name =~ s/^$real_class\_//; 133 $perl_name =~ s/^$real_class\_//;
174 191
175 $XS1 = "void\n" 192 $XS1 = "void\n"
176 . "XXXNAMEXXX (OpenCL::$classmap{$real_class} self$extra_xs_args)\n"; 193 . "XXXNAMEXXX (OpenCL::$classmap{$real_class} self$extra_xs_args)\n";
177 $XS2 = " PPCODE:\n"; 194 $XS2 = " PPCODE:\n";
178 195
196 my $stype = $type->[0]; # simplified type
197 $stype = $typesimplify{$stype} while exists $typesimplify{$stype};
198
179 if ($dynamic) { 199 if ($dynamic) {
180 $XS2 .= " size_t size;\n" 200 $XS2 .= " size_t size;\n"
181 . " 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"
182 . " $type->[0] *value = tmpbuf (size);\n" 202 . " $stype *value = tmpbuf (size);\n"
183 . " 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";
184 } else { 204 } else {
185 $XS2 .= " $type->[0] value [1];\n" 205 $XS2 .= " $stype value [1];\n"
186 . " 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";
187 } 207 }
188 208
189 if ($array && $nelem ne "1") { 209 if ($array && $nelem ne "1") {
190 $XS2 .= " int i, n = $nelem;\n" 210 $XS2 .= " int i, n = $nelem;\n"
202 222
203 my $stash = lc $type->[1]; 223 my $stash = lc $type->[1];
204 $stash =~ s/opencl:://; 224 $stash =~ s/opencl:://;
205 $stash =~ s/::/_/g; 225 $stash =~ s/::/_/g;
206 226
207 $XS2 .= " {\n";
208 $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";
209 $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n"; 228 $XS2 .= " PUSH_CLOBJ (stash_$stash, value [i]);\n";
210 $XS2 .= " }\n";
211 } else { 229 } else {
212 $XS2 .= " PUSHs (sv_2mortal ($type->[1]));\n"; 230 $XS2 .= " PUSHs (sv_2mortal ($type->[1]));\n";
213 } 231 }
214 232
215 $XS2 .= "\n"; 233 $XS2 .= "\n";
230 248
231 if (@{ $_->[1] } == 1) { # undo ALIAS 249 if (@{ $_->[1] } == 1) { # undo ALIAS
232 $_->[2] =~ s/\bix\b/$_->[1][0][1]/g; 250 $_->[2] =~ s/\bix\b/$_->[1][0][1]/g;
233 $_->[1] = ""; 251 $_->[1] = "";
234 } else { 252 } else {
235 $_->[1] = " ALIAS:\n" . join "", map " $_->[0] = $_->[1]\n", @{ $_->[1] }; 253 $_->[1] = " ALIAS:\n" . join "", sort, map " $_->[0] = $_->[1]\n", @{ $_->[1] };
236 } 254 }
237 $XS .= join "", @$_; 255 $XS .= join "", @$_;
238 } 256 }
239 257
240 warn "patching class $CLASS\n"; 258 warn "patching class $CLASS\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines