Mercurial > hg > Game > Cerium
annotate example/Bulk/main.cc @ 698:72b2da99e875 draft
no compile error for Task Array
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 13 Dec 2009 20:14:18 +0900 |
parents | ecf63089f5bb |
children | 8ece2ac85149 |
rev | line source |
---|---|
659 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include "TaskManager.h" | |
688 | 5 #include "Task.h" |
659 | 6 #include "Func.h" |
7 | |
8 extern void task_init(void); | |
9 | |
10 static int length = DATA_NUM; | |
684 | 11 static int task = 10; |
12 static int count = 10; | |
659 | 13 |
14 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ | |
15 -length Number of data (default DATA_NUM (Func.h))\n\ | |
16 -count Number of task (default 1)\n"; | |
17 | |
18 | |
19 void | |
20 print_data(int *data, int size, const char *title) | |
21 { | |
22 printf("%s ---\n", title); | |
23 for (int i = 0; i < size; i++) { | |
24 printf("%2d ", data[i]); | |
25 } | |
26 printf("\n"); | |
27 } | |
28 | |
29 /** | |
30 * タスク終了後の data1, data2 の確認 | |
31 */ | |
32 void | |
33 twice_result(SchedTask *s, void *a, void *b) | |
34 { | |
35 int* data = (int*)a; | |
688 | 36 int* task_buf = (int*)b; |
659 | 37 print_data(data, length, "after"); |
38 free(data); | |
688 | 39 free(task_buf); |
659 | 40 } |
41 | |
42 int | |
43 init(int argc, char **argv) | |
44 { | |
45 for (int i = 1; argv[i]; ++i) { | |
46 if (strcmp(argv[i], "-length") == 0) { | |
47 length = atoi(argv[++i]); | |
48 } else if (strcmp(argv[i], "-count") == 0) { | |
49 task = atoi(argv[++i]); | |
50 } else if (strcmp(argv[i], "-bluk") == 0) { | |
51 count = atoi(argv[++i]); | |
52 } | |
53 } | |
54 | |
55 return 0; | |
56 } | |
57 | |
58 void | |
59 twice_init(TaskManager *manager) | |
60 { | |
61 | |
62 int *data = (int*)manager->allocate(sizeof(int)*length); | |
63 | |
64 for (int i = 0; i < length; i++) { | |
65 data[i] = i; | |
66 } | |
67 | |
68 print_data(data, length, "before"); | |
69 | |
70 /** | |
71 * Create Task | |
72 * create_task(Task ID); | |
73 */ | |
698
72b2da99e875
no compile error for Task Array
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
689
diff
changeset
|
74 int size = Task::calc_size(2,2,2); |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
75 printf("allocate task size 0x%0x\n",size); |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
76 printf("allocate task total size 0x%0x\n",(size *= count)); |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
77 |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
78 memaddr task_buf = (memaddr)manager->allocate(size); |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
79 HTask *twice_main = manager->create_task(TaskArray, task_buf, size, 0, 0); |
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
80 |
684 | 81 int pos = 0; |
659 | 82 for(int i = 0;i<count;i++) { |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
83 Task *t = twice_main->create_task_array(Twice,pos); |
659 | 84 int length2 = length/2; |
684 | 85 // 以下の順序でデータを追加する必要がある。 |
86 // length を先に指定すればsetは後からでも良い。 | |
659 | 87 /** |
88 * Set 32bits parameter | |
89 * add_param(32bit parameter); | |
90 */ | |
684 | 91 t->set_param_length(2); |
659 | 92 t->set_param(0, (memaddr)length2); |
93 t->set_param(1, (memaddr)length2); | |
94 /** | |
95 * Set of Input Data | |
96 * add_inData(address of input data, size of input data); | |
97 */ | |
684 | 98 t->set_inData_length(2); |
99 t->set_inData(0,data, sizeof(int)*length2); | |
100 t->set_inData(1,data+length2, sizeof(int)*length2); | |
659 | 101 /** |
684 | 102 * Set of Output area |
659 | 103 * add_outData(address of output area, size of output area); |
104 */ | |
684 | 105 t->set_outData_length(2); |
106 t->set_outData(0,data, sizeof(int)*length2); | |
107 t->set_outData(1,data+length2, sizeof(int)*length2); | |
108 pos += t->size(); | |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
109 printf("pos 0x%0x size 0x%0x\n",pos, t->size()); |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
110 } |
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
111 twice_main->spawn_task_array(pos); |
684 | 112 |
659 | 113 twice_main->set_cpu(SPE_ANY); |
114 /* | |
115 * set_post() で ppe task を渡せるようにしたい | |
116 */ | |
688 | 117 twice_main->set_post(twice_result, (void*)data, (void*)task_buf); |
659 | 118 // add Active Queue |
684 | 119 twice_main->spawn(); |
659 | 120 } |
121 | |
122 int | |
123 TMmain(TaskManager *manager,int argc, char *argv[]) | |
124 { | |
125 if (init(argc, argv) < 0) { | |
126 return -1; | |
127 } | |
128 | |
129 // Task Register | |
130 // ppe/task_init.cc | |
131 task_init(); | |
132 | |
133 for (int i = 0; i < task; ++i) { | |
134 twice_init(manager); | |
135 } | |
136 | |
137 return 0; | |
138 } |