Mercurial > hg > Members > yutaka > manager
annotate ppe/Manager.cc @ 6:b25035e3282d
fix
author | yutaka@localhost.localdomain |
---|---|
date | Sat, 10 Apr 2010 16:50:55 +0900 |
parents | 8b4d6bf8c43d |
children | ec2c1003f9b6 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <libspe2.h> | |
4 #include <pthread.h> | |
5 #include <time.h> | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
6 #include <unistd.h> |
0 | 7 #include "Manager.h" |
8 #include "MailCommand.h" | |
9 #include "SIZE.h" | |
10 #include "Sys.h" | |
11 #include "Spe.h" | |
12 #include "Menu.h" | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
13 #include "Run.h" |
0 | 14 #include "params.h" |
15 | |
16 void | |
2 | 17 ppe_run(task_head_t *head, int tmplist_num) |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
18 { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
19 |
2 | 20 task_head_t *tmphead; |
21 task_t *tmp = (task_t*)allocate(sizeof(task_t)); | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
22 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
23 //printf("hoge1\n"); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
24 |
2 | 25 for (int j = 0; j < tmplist_num; j++) { |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
26 |
2 | 27 //printf("list_num %d\n",tmplist_num); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
28 |
2 | 29 for (tmphead = (task_head_t*)head[j].next_task; tmphead != 0; tmphead = (task_head_t*)tmphead->next_task) { |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
30 |
2 | 31 fix_type(tmp, tmphead); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
32 |
6 | 33 void *out = (void*)tmp->head->ea_out; |
2 | 34 int *in = (int*)tmp->input; |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
35 |
6 | 36 int size_in = tmp->head->size_in - tmp->head->pin_in; |
37 int size_out = tmp->head->size_out - tmp->head->pin_out; | |
3 | 38 |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
39 //printf("in[%d] %f\n",i,in[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
40 //printf("out[%d] %f\n",i,out[i]); |
2 | 41 |
42 //printf("size->out %d\n",tmp->head->size_out); | |
43 | |
3 | 44 run(in, out, size_in, size_out); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
45 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
46 //printf("out_spe[%d] %f\n",i,out_spe[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
47 //printf("out[%d] %f\n",i,out[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
48 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
49 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
50 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
51 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
52 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
53 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
54 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
55 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
56 void |
2 | 57 check_output(task_head_t *head, int tmplist_num) |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
58 { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
59 |
2 | 60 task_head_t *tmphead; |
61 task_t *tmp = (task_t*)allocate(sizeof(task_t)); | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
62 |
2 | 63 for (int j = 0; j < tmplist_num; j++) { |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
64 |
2 | 65 for (tmphead = (task_head_t*)head[j].next_task; tmphead != 0; tmphead = (task_head_t*)tmphead->next_task) { |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
66 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
67 fix_type(tmp, (void*)tmphead); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
68 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
69 int *out = (int*)tmp->head->ea_out; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
70 int *out_spe = (int*)allocate(tmp->head->size_out); |
2 | 71 int *in = (int*)tmp->input; |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
72 |
6 | 73 int size_in = tmp->head->size_in - tmp->head->pin_in; |
74 int size_out = tmp->head->size_out - tmp->head->pin_out; | |
3 | 75 |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
76 //printf("in[%d] %f\n",i,in[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
77 //printf("out[%d] %f\n",i,out[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
78 |
3 | 79 run(in, out_spe, size_in, size_out); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
80 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
81 //printf("out_spe[%d] %f\n",i,out_spe[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
82 //printf("out[%d] %f\n",i,out[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
83 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
84 for (int i = 0; i < tmp->head->size_out / sizeof(int); i++) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
85 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
86 printf("out_spe[%d] %d\n",i,out_spe[i]); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
87 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
88 if (out_spe[i] != out[i]) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
89 printf("!\n"); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
90 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
91 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
92 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
93 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
94 free(out_spe); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
95 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
96 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
97 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
98 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
99 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
100 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
101 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
102 void |
2 | 103 send_task_params(int &list_num, int &index, task_head_t *head, |
0 | 104 spe_context_ptr_t spe, int &flag) |
105 { | |
106 | |
107 unsigned int data = 0; | |
108 | |
2 | 109 if ( list_num ) { |
0 | 110 |
111 data = (unsigned int) &head[index]; | |
112 | |
113 //send task param mail | |
114 spe_in_mbox_write(spe,&data,1,SPE_MBOX_ALL_BLOCKING); | |
115 | |
2 | 116 list_num--; |
0 | 117 index++; |
118 | |
119 } else { //task nothing, spe run end | |
120 data = SPE_RUN_END; | |
121 flag += 1; | |
122 //send run end mail | |
123 spe_in_mbox_write(spe,&data,1,SPE_MBOX_ALL_BLOCKING); | |
124 //printf("send run end mail\n"); | |
125 } | |
126 | |
127 } | |
128 | |
129 | |
130 int | |
131 main(int argc, char *argv[]) | |
132 { | |
133 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
134 clock_t prog_s = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
135 clock_t prog_e = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
136 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
137 prog_s = clock(); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
138 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
139 clock_t create_s = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
140 clock_t create_e = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
141 clock_t run_s = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
142 clock_t run_e = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
143 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
144 int opt; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
145 int check_flag = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
146 int time_flag = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
147 int ppe_flag = 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
148 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
149 while ( (opt = getopt(argc, argv, "ctp")) != -1) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
150 switch( opt ) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
151 case 'c' : check_flag = 1; break; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
152 case 't' : time_flag = 1; break; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
153 case 'p' : ppe_flag = 1; break; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
154 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
155 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
156 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
157 if (ppe_flag) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
158 |
2 | 159 int list_num; |
160 task_head_t *head = menu(list_num); | |
161 ppe_run(head, list_num); | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
162 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
163 prog_e = clock(); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
164 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
165 if (time_flag) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
166 printf("program_run_time %f\n",(double)(prog_e - prog_s)/CLOCKS_PER_SEC); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
167 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
168 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
169 return 0; |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
170 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
171 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
172 |
0 | 173 spe_program_handle_t *prog; |
174 //スタック上にとるのはだめだめ。malloc | |
175 spe_context_ptr_t spe[SPE_NUM]; | |
176 pthread_t thread[SPE_NUM]; | |
177 | |
178 prog = spe_image_open("spe-main"); | |
179 //thread run. spe run. | |
180 spe_run_start(spe,prog,thread,SPE_NUM); | |
181 | |
182 int all_spe_run_end = SPE_NUM; | |
183 int flag = 0; | |
184 | |
2 | 185 int list_num = 0; |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
186 create_s = clock(); |
2 | 187 task_head_t *head = menu(list_num); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
188 create_e = clock(); |
2 | 189 int tmplist_num = list_num; |
0 | 190 |
191 int index = 0; | |
192 unsigned int data = 0; | |
193 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
194 run_s = clock(); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
195 |
0 | 196 //mail check |
197 while(flag != all_spe_run_end) { | |
198 | |
199 for (int i = 0; i < SPE_NUM; i++) { | |
200 if (spe_out_mbox_status(spe[i])) { | |
201 spe_out_mbox_read(spe[i],&data,1); | |
202 | |
203 //spe wait come task | |
204 //ppe send task or run end request mail for spe | |
205 if (data == WANT_DATA) { | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
206 //printf("spe %p\n",spe[i]); |
2 | 207 send_task_params(list_num, index, head, spe[i], flag); |
0 | 208 } |
209 | |
210 } | |
211 | |
212 }// end for | |
213 | |
214 }//end while mail check | |
215 | |
216 spe_run_endwait(spe,thread,SPE_NUM); | |
217 spe_image_close(prog); | |
218 | |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
219 run_e = clock(); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
220 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
221 if (check_flag) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
222 printf("check now\n"); |
2 | 223 check_output(head, tmplist_num); |
1
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
224 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
225 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
226 prog_e = clock(); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
227 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
228 if (time_flag) { |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
229 printf("create_task_time %f\n",(double)(create_e - create_s)/CLOCKS_PER_SEC); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
230 printf("run_calc_time %f\n",(double)(run_e - run_s)/CLOCKS_PER_SEC); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
231 printf("program_run_time %f\n",(double)(prog_e - prog_s)/CLOCKS_PER_SEC); |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
232 } |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
233 |
dcd83cefb980
check , ppe_only, show time , function add.
yutaka@localhost.localdomain
parents:
0
diff
changeset
|
234 //head[0] |
0 | 235 |
236 return 0; | |
237 | |
238 } | |
239 | |
240 /*end*/ |