Mercurial > hg > Game > Cerium
annotate example/Bulk/main.cc @ 839:1001c4bea1a0 draft
if unnecessary
author | Yutaka_Kinjyo |
---|---|
date | Fri, 28 May 2010 03:24:52 +0900 |
parents | 64f1d80dc650 |
children | 4b85fcf3c34d |
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" |
699 | 6 #include "ListData.h" |
659 | 7 #include "Func.h" |
8 | |
9 extern void task_init(void); | |
10 | |
11 static int length = DATA_NUM; | |
699 | 12 static int task = 3; |
787 | 13 static int task_array_num = 3; |
14 static int block_num = 3; | |
659 | 15 |
787 | 16 const char *usr_help_str = "Usage: ./twice [-length data_length] [-task_array_num task_num]\n\ |
17 -task_array_num Number of data in a block (default 16)\n\ | |
18 -block_num Number of block\n\ | |
19 -task Number of task\n\ | |
20 -block_size Size of a block\n"; | |
659 | 21 |
22 | |
699 | 23 static void |
659 | 24 print_data(int *data, int size, const char *title) |
25 { | |
26 printf("%s ---\n", title); | |
27 for (int i = 0; i < size; i++) { | |
28 printf("%2d ", data[i]); | |
29 } | |
30 printf("\n"); | |
31 } | |
32 | |
33 /** | |
34 * タスク終了後の data1, data2 の確認 | |
35 */ | |
699 | 36 static void |
659 | 37 twice_result(SchedTask *s, void *a, void *b) |
38 { | |
39 int* data = (int*)a; | |
688 | 40 int* task_buf = (int*)b; |
787 | 41 print_data(data, length*task_array_num, "after"); |
659 | 42 free(data); |
688 | 43 free(task_buf); |
659 | 44 } |
45 | |
699 | 46 static int |
659 | 47 init(int argc, char **argv) |
48 { | |
787 | 49 int block_size = 16; |
659 | 50 for (int i = 1; argv[i]; ++i) { |
787 | 51 if (strcmp(argv[i], "-task") == 0) { |
659 | 52 task = atoi(argv[++i]); |
787 | 53 } else if (strcmp(argv[i], "-task_array_num") == 0) { |
54 task_array_num = atoi(argv[++i]); | |
55 } else if (strcmp(argv[i], "-block_num") == 0) { | |
56 block_num = atoi(argv[++i]); | |
57 } else if (strcmp(argv[i], "-block_size") == 0) { | |
58 block_size = atoi(argv[++i]); | |
659 | 59 } |
60 } | |
787 | 61 length = task_array_num * block_num * block_size; |
659 | 62 |
63 return 0; | |
64 } | |
65 | |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
66 #if 0 |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
67 static void print_ListData(int size, ListElement *t) |
699 | 68 { |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
69 for(int i = 0;i<size;i++) { |
699 | 70 printf("ListData %d %d %lx\n",i,t[i].size,(unsigned long)t[i].addr); |
71 } | |
72 } | |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
73 #endif |
699 | 74 |
659 | 75 void |
700 | 76 twice_init(TaskManager *manager,int *data, int length) |
659 | 77 { |
78 | |
79 | |
787 | 80 for (int i = 0; i < length*task_array_num; i++) { |
659 | 81 data[i] = i; |
82 } | |
83 | |
787 | 84 print_data(data, length*task_array_num, "before"); |
659 | 85 |
86 /** | |
87 * Create Task | |
88 * create_task(Task ID); | |
89 */ | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
90 |
787 | 91 HTask *twice_main = manager->create_task_array(Twice,task_array_num,block_num+1,block_num,block_num); |
700 | 92 Task *t = twice_main->next_task_array(Twice, 0); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
93 #if 0 |
700 | 94 printf("allocate task size 0x%0x\n",t->size()); |
95 printf("allocate task total size 0x%0x = 0x%0x * %d\n",twice_main->r_size, | |
787 | 96 t->size(), task_array_num); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
97 #endif |
700 | 98 void *task_buf = twice_main->rbuf; |
99 twice_main->set_post(twice_result, (void*)data, task_buf); | |
687
25afcd4ae380
test code for TaskArray
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
686
diff
changeset
|
100 |
700 | 101 t = 0; |
787 | 102 for(int i = 0;i<task_array_num;i++) { |
700 | 103 t = twice_main->next_task_array(Twice, t); |
787 | 104 int block_size = length/block_num; |
105 t->set_param(0, (memaddr)block_num); | |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
106 |
787 | 107 for(int j = 0;j<block_num;j++) { |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
108 /** |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
109 * Set 32bits parameter |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
110 * add_param(32bit parameter); |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
111 */ |
787 | 112 t->set_param(j+1, (memaddr)block_size); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
113 /** |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
114 * Set of Input Data |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
115 * add_inData(address of input data, size of input data); |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
116 */ |
787 | 117 t->set_inData(j,data, sizeof(int)*block_size); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
118 /** |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
119 * Set of Output area |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
120 * add_outData(address of output area, size of output area); |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
121 */ |
787 | 122 t->set_outData(j,data, sizeof(int)*block_size); |
123 data += block_size; | |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
124 } |
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
125 #if 0 |
787 | 126 print_ListData(block_num,t->inData(0)); |
127 print_ListData(block_num,t->outData(0)); | |
700 | 128 printf("pos 0x%0lx size 0x%0x\n",(unsigned long)t, t->size()); |
701
44095db8cb61
Bulk task worked on Mac OS X
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
700
diff
changeset
|
129 #endif |
689
ecf63089f5bb
Task Array generation worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
688
diff
changeset
|
130 } |
700 | 131 twice_main->spawn_task_array(t->next()); |
684 | 132 |
659 | 133 twice_main->set_cpu(SPE_ANY); |
134 /* | |
135 * set_post() で ppe task を渡せるようにしたい | |
136 */ | |
137 // add Active Queue | |
684 | 138 twice_main->spawn(); |
659 | 139 } |
140 | |
141 int | |
142 TMmain(TaskManager *manager,int argc, char *argv[]) | |
143 { | |
144 if (init(argc, argv) < 0) { | |
145 return -1; | |
146 } | |
147 | |
148 // Task Register | |
149 // ppe/task_init.cc | |
150 task_init(); | |
151 | |
152 for (int i = 0; i < task; ++i) { | |
787 | 153 int *data = (int*)manager->allocate(sizeof(int)*length*task_array_num); |
700 | 154 twice_init(manager, data, length); |
659 | 155 } |
156 | |
157 return 0; | |
158 } |