• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl -w
2
3# Generate trivial test cases to exercise input types.
4
5use strict;
6
7# deliberately non-exhaustive
8my @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
17my @vecLengths = (1, 2, 4);
18
19sub 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
32print "// -Wall -Werror\n";
33print "#pragma version(1)\n";
34print "#pragma rs java_package_name(inputs)\n\n";
35print "// This test case was created by $0.\n";
36print "// It exercises various legal combinations of inputs and special parameters,\n";
37print "// so that we can ensure\n";
38print "// (a) We do not choke when compiling them\n";
39print "// (b) We reflect them correctly\n\n";
40print "// One example struct type\n";
41print "typedef struct MyStruct { float f; double d; } MyStruct;\n\n";
42print "// Trivial combiner shared by all test cases\n";
43print "static void combiner(int *accum, const int *other) { }\n";
44
45foreach 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