annotate example/word_count/main.cc @ 1894:b37dfbf3380d draft

fix GpuTaskManagerFactory
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Sun, 12 Jan 2014 10:28:52 +0900
parents 44fa0f1320a9
children 606f6f6cb784
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1584
Masa <e085726@ie.u-ryukyu.ac.jp>
parents: 1579
diff changeset
1 #include <stdio.h>
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
2 #include <stdlib.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
3 #include <string.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
4 #include <sys/mman.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
5 #include <sys/types.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
6 #include <sys/stat.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
7 #include <fcntl.h>
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
8 #include <unistd.h>
1544
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
9 #include <sys/time.h>
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
10 #include "TaskManager.h"
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
11 #include "SchedTask.h"
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
12 #include "Func.h"
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
13 #include "WordCount.h"
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
14
1268
f0808a329663 find bug
Daichi Toma <amothic@gmail.com>
parents: 1123
diff changeset
15 /* ;TODO
f0808a329663 find bug
Daichi Toma <amothic@gmail.com>
parents: 1123
diff changeset
16 * PS3でCPU数が2以上の時に、あまりが計算されてない
f0808a329663 find bug
Daichi Toma <amothic@gmail.com>
parents: 1123
diff changeset
17 */
f0808a329663 find bug
Daichi Toma <amothic@gmail.com>
parents: 1123
diff changeset
18
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
19 extern void task_init();
1544
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
20 void TMend(TaskManager *);
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
21 static double st_time;
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
22 static double ed_time;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
23 int all = 0;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
24 int use_task_array = 1;
1039
e8ef7f5f22f6 add TaskCreater test funciton..
yutaka@localhost.localdomain
parents: 1021
diff changeset
25 int use_task_creater = 0;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
26 int use_compat = 0;
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
27 int use_iterate = 0;
967
daab1b74b32d add anum option in WordCount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 950
diff changeset
28 int array_task_num = 8;
970
1a4849b2acad change pipeline and TaskArray fast
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 968
diff changeset
29 int spe_num = 1;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
30 CPU_TYPE spe_cpu = SPE_ANY;
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
31 const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename]\n";
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
32
1544
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
33 static double
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
34 getTime() {
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
35 struct timeval tv;
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
36 gettimeofday(&tv, NULL);
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
37 return tv.tv_sec + (double)tv.tv_usec*1e-6;
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
38 }
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
39
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
40 typedef struct {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
41 caddr_t file_mmap;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
42 off_t size;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
43 } st_mmap_t;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
44
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
45 /*与えられたsizeをfix_byte_sizeの倍数にする(丸め込むっていうのかな?)*/
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
46 static int
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
47 fix_byte(int size,int fix_byte_size)
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
48 {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
49 size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
50
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
51 return size;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
52 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
53
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
54
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
55 static st_mmap_t
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
56 my_mmap(char *filename)
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
57 {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
58
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
59 /*マッピングだよ!*/
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
60 int fd = -1;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
61 int map = MAP_PRIVATE;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
62 st_mmap_t st_mmap;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
63 struct stat sb;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
64
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
65 if ((fd=open(filename,O_RDONLY,0666))==0) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
66 fprintf(stderr,"can't open %s\n",filename);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
67 }
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
68
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
69 if (fstat(fd,&sb)) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
70 fprintf(stderr,"can't fstat %s\n",filename);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
71 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
72
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
73 printf("file size %d\n",(int)sb.st_size);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
74
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
75 /*sizeをページングサイズの倍数にあわせる*/
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
76 st_mmap.size = fix_byte(sb.st_size,4096);
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
77
394
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
78 printf("fix 4096byte file size %d\n",(int)st_mmap.size);
1783
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
79
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
80 st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0);
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
81 if (st_mmap.file_mmap == (caddr_t)-1) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
82 fprintf(stderr,"Can't mmap file\n");
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
83 perror(NULL);
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
84 exit(0);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
85 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
86
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
87 return st_mmap;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
88
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
89 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
90
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
91 static void
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
92 run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size)
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
93 {
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
94
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
95 if (task_count < array_task_num) {
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
96 array_task_num = task_count;
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
97 if (task_count<=0) return;
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
98 }
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
99
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
100 for (int i = 0; i < task_count; i += array_task_num) {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
101 HTask *task_array;
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
102 if (use_task_array) {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
103 int task_num = (w->size+size-1)/size;
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
104 if (task_num>array_task_num) task_num = array_task_num;
1836
56692133c5fb success run wordcount with gpu, but result is wrong
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1835
diff changeset
105 task_array = manager->create_task_array(TASK_EXEC,task_num,1,1,1);
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
106 if (!all) {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
107 t_next->wait_for(task_array);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
108 } else {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
109 w->t_print->wait_for(task_array);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
110 }
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
111 }
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
112
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
113 Task *t_exec = 0;
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
114 HTask *h_exec = 0;
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
115 for (int j = 0; j < array_task_num; j++) {
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
116 int i = w->task_spwaned++;
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
117 if (w->size < size) size = w->size;
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
118 if (size==0) break;
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
119 if (use_task_array) {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
120 t_exec = task_array->next_task_array(TASK_EXEC,t_exec);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
121 t_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
122 t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
1836
56692133c5fb success run wordcount with gpu, but result is wrong
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1835
diff changeset
123 t_exec->set_param(0,(long)size);
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
124 } else if (use_compat) {
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
125 h_exec = manager->create_task(TASK_EXEC);
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
126 h_exec->set_inData(0,w->file_mmap + i*w->division_size, size);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
127 h_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
128
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
129 t_next->wait_for(h_exec);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
130
1737
6bd9a57eb44d minor fix
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1727
diff changeset
131 h_exec->set_cpu(spe_cpu);
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
132 h_exec->spawn();
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
133 } else if (use_iterate) {
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
134 w->size -= size*array_task_num;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
135 if(w->size < 0) array_task_num -= 1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
136 h_exec = manager->create_task(TASK_EXEC_DATA_PARALLEL);
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
137 // h_exec->flip();
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
138 h_exec->set_inData(0,w->file_mmap,w->file_size);
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
139 // h_exec->set_inData(1,w->o_data,w->out_size_);
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
140 // h_exec->set_outData(0,w->file_mmap,w->file_size);
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
141 h_exec->set_outData(0,w->o_data,w->out_size_);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
142 h_exec->set_param(0,(long)i);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
143 h_exec->set_param(1,(long)w->division_size);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
144 h_exec->set_param(2,(long)size);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
145 h_exec->set_param(3,(long)w->out_size);
1836
56692133c5fb success run wordcount with gpu, but result is wrong
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1835
diff changeset
146
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
147 t_next->wait_for(h_exec);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
148 h_exec->set_cpu(spe_cpu);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
149 h_exec->iterate(array_task_num);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
150
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
151 w->task_num -= array_task_num;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
152 w->task_spwaned += array_task_num-1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
153
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
154 if(w->size < 0) {
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
155 h_exec = manager->create_task(TASK_EXEC_DATA_PARALLEL);
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
156 // h_exec->flip();
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
157 h_exec->set_inData(0,w->file_mmap,w->file_size);
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
158 // h_exec->set_inData(1,w->o_data,w->out_size_);
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
159 // h_exec->set_outData(0,w->file_mmap,w->file_size);
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
160 h_exec->set_outData(0,w->o_data,w->out_size_);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
161 h_exec->set_param(0,(long)w->task_spwaned);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
162 h_exec->set_param(1,(long)w->division_size);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
163 h_exec->set_param(2,(long)(size+w->size));
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
164 h_exec->set_param(3,(long)w->out_size);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
165
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
166 t_next->wait_for(h_exec);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
167 h_exec->set_cpu(spe_cpu);
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
168 h_exec->iterate(1);
1870
44fa0f1320a9 run wordcount with iterate
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1837
diff changeset
169
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
170 w->task_num -= 1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
171 w->task_spwaned += 1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
172 array_task_num += 1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
173 }
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
174 break;
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
175 } else {
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
176 h_exec = manager->create_task(TASK_EXEC,
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
177 (memaddr)(w->file_mmap + i*w->division_size), size,
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
178 (memaddr)(w->o_data + i*w->out_size), w->division_out_size);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
179 t_next->wait_for(h_exec);
1737
6bd9a57eb44d minor fix
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1727
diff changeset
180 h_exec->set_cpu(spe_cpu);
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
181 h_exec->spawn();
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
182 }
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
183 w->size -= size;
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
184 w->task_num--;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
185 }
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
186 if (use_task_array) {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
187 task_array->spawn_task_array(t_exec->next());
1737
6bd9a57eb44d minor fix
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1727
diff changeset
188 task_array->set_cpu(spe_cpu);
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
189 task_array->spawn();
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
190 } else {
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
191 //if (!all) t_next->wait_for(h_exec);
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
192 }
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
193 }
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
194 }
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
195
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
196 /**
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
197 * このTaskは、PPE上で実行されるので、並列に実行されることはない
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
198 * 二つ実行されていて、Task が足りなくなることがないようにしている。
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
199 */
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
200
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
201 SchedDefineTask1(RUN_TASK_BLOCKS,run16);
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
202
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
203 static int
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
204 run16(SchedTask *manager, void *in, void *out)
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
205 {
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
206 WordCount *w = *(WordCount **)in;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
207
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
208 if (w->task_num < w->task_blocks) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
209 // last case
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
210 while (w->size >= w->division_size)
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
211 run_tasks(manager,w,w->task_num, w->t_print, w->division_size);
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
212 // remaining data
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
213 while (w->size>0)
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
214 run_tasks(manager,w,1, w->t_print, w->size);
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
215 // printf("run16 last %d\n",w->task_num);
949
5f0135ca75ee word count size fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 948
diff changeset
216 } else {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
217 HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS,
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
218 (memaddr)&w->self,sizeof(memaddr),0,0);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
219 w->t_print->wait_for(t_next);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
220
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
221 run_tasks(manager,w, w->task_blocks, t_next, w->division_size);
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
222
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
223 t_next->spawn();
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
224 // printf("run16 next %d\n",w->task_num);
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
225 }
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
226 return 0;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
227 }
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
228
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
229
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
230 static int blocks = 48;
1123
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 1083
diff changeset
231 //static int blocks = 31 * 6 * 24;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
232 static int division = 16; // in Kbyte
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
233
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
234 static void
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
235 run_start(TaskManager *manager, char *filename)
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
236 {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
237 HTaskPtr t_print;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
238
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
239 st_mmap_t st_mmap;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
240 st_mmap = my_mmap(filename);
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
241 WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount));
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
242 // bzero(w,sizeof(WordCount));
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
243
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
244 //w->task_blocks = blocks;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
245 w->self = w;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
246 w->task_spwaned = 0;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
247
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
248 /*sizeはdivision_sizeの倍数にしている。*/
949
5f0135ca75ee word count size fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 948
diff changeset
249 w->size = w->file_size = st_mmap.size;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
250 w->file_mmap = st_mmap.file_mmap;
949
5f0135ca75ee word count size fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 948
diff changeset
251 printf("w %lx\n",(long)w);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
252
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
253 /* 1task分のデータサイズ(byte) */
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
254 if (w->size >= 1024*division) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
255 w->division_size = 1024 * division;/*16kbyte*/
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
256 } else {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
257 w->division_size = w->size;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
258 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
259
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
260 printf("dvision_size %d\n",w->division_size);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
261
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
262 /* "word num" and "line num" */
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
263 w->status_num = 2;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
264 /* taskの数 */
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
265 w->task_num = w->size / w->division_size;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
266 w->task_num = w->task_num + (w->division_size*w->task_num < w->size);
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
267 int out_task_num = w->task_num;
394
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
268
968
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
269 if(!all) {
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
270 w->task_blocks = blocks;
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
271 } else {
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
272 w->task_blocks = w->task_num;
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
273 }
122b1fddfa94 fix wordcount
Yutaka Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents: 967
diff changeset
274
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
275 w->out_task_num = out_task_num;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
276 printf("task_num %d\n",w->task_num);
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
277 printf("out_task_num %d\n",w->out_task_num);
394
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
278
1007
00c01f416e3a add mail_queue
yutaka@localhost.localdomain
parents: 972
diff changeset
279 /* out用のdivision_size. statusが2つなので、あわせて16byteになるように、long long(4byte)を使用 */
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
280
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
281 w->division_out_size = sizeof(unsigned long long)*4;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
282 int out_size = w->division_out_size*out_task_num;
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
283 w->o_data = (unsigned long long *)manager->allocate(out_size);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
284 w->out_size_ = out_size;
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
285 w->out_size = 4;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
286 printf("out size %d\n",out_size);
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
287
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
288 /*各SPEの結果を合計して出力するタスク*/
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
289
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
290 t_print = manager->create_task(TASK_PRINT,
1542
9ccfdc408d51 fix gpu word count.but not count line num.
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1538
diff changeset
291 (memaddr)&w->self,sizeof(memaddr),0,0);
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
292 w->t_print = t_print;
1783
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
293
1837
093bdd5e940e add file
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1836
diff changeset
294 for(int i=0;i<1;i++) {
1783
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
295 /* Task を task_blocks ずつ起動する Task */
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
296 /* serialize されていると仮定する... */
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
297 HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS,
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
298 (memaddr)&w->self,sizeof(memaddr),0,0);
1783
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
299 t_print->wait_for(t_exec);
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
300 // t_exec->iterate(4);
1783
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
301 t_exec->spawn();
803dfdd1c741 minor change
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1737
diff changeset
302 }
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
303 t_print->spawn();
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
304 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
305
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
306 static char*
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
307 init(int argc, char **argv)
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
308 {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
309
394
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
310 char *filename = 0;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
311
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
312 for (int i = 1; argv[i]; ++i) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
313 if (strcmp(argv[i], "-file") == 0) {
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
314 filename = argv[i+1]; i++;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
315 } else if (strcmp(argv[i], "-division") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
316 division = atoi(argv[i+1]);
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
317 i++;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
318 } else if (strcmp(argv[i], "-block") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
319 blocks = atoi(argv[i+1]);
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
320 i++;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
321 } else if (strcmp(argv[i], "-a") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
322 // create task all at once
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
323 all = 1;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
324 } else if (strcmp(argv[i], "-c") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
325 use_task_array = 0;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
326 use_compat = 1;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
327 } else if (strcmp(argv[i], "-s") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
328 use_task_array = 0;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
329 use_compat = 0;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
330 } else if (strcmp(argv[i], "-t") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
331 use_task_creater = 1;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
332 use_task_array = 0;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
333 use_compat = 0;
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
334 } else if (strcmp(argv[i], "-anum") == 0) {
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
335 array_task_num = atoi(argv[i+1]);
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
336 i++;
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
337 } else if (strcmp(argv[i], "-g") == 0) {
1835
144e573b030b fix fft
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1799
diff changeset
338 spe_cpu = GPU_ANY;
1894
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
339 } else if (strcmp(argv[i], "-any") == 0) {
b37dfbf3380d fix GpuTaskManagerFactory
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1870
diff changeset
340 spe_cpu = ANY_ANY;
1799
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
341 } else if (strcmp(argv[i], "-i") == 0) {
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
342 use_iterate = 1;
d9122ca02431 Exec wordcount by Data Parallel
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1783
diff changeset
343 use_task_array = 0;
1737
6bd9a57eb44d minor fix
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents: 1727
diff changeset
344 }/* else if (strcmp(argv[i], "-cpu") == 0) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
345 spe_num = atoi(argv[i+1]);
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
346 i++;
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
347 if (spe_num==0) spe_num = 1;
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
348 } else {
1679
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
349 fprintf(stderr,"%s\n",usr_help_str);
ff43dc274ec9 word_count fix for GPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1678
diff changeset
350 exit (0);
1688
705f09f646ac remove spe_num roop
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1684
diff changeset
351 }*/
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
352 }
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
353 if (filename==0) {
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
354 puts(usr_help_str);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
355 exit(1);
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
356 }
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
357
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
358 return filename;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
359 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
360
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
361
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
362 int
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
363 TMmain(TaskManager *manager, int argc, char *argv[])
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
364 {
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
365
394
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
366 char *filename = 0;
bc2012726a51 debug word_count
e065725@localhost.localdomain
parents: 393
diff changeset
367 filename = init(argc, argv);
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
368
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
369 if (filename < 0) {
1538
fac06524090b add gpu task wordcount. But not work print
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1351
diff changeset
370 return -1;
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
371 }
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
372
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
373 task_init();
400
984e7890db0c Fix examples.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 394
diff changeset
374 run_start(manager, filename);
1544
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
375 st_time = getTime();
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
376 manager->set_TMend(TMend);
393
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
377 return 0;
cb06748ba6cf add word_count
e065725@localhost.localdomain
parents:
diff changeset
378 }
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
379
1544
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
380 void
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
381 TMend(TaskManager *manager)
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
382 {
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
383 ed_time = getTime();
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
384 printf("Time: %0.6f\n",ed_time-st_time);
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
385 }
5c4e3f0d372a many_task add task array
Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
parents: 1542
diff changeset
386
946
852ed17d8af1 unify word count examples....
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 797
diff changeset
387 /* end */