1 #include "RenderScript.h"
2 #include <sys/time.h>
3
4 #include "ScriptC_latency.h"
5
6 using namespace android;
7 using namespace RSC;
8
main(int argc,char ** argv)9 int main(int argc, char** argv)
10 {
11 int iters = 100;
12 int numElems = 1000;
13 bool forceCpu = false;
14 bool synchronous = false;
15
16 if (argc >= 2) {
17 iters = atoi(argv[1]);
18 if (iters <= 0) {
19 printf("iters must be positive\n");
20 return 1;
21 }
22 }
23
24 printf("iters = %d\n", iters);
25
26 if (argc >= 3) {
27 numElems = atoi(argv[2]);
28 if (numElems <= 0) {
29 printf("numElems must be positive\n");
30 return 1;
31 }
32 }
33
34 if (argc >= 4) {
35 int temp = atoi(argv[3]);
36 if (temp != 0)
37 forceCpu = true;
38 }
39
40 if (argc >= 5) {
41 int temp = atoi(argv[4]);
42 if (temp != 0)
43 synchronous = true;
44 }
45
46 if (forceCpu)
47 printf("forcing CPU\n");
48
49 if (synchronous)
50 printf("forcing synchronous\n");
51
52 printf("numElems = %d\n", numElems);
53
54 sp<RS> rs = new RS();
55
56 bool r = rs->init(forceCpu, synchronous);
57
58 sp<const Element> e = Element::U32(rs);
59
60 Type::Builder tb(rs, e);
61 tb.setX(numElems);
62 sp<const Type> t = tb.create();
63
64 uint32_t *buf = new uint32_t[numElems];
65
66 sp<Allocation> ain = Allocation::createTyped(rs, t);
67 sp<Allocation> aout = Allocation::createTyped(rs, t);
68
69 sp<ScriptC_latency> sc = new ScriptC_latency(rs, NULL, 0);
70
71 struct timeval start, stop;
72
73 gettimeofday(&start, NULL);
74
75 for (int i = 0; i < iters; i++) {
76 sc->forEach_root(ain, aout);
77 }
78
79 rs->finish();
80
81 gettimeofday(&stop, NULL);
82
83 long long elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
84 printf("elapsed time : %lld microseconds\n", elapsed);
85 printf("time per iter: %f microseconds\n", (double)elapsed / iters);
86
87 gettimeofday(&start, NULL);
88
89 for (int i = 0; i < iters; i++) {
90 ain->copy1DFrom(buf);
91 sc->forEach_root(ain, aout);
92 aout->copy1DTo(buf);
93 }
94
95 rs->finish();
96
97 gettimeofday(&stop, NULL);
98 elapsed = (stop.tv_sec * 1000000) - (start.tv_sec * 1000000) + (stop.tv_usec - start.tv_usec);
99 printf("elapsed time with copy : %lld microseconds\n", elapsed);
100 printf("time per iter with copy: %f microseconds\n", (double)elapsed / iters);
101
102 sc.clear();
103 t.clear();
104 e.clear();
105 ain.clear();
106 aout.clear();
107 }
108