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