Mercurial > hg > Game > Cerium
changeset 1910:b7b528e9ec5e draft
Implement divide read in word_count ( but cannot running )
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 19 Jan 2014 22:54:01 +0900 |
parents | c228dbede5df |
children | f842ea419307 |
files | example/fileread/FileRead.h example/word_count/Func.h example/word_count/WordCount.h example/word_count/main.cc example/word_count/task_init.cc |
diffstat | 5 files changed, 171 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/example/fileread/FileRead.h Sun Jan 19 21:39:52 2014 +0900 +++ b/example/fileread/FileRead.h Sun Jan 19 22:54:01 2014 +0900 @@ -1,15 +1,15 @@ typedef struct fileRead { - struct fileRead *self; - long fd; - long division_size; - long task_number; - long task_num; - long left_task_num; - long filesize; - long left_size; - int task_blocks; - char *read_text; - CPU_TYPE cpu; - HTaskPtr t_print; + struct fileRead *self; + long fd; + long division_size; + long task_number; + long task_num; + long left_task_num; + long filesize; + long left_size; + int task_blocks; + char *read_text; + CPU_TYPE cpu; + HTaskPtr t_print; } FileRead, *FileReadPtr;
--- a/example/word_count/Func.h Sun Jan 19 21:39:52 2014 +0900 +++ b/example/word_count/Func.h Sun Jan 19 22:54:01 2014 +0900 @@ -1,5 +1,8 @@ enum { #include "SysTasks.h" + Read_task, + RUN_READ_BLOCKS, + MMAP, TASK_EXEC, TASK_EXEC_DATA_PARALLEL, RUN_TASK_BLOCKS,
--- a/example/word_count/WordCount.h Sun Jan 19 21:39:52 2014 +0900 +++ b/example/word_count/WordCount.h Sun Jan 19 22:54:01 2014 +0900 @@ -1,6 +1,17 @@ typedef struct wordCount { struct wordCount *self; + int fd; + int read_division_size; + int read_task_number; + int read_task_num; + int read_left_task_num; + int read_filesize; + int read_left_size; + int read_task_blocks; + char *read_text; + CPU_TYPE read_cpu; + int size; // remaining file size int division_size; // for each word count task int division_out_size; @@ -17,5 +28,5 @@ char * file_mmap; int file_size; HTaskPtr t_print; -} WordCount; +} WordCount, *WordCountPtr;
--- a/example/word_count/main.cc Sun Jan 19 21:39:52 2014 +0900 +++ b/example/word_count/main.cc Sun Jan 19 22:54:01 2014 +0900 @@ -28,6 +28,8 @@ int use_iterate_all = 0; int array_task_num = 8; int spe_num = 1; +int divide_read_flag = 0; +int READ_DIVISION_SIZE = 16 * 1024; CPU_TYPE spe_cpu = SPE_ANY; const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename]\n"; @@ -53,41 +55,111 @@ } -static st_mmap_t -my_mmap(char *filename) -{ +SchedDefineTask1(RUN_READ_BLOCKS,read_run); + +static int +read_run(SchedTask *manager, void *in, void *out) { + + WordCountPtr w = (WordCountPtr)in; + char* read_text = (char*)out; + HTaskPtr wait; + + for (int i = 0; (w->read_left_size > 0) && (i < w->read_task_blocks); i++) { + HTaskPtr read = manager->create_task(Read_task); + read->set_cpu(w->read_cpu); + + if (i == w->read_task_blocks / 2) wait = read; - /*マッピングだよ!*/ - int fd = -1; - int map = MAP_PRIVATE; - st_mmap_t st_mmap; - struct stat sb; + read->set_param(0,(long)w->read_task_number); //生成するTaskが何番目か + read->set_param(1,(long)w->read_division_size); //1つのタスクが読み込む量 + if(w->read_left_size <= w->read_division_size){ + read->set_param(2,(long)w->read_left_size); + }else{ + read->set_param(2,(long)w->read_division_size); + } + read->set_param(3,(long)w->fd); //fdの番号の受け渡し - if ((fd=open(filename,O_RDONLY,0666))==0) { - fprintf(stderr,"can't open %s\n",filename); + read->set_outData(0,read_text + w->read_task_number*w->read_division_size, w->read_division_size); + + w->t_print->wait_for(read); + read->spawn(); + + w->read_left_size -= w->read_division_size; + w->read_task_number++; } - if (fstat(fd,&sb)) { - fprintf(stderr,"can't fstat %s\n",filename); + if (w->read_left_size > 0) { + + HTaskPtr next = manager->create_task(RUN_READ_BLOCKS, (memaddr)&w->self, sizeof(memaddr),read_text,w->read_filesize); + + w->t_print->wait_for(next); + next->wait_for(wait); + next->spawn(); } + return 0; +} - printf("file size %d\n",(int)sb.st_size); +SchedDefineTask1(MMAP,my_mmap); - /*sizeをページングサイズの倍数にあわせる*/ - st_mmap.size = fix_byte(sb.st_size,4096); +static int +my_mmap(SchedTask *s, void *in, void *out) +{ + + WordCountPtr w = (WordCountPtr)in; + /*マッピングだよ!*/ - printf("fix 4096byte file size %d\n",(int)st_mmap.size); - - st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); + int map = MAP_PRIVATE; + st_mmap_t st_mmap; + + int fd = w->fd; + st_mmap.size = w->read_filesize; + w->file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); if (st_mmap.file_mmap == (caddr_t)-1) { fprintf(stderr,"Can't mmap file\n"); + perror(NULL); exit(0); } - return st_mmap; + printf("in mmap mode\n"); + return 0; +} -} +//static st_mmap_t +//my_mmap(char *filename) +//{ +// +// /*マッピングだよ!*/ +// int fd = -1; +// int map = MAP_PRIVATE; +// st_mmap_t st_mmap; +// struct stat sb; +// +// if ((fd=open(filename,O_RDONLY,0666))==0) { +// fprintf(stderr,"can't open %s\n",filename); +// } +// +// if (fstat(fd,&sb)) { +// fprintf(stderr,"can't fstat %s\n",filename); +// } +// +// printf("file size %d\n",(int)sb.st_size); +// +// /*sizeをページングサイズの倍数にあわせる*/ +// st_mmap.size = fix_byte(sb.st_size,4096); +// +// printf("fix 4096byte file size %d\n",(int)st_mmap.size); +// +// st_mmap.file_mmap = (char*)mmap(NULL,st_mmap.size,PROT_READ,map,fd,(off_t)0); +// if (st_mmap.file_mmap == (caddr_t)-1) { +// fprintf(stderr,"Can't mmap file\n"); +// perror(NULL); +// exit(0); +// } +// +// return st_mmap; +// +//} static void run_tasks(SchedTask *manager, WordCount *w, int task_count, HTaskPtr t_next, int size) @@ -239,11 +311,53 @@ static void run_start(TaskManager *manager, char *filename) { + + long fd = (long)manager->allocate(sizeof(long)); + struct stat *sb = (struct stat*)manager->allocate(sizeof(struct stat)); + + if ((fd=open(filename,O_RDONLY,0666))==0) { + fprintf(stderr,"can't open %s\n",filename); + } + + if (fstat(fd,sb)) { + fprintf(stderr,"can't fstat %s\n",filename); + } + + //WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); + WordCountPtr w = (WordCountPtr)manager->allocate(sizeof(WordCount)); + + w->self = w; + w->fd = fd; + w->read_cpu = spe_cpu; + w->read_task_blocks = 16; + w->read_filesize = sb->st_size; + w->read_left_size = w->read_filesize; + w->read_division_size = READ_DIVISION_SIZE; + w->read_task_num = w->read_filesize / READ_DIVISION_SIZE; + w->read_task_num += ((w->read_filesize % READ_DIVISION_SIZE) != 0); + + printf("filesize : %d\n",w->read_filesize); + printf("one_task_size: %d\n",w->read_division_size); + printf("task_num : %d\n",w->read_task_num); + + HTaskPtr run = NULL; + + if (divide_read_flag != 0) { + char *read_text = (char*)manager->allocate(w->read_filesize); + run = manager->create_task(RUN_READ_BLOCKS, (memaddr)&w->self, sizeof(memaddr),read_text,w->read_filesize); + w->read_text = read_text; + }else { + //my_mmap(filename, fd, fr); + run = manager->create_task(MMAP , (memaddr)&w->self, sizeof(memaddr),0,0); + } + + run->spawn(); + + /* original */ HTaskPtr t_print; st_mmap_t st_mmap; - st_mmap = my_mmap(filename); - WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); + //st_mmap = my_mmap(filename); // bzero(w,sizeof(WordCount)); //w->task_blocks = blocks; @@ -349,6 +463,8 @@ use_iterate_all = 1; use_iterate = 1; use_task_array = 0; + } else if (strcmp(argv[i], "-dr") == 0) { + divide_read_flag = 1; } /* else if (strcmp(argv[i], "-cpu") == 0) { spe_num = atoi(argv[i+1]); i++;
--- a/example/word_count/task_init.cc Sun Jan 19 21:39:52 2014 +0900 +++ b/example/word_count/task_init.cc Sun Jan 19 22:54:01 2014 +0900 @@ -5,6 +5,9 @@ #endif /* 必ずこの位置に書いて */ +SchedExternTask(Read_task); +SchedExternTask(RUN_READ_BLOCKS); +SchedExternTask(MMAP); SchedExternTask(Exec); SchedExternTask(Exec_Data_Parallel); SchedExternTask(Print); @@ -22,6 +25,9 @@ GpuSchedRegister(TASK_EXEC, "gpu/Exec.cl", "wordcount"); GpuSchedRegister(TASK_EXEC_DATA_PARALLEL, "gpu/Exec_Data_Parallel.cl","wordcount_parallel"); #endif + SchedRegister(Read_task); + SchedRegister(RUN_READ_BLOCKS); + SchedRegister(MMAP); SchedRegisterTask(TASK_EXEC, Exec); SchedRegisterTask(TASK_EXEC_DATA_PARALLEL, Exec_Data_Parallel);