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 14 if (argc >= 2) { 15 int tempNumElems = atoi(argv[1]); 16 if (tempNumElems < 1) { 17 printf("numElems must be greater than 0\n"); 18 return 1; 19 } 20 numElems = (uint32_t) tempNumElems; 21 } 22 23 sp<RS> rs = new RS(); 24 25 bool r = rs->init("/system/bin"); 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