Home | History | Annotate | Download | only in cppstrided
      1 
      2 #include "RenderScript.h"
      3 
      4 #include "ScriptC_multiply.h"
      5 
      6 using namespace android;
      7 using namespace RSC;
      8 
      9 int main(int argc, char** argv)
     10 {
     11 
     12     uint32_t numElems = 1024;
     13     uint32_t stride = 1025;
     14 
     15     if (argc >= 2) {
     16         int tempStride = atoi(argv[1]);
     17         if (tempStride < 1024) {
     18             printf("stride must be greater than or equal to 1024\n");
     19             return 1;
     20         }
     21         stride = (uint32_t) tempStride;
     22     }
     23 
     24     sp<RS> rs = new RS();
     25 
     26     bool r = rs->init();
     27 
     28     sp<const Element> e = Element::U32(rs);
     29 
     30     Type::Builder tb(rs, e);
     31     tb.setX(numElems);
     32     tb.setY(numElems);
     33     sp<const Type> t = tb.create();
     34 
     35     sp<Allocation> ain = Allocation::createTyped(rs, t);
     36     sp<Allocation> aout = Allocation::createTyped(rs, t);
     37 
     38     sp<ScriptC_multiply> sc = new ScriptC_multiply(rs);
     39 
     40     uint32_t* buf = (uint32_t*) malloc(stride * numElems * sizeof(uint32_t));
     41     if (!buf) {
     42         printf("malloc failed\n");
     43         return 1;
     44     }
     45 
     46     for (uint32_t i = 0; i < numElems; i++) {
     47         for (uint32_t ct=0; ct < numElems; ct++) {
     48             *(buf+(stride*i)+ct) = (uint32_t)ct + (i * numElems);
     49         }
     50     }
     51 
     52     ain->copy2DStridedFrom(buf, stride * sizeof(uint32_t));
     53 
     54     sc->forEach_multiply(ain, aout);
     55 
     56     aout->copy2DStridedTo(buf, stride * sizeof(uint32_t));
     57 
     58     for (uint32_t i = 0; i < numElems; i++) {
     59         for (uint32_t ct=0; ct < numElems; ct++) {
     60             if (*(buf+(stride*i)+ct) != (uint32_t)(ct + (i * numElems)) * 2) {
     61                 printf("Mismatch at location %d, %d: %u\n", i, ct, *(buf+(stride*i)+ct));
     62                 return 1;
     63             }
     64         }
     65     }
     66 
     67     printf("Test successful with %u stride!\n", stride);
     68 
     69     sc.clear();
     70     t.clear();
     71     e.clear();
     72     ain.clear();
     73     aout.clear();
     74 }
     75