Mercurial > hg > Game > Cerium
annotate example/HelloWorld/main.cc @ 1716:c12df61ded45 draft
fix gpu profile. not work yet
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Oct 2013 17:21:10 +0900 |
parents | 55f92ed3f244 |
children | cd2ef2861eb1 |
rev | line source |
---|---|
109 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
5 #include "Func.h" | |
6 | |
7 extern void task_init(void); | |
8 | |
9 static int count = 1; | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
10 static int spe_num = 1; |
109 | 11 |
12 extern TaskManager *manager; | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
13 int use_task_creater = 0; |
109 | 14 |
253
0c9c9906d777
usr_help_str is nessesary for example
tkaito@localhost.localdomain
parents:
109
diff
changeset
|
15 const char *usr_help_str = "Usage: ./hello [-cpu spe_num] [-count N]\n\ |
109 | 16 -cpu Number of SPE (default 1) \n\ |
17 -count Number of task is print \"Hello, World!!\""; | |
18 | |
19 int | |
20 init(int argc, char **argv) | |
21 { | |
22 for (int i = 1; argv[i]; ++i) { | |
23 if (strcmp(argv[i], "-count") == 0) { | |
24 count = atoi(argv[++i]); | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
25 } else if (strcmp(argv[i], "-cpu") == 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
26 spe_num = atoi(argv[i+1]); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
27 } else if (strcmp(argv[i], "-t") == 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
28 use_task_creater = 1; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
29 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
30 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
31 |
253
0c9c9906d777
usr_help_str is nessesary for example
tkaito@localhost.localdomain
parents:
109
diff
changeset
|
32 |
109 | 33 } |
34 | |
35 return 0; | |
36 } | |
37 | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
38 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
39 static void simple_task_creater(int in_total_size, int out_total_size, |
1457 | 40 int command, int in_data_size, int out_data_size, |
41 void *in_data, void *out_data, TaskManager *manager, | |
42 HTask *wait_i, HTask *wait_me) { | |
43 | |
44 | |
45 int in_task_size = 0; | |
46 int out_task_size = 0; | |
47 | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
48 if (in_total_size != 0) { |
1457 | 49 in_task_size = in_total_size / in_data_size; |
50 if (in_total_size != in_task_size * in_data_size) { | |
51 printf("mismatch of in_total_size and in_data_size\n"); | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
52 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
53 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
54 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
55 if (out_total_size != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
56 out_task_size = out_total_size / out_data_size; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
57 if (out_total_size != out_task_size * out_data_size) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
58 printf("mismatch of out_total_size and out_data_size\n"); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
59 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
60 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
61 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
62 /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/ |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
63 int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
64 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
65 if (task_num == 0) task_num = 1; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
66 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
67 /*spe分あればいいのかな?*/ |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
68 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
69 int array_num = spe_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
70 if (task_num < array_num) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
71 array_num = task_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
72 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
73 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
74 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
75 int array_length = task_num / array_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
76 int rest = task_num % array_num; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
77 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
78 HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
79 TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_length*array_num); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
80 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
81 int index = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
82 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
83 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
84 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
85 task_array[k] = manager->create_task_array(command,array_length,0,1,1); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
86 t_exec[k] = 0; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
87 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
88 if (wait_me != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
89 wait_me->wait_for(task_array[k]); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
90 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
91 if (wait_i != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
92 task_array[k]->wait_for(wait_i); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
93 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
94 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
95 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
96 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
97 for (int j = 0; j < array_length; j++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
98 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
99 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
100 t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
101 t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
102 t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
103 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
104 index++; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
105 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
106 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
107 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
108 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
109 for (int k = 0; k < array_num; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
110 task_array[k]->spawn_task_array(t_exec[k]->next()); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
111 task_array[k]->set_cpu(SPE_ANY); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
112 task_array[k]->spawn(); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
113 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
114 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
115 for (int k = 0; k < rest; k++) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
116 HTaskPtr t_exec = manager->create_task(command); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
117 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
118 t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
119 t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
120 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
121 index++; |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
122 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
123 if (wait_me != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
124 wait_me->wait_for(t_exec); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
125 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
126 if (wait_i != 0) { |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
127 t_exec->wait_for(wait_i); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
128 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
129 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
130 t_exec->set_cpu(SPE_ANY); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
131 t_exec->spawn(); |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
132 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
133 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
134 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
135 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
136 } |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
137 |
109 | 138 void |
400 | 139 hello_init(TaskManager *manager) |
109 | 140 { |
786
043c98537bc5
fix early free of TaskArray, add SchedTaskArrayNop stage.
yutaka@localhost.localdomain
parents:
625
diff
changeset
|
141 |
109 | 142 for (int i = 0; i < count; i++) { |
1457 | 143 /** |
144 * Create Task | |
145 * create_task(Task ID); | |
146 */ | |
147 | |
148 | |
149 if (use_task_creater) { | |
150 | |
151 simple_task_creater(0,0,Hello,0,0,0,0,manager,0,0); | |
152 | |
153 } else { | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
154 |
1012 | 155 HTask *hello = manager->create_task(Hello); |
109 | 156 |
157 /** | |
158 * Select CPU | |
159 * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY | |
160 * if you do not call this, execute PPE. | |
161 */ | |
162 hello->set_cpu(SPE_ANY); | |
163 | |
164 /** | |
165 * Set 32bits parameter | |
166 * add_param(32bit parameter); | |
167 */ | |
786
043c98537bc5
fix early free of TaskArray, add SchedTaskArrayNop stage.
yutaka@localhost.localdomain
parents:
625
diff
changeset
|
168 hello->set_param(0,(memaddr)i); |
109 | 169 |
170 hello->spawn(); | |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
171 } |
109 | 172 } |
1039
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
173 |
e8ef7f5f22f6
add TaskCreater test funciton..
yutaka@localhost.localdomain
parents:
1012
diff
changeset
|
174 |
109 | 175 } |
176 | |
177 int | |
400 | 178 TMmain(TaskManager *manager, int argc, char *argv[]) |
109 | 179 { |
180 if (init(argc, argv) < 0) { | |
181 return -1; | |
182 } | |
183 | |
184 // Task Register | |
185 // ppe/task_init.cc | |
186 task_init(); | |
187 | |
400 | 188 hello_init(manager); |
109 | 189 |
190 return 0; | |
191 } |