Mercurial > hg > Game > Cerium
annotate example/flip/main.cc @ 2048:6796d85f3d6b draft
remove error
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Jan 2016 00:05:49 +0900 |
parents | 273de551f726 |
children |
rev | line source |
---|---|
1515 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <fcntl.h> | |
5 #include <sys/stat.h> | |
6 #include "types.h" | |
7 #include "TaskManager.h" | |
8 #include "GpuFunc.h" | |
9 | |
10 #define DEFAULT 5 | |
11 static long int length = DEFAULT; | |
12 static int task = 1; | |
13 int *indata; | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
14 int *data; |
1515 | 15 |
16 extern void task_init(void); | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
17 void TMend(TaskManager*); |
1515 | 18 |
19 char usr_help_str[] = "GpuRun [length]\n"; | |
20 | |
21 void | |
22 print_data(int *data, int size, const char *title) | |
23 { | |
24 printf("%s ---\n", title); | |
25 for ( int i = 0; i < size; i++) { | |
26 printf("%2d ", data[i]); | |
27 } | |
28 printf("\n"); | |
29 } | |
30 | |
31 /** | |
32 * タスク終了後の data1, data2 の確認 | |
33 */ | |
34 void | |
35 twice_result(SchedTask *s, void *a, void *b) | |
36 { | |
37 int* data = (int*)a; | |
38 long length = (long)b; | |
39 print_data(data, length, "after"); | |
40 } | |
41 | |
42 | |
43 int | |
44 init(int argc, char **argv) | |
45 { | |
46 for (int i = 1; argv[i]; ++i) { | |
47 if (strcmp(argv[i], "-length") == 0) { | |
48 length = atoi(argv[++i]); | |
49 } else if (strcmp(argv[i], "-count") == 0) { | |
50 task = atoi(argv[++i]); | |
51 } | |
52 } | |
53 | |
54 return 0; | |
55 } | |
56 | |
57 | |
58 void | |
59 tester(int *indata, int *outdata, int num) { | |
60 | |
61 //チェック | |
62 int check = 0; | |
63 for (int c=0; c<num; c++) { | |
64 if(outdata[c] == indata[c]*2) { | |
65 check++; | |
66 } | |
67 } | |
68 | |
69 printf("Computed '%d/%d' correct values\n",check,num); | |
70 | |
71 } | |
72 | |
73 | |
74 void | |
75 test(TaskManager *manager) { | |
76 indata = new int[length]; | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
77 data = new int; |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
78 |
1515 | 79 for (int c=0; c < length ;c++) { |
80 indata[c] = c; | |
81 } | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
82 *data = 2; |
1515 | 83 print_data(indata, length, "before"); |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
84 |
1515 | 85 HTaskPtr twice = manager->create_task(Twice); |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
86 |
1515 | 87 twice->set_param(0, (memaddr)length); |
88 twice->set_inData(0, indata, sizeof (int)*length); | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
89 twice->set_inData(1, data, sizeof(int)); |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
90 twice->set_outData(0, indata, sizeof (int)*length); |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
91 twice->set_outData(1, data, sizeof(int)); |
1515 | 92 twice->set_cpu(GPU_0); |
93 twice->flip(); | |
94 | |
95 /* | |
96 * set_post() で ppe task を渡せるようにしたい | |
97 */ | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
98 //twice->set_post(twice_result, (void*)indata, (void*)length); |
1515 | 99 |
100 twice->spawn(); | |
101 } | |
102 | |
103 int | |
104 TMmain(TaskManager *manager, int argc, char* argv[]) | |
105 { | |
106 if (init(argc, argv) < 0) { | |
107 return -1; | |
108 } | |
109 | |
110 task_init(); | |
111 | |
112 for (int i = 0; i < task; ++i) { | |
113 test(manager); | |
114 } | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
115 |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
116 manager->set_TMend(TMend); |
1515 | 117 return 0; |
118 } | |
119 | |
1960
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
120 void |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
121 TMend(TaskManager* manager) { |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
122 print_data(indata, length, "after"); |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
123 delete[] indata; |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
124 delete data; |
273de551f726
use multiple command_queue
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
1544
diff
changeset
|
125 } |
1515 | 126 /* end */ |