blob: 8439ffb6dfdfe8ea509a01acfd53a95b29ddc018 [file] [log] [blame]
Tim Murray704616e2012-11-13 14:10:21 -08001
2#include "RenderScript.h"
3
4#include "ScriptC_multiply.h"
5
6using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -08007using namespace RSC;
Tim Murray704616e2012-11-13 14:10:21 -08008
9int 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();
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, NULL, 0);
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
Tim Murraya4cbc2b2012-11-14 17:18:08 -080043 ain->copy1DRangeFrom(0, numElems, buf, numElems*sizeof(uint32_t));
Tim Murray704616e2012-11-13 14:10:21 -080044
45 sc->forEach_multiply(ain, aout);
46
Tim Murraya4cbc2b2012-11-14 17:18:08 -080047 aout->copy1DRangeTo(0, numElems, buf, numElems*sizeof(uint32_t));
Tim Murray704616e2012-11-13 14:10:21 -080048
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}