Home | History | Annotate | Download | only in P_reduce_general_inputs
      1 #!/usr/bin/perl -w
      2 
      3 # Generate trivial test cases to exercise input types.
      4 
      5 use strict;
      6 
      7 # deliberately non-exhaustive
      8 my @basicTypes = ("half", "float", # "double",
      9                   "char", "short", # "int", "long",
     10                   "uchar", "ushort", # "uint", "ulong",
     11                   "bool",
     12                   "rs_matrix2x2", # "rs_matrix3x3", "rs_matrix4x4",
     13                   "MyStruct");
     14 
     15 # 1 signifies non-vector
     16 # 3 is not supported for exported types
     17 my @vecLengths = (1, 2, 4);
     18 
     19 sub isVectorEligible {
     20   my ($type) = @_;
     21 
     22   # There are no bool vectors or struct vectors
     23   return 0 if ($type eq "bool") || ($type eq "MyStruct");
     24 
     25   # There are no matrix or object vectors
     26   return 0 if (substr($type, 0, 3) eq "rs_");
     27 
     28   # Else ok
     29   return 1;
     30 }
     31 
     32 print "// -Wall -Werror\n";
     33 print "#pragma version(1)\n";
     34 print "#pragma rs java_package_name(inputs)\n\n";
     35 print "// This test case was created by $0.\n";
     36 print "// It exercises various legal combinations of inputs and special parameters,\n";
     37 print "// so that we can ensure\n";
     38 print "// (a) We do not choke when compiling them\n";
     39 print "// (b) We reflect them correctly\n\n";
     40 print "// One example struct type\n";
     41 print "typedef struct MyStruct { float f; double d; } MyStruct;\n\n";
     42 print "// Trivial combiner shared by all test cases\n";
     43 print "static void combiner(int *accum, const int *other) { }\n";
     44 
     45 foreach my $basicTypeA (@basicTypes) {
     46   foreach my $vecLenA (@vecLengths) {
     47     next if ($vecLenA > 1) && !isVectorEligible($basicTypeA);
     48 
     49     my $eltNameA = $basicTypeA;
     50     $eltNameA .= $vecLenA if ($vecLenA > 1);
     51 
     52     foreach my $basicTypeB (@basicTypes) {
     53       foreach my $vecLenB (@vecLengths) {
     54         next if ($vecLenB > 1) && !isVectorEligible($basicTypeB);
     55 
     56         my $eltNameB = $basicTypeB;
     57         $eltNameB .= $vecLenB if ($vecLenB > 1);
     58 
     59         for (my $hasSpecial = 0; $hasSpecial <= 1; ++$hasSpecial) {
     60           my $reduceName = "my_${eltNameA}_${eltNameB}_${hasSpecial}";
     61           my $accumName = "${reduceName}_accum";
     62           print "\n";
     63           print "#pragma rs reduce(${reduceName}) accumulator(${accumName}) combiner(combiner)\n";
     64           print "static void ${accumName}(int *accum, ${eltNameA} a, ${eltNameB} b";
     65           print ", rs_kernel_context context" if ($hasSpecial);
     66           print ") { }\n";
     67         }
     68       }
     69     }
     70   }
     71 }
     72