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