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