comparison example/Bulk/main.cc @ 787:5df90e02e34f

fix Bulk
author yutaka@localhost.localdomain
date Sat, 24 Apr 2010 17:25:46 +0900
parents 226d95fa2691
children
comparison
equal deleted inserted replaced
786:ccf78a465459 787:5df90e02e34f
8 8
9 extern void task_init(void); 9 extern void task_init(void);
10 10
11 static int length = DATA_NUM; 11 static int length = DATA_NUM;
12 static int task = 3; 12 static int task = 3;
13 static int count = 3; 13 static int task_array_num = 3;
14 static int data_count = 3; 14 static int block_num = 3;
15 15
16 const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ 16 const char *usr_help_str = "Usage: ./twice [-length data_length] [-task_array_num task_num]\n\
17 -length Number of data (default DATA_NUM (Func.h))\n\ 17 -task_array_num Number of data in a block (default 16)\n\
18 -count Number of task (default 1)\n"; 18 -block_num Number of block\n\
19 -task Number of task\n\
20 -block_size Size of a block\n";
19 21
20 22
21 static void 23 static void
22 print_data(int *data, int size, const char *title) 24 print_data(int *data, int size, const char *title)
23 { 25 {
34 static void 36 static void
35 twice_result(SchedTask *s, void *a, void *b) 37 twice_result(SchedTask *s, void *a, void *b)
36 { 38 {
37 int* data = (int*)a; 39 int* data = (int*)a;
38 int* task_buf = (int*)b; 40 int* task_buf = (int*)b;
39 print_data(data, length*count, "after"); 41 print_data(data, length*task_array_num, "after");
40 free(data); 42 free(data);
41 free(task_buf); 43 free(task_buf);
42 } 44 }
43 45
44 static int 46 static int
45 init(int argc, char **argv) 47 init(int argc, char **argv)
46 { 48 {
49 int block_size = 16;
47 for (int i = 1; argv[i]; ++i) { 50 for (int i = 1; argv[i]; ++i) {
48 if (strcmp(argv[i], "-length") == 0) { 51 if (strcmp(argv[i], "-task") == 0) {
49 length = atoi(argv[++i]);
50 } else if (strcmp(argv[i], "-task") == 0) {
51 task = atoi(argv[++i]); 52 task = atoi(argv[++i]);
52 } else if (strcmp(argv[i], "-count") == 0) { 53 } else if (strcmp(argv[i], "-task_array_num") == 0) {
53 count = atoi(argv[++i]); 54 task_array_num = atoi(argv[++i]);
54 } else if (strcmp(argv[i], "-data_count") == 0) { 55 } else if (strcmp(argv[i], "-block_num") == 0) {
55 data_count = atoi(argv[++i]); 56 block_num = atoi(argv[++i]);
57 } else if (strcmp(argv[i], "-block_size") == 0) {
58 block_size = atoi(argv[++i]);
56 } 59 }
57 } 60 }
61 length = task_array_num * block_num * block_size;
58 62
59 return 0; 63 return 0;
60 } 64 }
61 65
62 #if 0 66 #if 0
71 void 75 void
72 twice_init(TaskManager *manager,int *data, int length) 76 twice_init(TaskManager *manager,int *data, int length)
73 { 77 {
74 78
75 79
76 for (int i = 0; i < length*count; i++) { 80 for (int i = 0; i < length*task_array_num; i++) {
77 data[i] = i; 81 data[i] = i;
78 } 82 }
79 83
80 print_data(data, length*count, "before"); 84 print_data(data, length*task_array_num, "before");
81 85
82 /** 86 /**
83 * Create Task 87 * Create Task
84 * create_task(Task ID); 88 * create_task(Task ID);
85 */ 89 */
86 90
87 HTask *twice_main = manager->create_task_array(Twice,count,data_count+1,data_count,data_count); 91 HTask *twice_main = manager->create_task_array(Twice,task_array_num,block_num+1,block_num,block_num);
88 Task *t = twice_main->next_task_array(Twice, 0); 92 Task *t = twice_main->next_task_array(Twice, 0);
89 #if 0 93 #if 0
90 printf("allocate task size 0x%0x\n",t->size()); 94 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, 95 printf("allocate task total size 0x%0x = 0x%0x * %d\n",twice_main->r_size,
92 t->size(), count); 96 t->size(), task_array_num);
93 #endif 97 #endif
94 void *task_buf = twice_main->rbuf; 98 void *task_buf = twice_main->rbuf;
95 twice_main->set_post(twice_result, (void*)data, task_buf); 99 twice_main->set_post(twice_result, (void*)data, task_buf);
96 100
97 t = 0; 101 t = 0;
98 for(int i = 0;i<count;i++) { 102 for(int i = 0;i<task_array_num;i++) {
99 t = twice_main->next_task_array(Twice, t); 103 t = twice_main->next_task_array(Twice, t);
100 int length2 = length/data_count; 104 int block_size = length/block_num;
101 t->set_param(0, (memaddr)data_count); 105 t->set_param(0, (memaddr)block_num);
102 106
103 for(int j = 0;j<data_count;j++) { 107 for(int j = 0;j<block_num;j++) {
104 /** 108 /**
105 * Set 32bits parameter 109 * Set 32bits parameter
106 * add_param(32bit parameter); 110 * add_param(32bit parameter);
107 */ 111 */
108 t->set_param(j+1, (memaddr)length2); 112 t->set_param(j+1, (memaddr)block_size);
109 /** 113 /**
110 * Set of Input Data 114 * Set of Input Data
111 * add_inData(address of input data, size of input data); 115 * add_inData(address of input data, size of input data);
112 */ 116 */
113 t->set_inData(j,data, sizeof(int)*length2); 117 t->set_inData(j,data, sizeof(int)*block_size);
114 /** 118 /**
115 * Set of Output area 119 * Set of Output area
116 * add_outData(address of output area, size of output area); 120 * add_outData(address of output area, size of output area);
117 */ 121 */
118 t->set_outData(j,data, sizeof(int)*length2); 122 t->set_outData(j,data, sizeof(int)*block_size);
119 data += length2; 123 data += block_size;
120 } 124 }
121 #if 0 125 #if 0
122 print_ListData(data_count,t->inData(0)); 126 print_ListData(block_num,t->inData(0));
123 print_ListData(data_count,t->outData(0)); 127 print_ListData(block_num,t->outData(0));
124 printf("pos 0x%0lx size 0x%0x\n",(unsigned long)t, t->size()); 128 printf("pos 0x%0lx size 0x%0x\n",(unsigned long)t, t->size());
125 #endif 129 #endif
126 } 130 }
127 twice_main->spawn_task_array(t->next()); 131 twice_main->spawn_task_array(t->next());
128 132
144 // Task Register 148 // Task Register
145 // ppe/task_init.cc 149 // ppe/task_init.cc
146 task_init(); 150 task_init();
147 151
148 for (int i = 0; i < task; ++i) { 152 for (int i = 0; i < task; ++i) {
149 int *data = (int*)manager->allocate(sizeof(int)*length*count); 153 int *data = (int*)manager->allocate(sizeof(int)*length*task_array_num);
150 twice_init(manager, data, length); 154 twice_init(manager, data, length);
151 } 155 }
152 156
153 return 0; 157 return 0;
154 } 158 }