Home | History | Annotate | Download | only in cppallocation
      1 
      2 #include "RenderScript.h"
      3 
      4 #include "ScriptC_multiply.h"
      5 
      6 int main(int argc, char** argv)
      7 {
      8 
      9     uint32_t numElems = 1024;
     10 
     11     if (argc >= 2) {
     12         int tempNumElems = atoi(argv[1]);
     13         if (tempNumElems < 1) {
     14             printf("numElems must be greater than 0\n");
     15             return 1;
     16         }
     17         numElems = (uint32_t) tempNumElems;
     18     }
     19 
     20     sp<RS> rs = new RS();
     21 
     22     if (!rs->init("/system/bin")) {
     23         printf("Could not initialize RenderScript\n");
     24         return 1;
     25     }
     26 
     27     sp<const Element> e = Element::U32(rs);
     28 
     29     Type::Builder tb(rs, e);
     30     tb.setX(numElems);
     31     sp<const Type> t = tb.create();
     32 
     33     sp<Allocation> ain = Allocation::createTyped(rs, t);
     34     sp<Allocation> aout = Allocation::createTyped(rs, t);
     35 
     36     sp<ScriptC_multiply> sc = new ScriptC_multiply(rs);
     37 
     38     uint32_t* buf = new uint32_t[numElems];
     39     for (uint32_t ct=0; ct < numElems; ct++) {
     40         buf[ct] = (uint32_t)ct;
     41     }
     42 
     43     ain->copy1DRangeFrom(0, numElems, buf);
     44 
     45     sc->forEach_multiply(ain, aout);
     46 
     47     aout->copy1DRangeTo(0, numElems, buf);
     48 
     49     for (uint32_t ct=0; ct < numElems; ct++) {
     50         if (buf[ct] !=  ct * 2) {
     51             printf("Mismatch at location %d: %u\n", ct, buf[ct]);
     52             return 1;
     53         }
     54     }
     55 
     56     printf("Test successful with %u elems!\n", numElems);
     57 
     58     sc.clear();
     59     t.clear();
     60     e.clear();
     61     ain.clear();
     62     aout.clear();
     63 }
     64