# HG changeset patch # User yutaka@localhost.localdomain # Date 1274436048 -32400 # Node ID 32584e896fe7861a537e99bf1a355b79fdd6b8b9 # Parent daab9cd6f91ff76c43c22cd6950aab56cf3d07ea add word_count_run16array diff -r daab9cd6f91f -r 32584e896fe7 TaskManager/kernel/schedule/SchedTask.cc --- a/TaskManager/kernel/schedule/SchedTask.cc Fri May 21 18:31:31 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Fri May 21 19:00:48 2010 +0900 @@ -261,15 +261,10 @@ return manager->create_task(cmd,r,rs,w,ws); } -HTaskPtr -SchedTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { - return manager->create_task_array(id, num_task, num_param, num_inData, num_outData) ; -} - HTaskPtr SchedTask::create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData) { - return scheduler->create_task_array(id, num_task, num_param, num_inData, num_outData); + return manager->create_task_array(id, num_task, num_param, num_inData, num_outData); } diff -r daab9cd6f91f -r 32584e896fe7 TaskManager/kernel/schedule/SchedTask.h --- a/TaskManager/kernel/schedule/SchedTask.h Fri May 21 18:31:31 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Fri May 21 19:00:48 2010 +0900 @@ -94,7 +94,7 @@ // user HTaskPtr create_task(int cmd); HTaskPtr create_task(int cmd, memaddr r, long rs, memaddr w, long ws); - HTask *create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData); + HTaskPtr create_task_array(int id, int num_task, int num_param, int num_inData, int num_outData); void set_task_depend(HTaskPtr master, HTaskPtr slave); void spawn_task(HTaskPtr); diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Func.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Func.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,12 @@ +enum { +#include "SysTasks.h" + TASK_EXEC, + RUN_TASK_BLOCKS, + TASK_PRINT, + RUN_FINISH, +}; + +#define DATA_NUM 12 +#define ADD_NUM 26 + +#define DATA_ID 0 diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Makefile Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,20 @@ +default: macosx + +macosx: FORCE + @echo "Make for Mac OS X" + @$(MAKE) -f Makefile.macosx + +linux: FORCE + @echo "Make for Linux" + @$(MAKE) -f Makefile.linux + +cell: FORCE + @echo "Make for CELL (Cell)" + @$(MAKE) -f Makefile.cell + +FORCE: + +clean: + @$(MAKE) -f Makefile.macosx clean + @$(MAKE) -f Makefile.linux clean + @$(MAKE) -f Makefile.cell clean \ No newline at end of file diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Makefile.cell --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Makefile.cell Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,39 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lCellManager -lspe2 -lpthread -Wl,--gc-sections + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) speobject + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +speobject: + cd spe; $(MAKE) + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo ppu-gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + cd spe; $(MAKE) clean diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Makefile.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Makefile.def Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,18 @@ +TARGET = word_count + +# include/library path +# ex macosx +#CERIUM = /Users/gongo/Source/Cerium + +# ex linux/ps3 +CERIUM = ../../../Cerium + + +OPT = -O9 +#OPT = -g + +CC = g++ +CFLAGS = -Wall $(OPT) + +INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L${CERIUM}/TaskManager diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Makefile.linux --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Makefile.linux Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,36 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lFifoManager + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + rm -f spe/*~ spe/\#* diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/Makefile.macosx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/Makefile.macosx Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,37 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +LIBS += -lFifoManager `sdl-config --libs` +CC += -m32 + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +link: + $(CC) -o $(TARGET) $(OBJS) $(TASK_OBJS) $(LIBS) + +debug: $(TARGET) + sudo gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f ppe/*~ ppe/\#* + rm -f spe/*~ spe/\#* diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/README Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,59 @@ +/* + * $Id: README,v 1.3 2008/10/20 08:49:52 gongo Exp $ + */ + +- 概要 +Task の依存関係を設定する例題 + +タスクは二種類あって + +配列 idata があるとする (サイズは length*2) + +Exec: idata を length の前後に分けて受け取り、各要素に値を加算 + 半分に分けるため、今回はこのタスクを 2 つに固定。 + まあ3つ以上でもいいんだけどね。 + +Print: idata を表示する。 + + +依存関係としては、まずは Exec を先に実行しないといけないので + +------------> 時間 + +Exec 1 + \ + Print + / +Exec 2 + + +みたいな感じ。 +この依存を設定しないと、Print は Exec1,2 が計算する前の +idata を詠んでしまう可能性がある。 + + +- 実行方法 + +% ./dependency [-cpu spe_num] [-nodepend] + + -cpu SPU の数 + -nodepend Exec と Print に依存を設定しない + + +- 実行例 + +%./dependency +[TASK_PRINT] +13 13 13 13 13 13 13 13 13 13 13 13 26 26 26 26 26 26 26 26 26 26 26 26 + +%./dependency -nodepend +[TASK_PRINT] + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + +上の場合、Exec 1, 2 の処理結果が PPE の idata に書き込まれる前に +Print が idata から DMA でデータを取ってきて表示しているために +全て 0 になっている。 +このタスクが全て同じ SPE 上で実行されているとして、 +Exec 1, 2 のあと、Print の DMA read が実行される前に +Exec 1, 2 の DMA write が済んでいればもしかしたらデータが取れるかもしれない。 +しかし「もしかしたら」では使いものにならないので、依存を設定するわけです。 \ No newline at end of file diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/WordCount.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/WordCount.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,19 @@ + +typedef struct wordCount { + struct wordCount *self; + int size; // remaining file size + int division_size; // for each word count task + int division_out_size; + int out_size; + int task_num; // remaining task count + int task_blocks; // spawn task one at a time + int status_num; + int task_spwaned; + unsigned long long *o_data; + unsigned long long *head_tail_flag; + int out_task_num; + int pad; + char * file_mmap; + HTaskPtr t_print; +} WordCount; + diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/main.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,243 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "TaskManager.h" +#include "SchedTask.h" +#include "Func.h" +#include "WordCount.h" + +extern void task_init(); + +const char *usr_help_str = "Usage: ./word_count [-cpu spe_num] [-file filename]\n"; + +typedef struct { + caddr_t file_mmap; + off_t size; +} st_mmap_t; + + + +/*筝sizefix_byte_size違(筝吾莨若c鐚)*/ +static int +fix_byte(int size,int fix_byte_size) +{ + size = (size/fix_byte_size)*fix_byte_size + ((size%fix_byte_size)!= 0)*fix_byte_size; + + return size; +} + + +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) +{ + + int array_task_num = 8; + if (task_count < array_task_num) { + array_task_num = task_count; + } + + for (int i = 0; i < task_count; i += array_task_num) { + + HTask *task_array = manager->create_task_array(TASK_EXEC,array_task_num,0,1,1); + t_next->wait_for(task_array); + + Task *t_exec = 0; + for (int j = 0; j < array_task_num; j++) { + int i = w->task_spwaned++; + + t_exec = task_array->next_task_array(TASK_EXEC,t_exec); + t_exec->set_inData(0,w->file_mmap + i*w->division_size, size); + t_exec->set_outData(0,w->o_data + i*w->out_size, w->division_out_size); + t_exec->set_param(0,size); + + w->size -= size; + w->task_num--; + } + + task_array->spawn_task_array(t_exec->next()); + task_array->set_cpu(SPE_ANY); + task_array->spawn(); + } +} + +SchedDefineTask1(RUN_TASK_BLOCKS,run16); + +static int +run16(SchedTask *manager, void *in, void *out) +{ + WordCount *w = *(WordCount **)in; + + if (w->task_num < w->task_blocks) { + if (w->size >= w->division_size) + run_tasks(manager,w,w->task_num, w->t_print, w->division_size); + while (w->size>0) + run_tasks(manager,w,1, w->t_print, w->size); + // printf("run16 last %d\n",w->task_num); + } else { + HTaskPtr t_next = manager->create_task(RUN_TASK_BLOCKS, + (memaddr)&w->self,sizeof(memaddr),0,0); + w->t_print->wait_for(t_next); + + run_tasks(manager,w, w->task_blocks, t_next, w->division_size); + + t_next->spawn(); + // printf("run16 next %d\n",w->task_num); + } + return 0; +} + + +static int blocks = 48; +static int division = 16; // in Kbyte +static int profile = 0; + +static void +run_start(TaskManager *manager, char *filename) +{ + HTaskPtr t_print; + + st_mmap_t st_mmap; + st_mmap = my_mmap(filename); + WordCount *w = (WordCount*)manager->allocate(sizeof(WordCount)); + // bzero(w,sizeof(WordCount)); + + w->self = w; + w->task_blocks = blocks; + w->task_spwaned = 0; + + /*sizedivision_size違*/ + w->size = st_mmap.size; + w->file_mmap = st_mmap.file_mmap; + + /* 1task若帥泣ゃ(byte) */ + if (w->size >= 1024*division) { + w->division_size = 1024 * division;/*16kbyte*/ + } else { + w->division_size = w->size; + } + + printf("dvision_size %d\n",w->division_size); + + /* "word num" and "line num" */ + w->status_num = 2; + /* task */ + w->task_num = w->size / w->division_size; + w->task_num = w->task_num + (w->division_size*w->task_num < w->size); + int out_task_num = w->task_num; + + w->out_task_num = out_task_num; + printf("task_num %d\n",w->task_num); + printf("out_task_num %d\n",w->out_task_num); + + /* outdivision_size. status2ゃс16bytelong long(8byte)篏睡 */ + + w->division_out_size = sizeof(unsigned long long)*4; + int out_size = w->division_out_size*out_task_num; + w->o_data = (unsigned long long *)manager->allocate(out_size); + w->out_size = 4; + printf("out size %d\n",out_size); + + /*SPE腟荐阪帥鴻*/ + + t_print = manager->create_task(TASK_PRINT, + (memaddr)&w->self,sizeof(memaddr),0,0); + + w->t_print = t_print; + + for(int i = 0;i<1;i++) { + /* Task task_blocks よ儀 Task */ + /* serialize 篁絎... */ + HTaskPtr t_exec = manager->create_task(RUN_TASK_BLOCKS, + (memaddr)&w->self,sizeof(memaddr),0,0); + t_print->wait_for(t_exec); + t_exec->spawn(); + } + + t_print->spawn(); +} + +static char* +init(int argc, char **argv) +{ + + char *filename = 0; + + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-file") == 0) { + filename = argv[i+1]; + } else if (strcmp(argv[i], "-division") == 0) { + division = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-block") == 0) { + blocks = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-p") == 0) { + profile = 1; + } + } + if (filename==0) { + printf("usage: %s [-block 10] -file filename\n",argv[0]); + exit(1); + } + + return filename; +} + + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + + char *filename = 0; + filename = init(argc, argv); + + if (filename < 0) { + return -1; + } + + task_init(); + run_start(manager, filename); + + return 0; +} + +/* end */ diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/Exec.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/Exec.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,45 @@ +#include +#include +#include "Exec.h" +#include "Func.h" + +/* 綽 */ +SchedDefineTask(Exec); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + char *i_data = (char *)rbuf; + unsigned long long *o_data = (unsigned long long*)wbuf; + unsigned long long *head_tail_flag = o_data +2; + int length = (int)s->get_param(0); + int word_flag = 0; + int word_num = 0; + int line_num = 0; + int i = 0; + + head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); + word_num -= 1-head_tail_flag[0]; + + for (; i < length; i++) { + if (i_data[i] == 0x20) { + word_flag = 1; + } else if (i_data[i] == 0x0A) { + line_num += 1; + word_flag = 1; + } else { + word_num += word_flag; + word_flag = 0; + } + } + + word_num += word_flag; + head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); + + // s->printf("SPE word %d line %d\n",word_num,line_num); + + o_data[0] = (unsigned long long)word_num; + o_data[1] = (unsigned long long)line_num; + + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/Exec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/Exec.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/Print.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/Print.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,92 @@ +#include +#include +#include "Print.h" +#include "Func.h" +#include "WordCount.h" + +/* 綽 */ +SchedDefineTask1(Print,run_print); + +static int +run_print(SchedTask *s, void *rbuf, void *wbuf) +{ + WordCount *w = *(WordCount**)rbuf; + unsigned long long *idata = w->o_data; + // long task_num = w->task_num; + long status_num = w->status_num; + int out_task_num = w->out_task_num; + + /* + * head_flag + * o_data[0] + * o_data[1] + * + */ + unsigned long long word_data[2]; + + int flag_cal_sum = 0; + //printf("pad %d\n",pad); + + + /* head_tail_flag : task = 2 : 1 + * + * head_tail_flag[2] + * ___________ __________ + * | | | + * | head_flag | tail_fag | + * |___________|__________| + * [0] [1] + * + * |----------------------| + * unsigned long long + * 16byte + * + * head_flag 帥 + * 絨障 tail_flag 帥 + * 綵膀峨絨丈絖壕鴻若剛札紊(tail_flag = 1)с + * 綵膀蚊絖壕鴻若鴻(head_flag = 0)翫 + * 茯違 +1 с翫с + * + * ex. + * task_num 4 + * head_tail_flag[8] + * + * 0 1 2 3 4 5 6 7 + * ___ ___ ___ ___ ___ ___ ___ ___ + * | h | t | h | t | h | t | h | t | + * |___|___|___|___|___|___|___|___| + * |-------|-------|-------| + * 罸莠 罸莠 罸莠 + * + */ + + s->printf("start sum\n"); + + for (int i = 0; i < status_num; i++) { + word_data[i] = 0; + } + + for (int i = 0; i < out_task_num ; i++) { + word_data[0] += idata[i*w->out_size+0]; + word_data[1] += idata[i*w->out_size+1]; + unsigned long long *head_tail_flag = + &idata[i*w->out_size+2]; + if((i!=out_task_num-1)&& + (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) { + flag_cal_sum++; + } + } + + word_data[0] += flag_cal_sum; + + for (int i = status_num-1; i >=0; i--) { + s->printf("%llu ",word_data[i]); + } + + //printf("j = %d\n",j); + + + s->printf("\n"); + + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/Print.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/Print.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_PRINT +#define INCLUDED_TASK_PRINT + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/RunFinish.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/RunFinish.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,10 @@ +#include "RunFinish.h" + +/* 綽 */ +SchedDefineTask(RunFinish); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/RunFinish.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/RunFinish.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_RUNFINISH +#define INCLUDED_TASK_RUNFINISH + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/ppe/task_init.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/ppe/task_init.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,22 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 綽篏臀吾 */ +SchedExternTask(Print); +SchedExternTask(Exec); +SchedExternTask(RUN_TASK_BLOCKS); +SchedExternTask(RunFinish); + +/** + * ∽違 ../spe/spe-main c + * у若喝冴違∽違 + * 絅純∽医сk (SchedRegisterTask 綽) + */ +void +task_init(void) +{ + SchedRegisterTask(TASK_PRINT, Print); + SchedRegisterTask(TASK_EXEC, Exec); + SchedRegister(RUN_TASK_BLOCKS); + SchedRegisterTask(RUN_FINISH, RunFinish); +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Exec.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Exec.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,45 @@ +#include +#include +#include "Exec.h" +#include "Func.h" + +/* 綽 */ +SchedDefineTask(Exec); + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + char *i_data = (char *)rbuf; + unsigned long long *o_data = (unsigned long long*)wbuf; + unsigned long long *head_tail_flag = o_data +2; + int length = (int)s->get_param(0); + int word_flag = 0; + int word_num = 0; + int line_num = 0; + int i = 0; + + head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); + word_num -= 1-head_tail_flag[0]; + + for (; i < length; i++) { + if (i_data[i] == 0x20) { + word_flag = 1; + } else if (i_data[i] == 0x0A) { + line_num += 1; + word_flag = 1; + } else { + word_num += word_flag; + word_flag = 0; + } + } + + word_num += word_flag; + head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); + + // s->printf("SPE word %d line %d\n",word_num,line_num); + + o_data[0] = (unsigned long long)word_num; + o_data[1] = (unsigned long long)line_num; + + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Exec.cc.vector --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Exec.cc.vector Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,73 @@ +#include +#include +#include "Exec.h" +#include "Func.h" + +/* 綽 */ +SchedDefineTask(Exec); + +typedef char *cvector __attribute__ ((vector_size (16))); +// vectorize 腟... +// +// typedef char *cvector; + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ +#ifdef SIMPLE_TASK + cvector i_data = (cvector)rbuf; + char* i_data0 = (char*)rbuf; + unsigned long long *o_data = (unsigned long long*)wbuf; + unsigned long long *head_tail_flag = o_data +2; + int length = s->read_size(); +#else + cvector i_data = (cvector)s->get_input(rbuf, 0); + char* i_data0 = (char*)s->get_input(rbuf, 0); + unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); + /*綵膀蚊絨障壕鴻若鴻篁ュ絖*/ + unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); + int length = (long)s->get_param(0); +#endif + + static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ; + cvector const space = (cvector)spaces; + static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; + cvector const newline = (cvector)newlines; + + int word_flag = 0; + int word_num = 0; + int line_num = 0; + int i = 0; + + /*絖1,鴻若鴻壕0*/ + char top = i_data0[0]; + head_tail_flag[0] = ((top != 0x20) && (top != 0x0a)); + word_num -= 1-head_tail_flag[0]; + + for (; i < length; i++) { + if (i_data[i] == space[i%16]) { + //s->printf("鴻若\n"); + word_flag = 1; + } else if (i_data[i] == newline[i%16]) { + //s->printf("壕\n"); + line_num += 1; + word_flag = 1; + } else { + word_num += word_flag; + word_flag = 0; + } + } + + word_num += word_flag; + /*絖1,鴻若鴻壕0*/ + //printf("last word %c",i_data[i-1]); + char end = i_data0[i-1]; + head_tail_flag[1] = ((end != 0x20) && (end != 0x0a)); + + // s->printf("SPU word %d line %d\n",word_num,line_num); + + o_data[0] = (unsigned long long)word_num; + o_data[1] = (unsigned long long)line_num; + + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Exec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Exec.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Makefile Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,26 @@ +include ../Makefile.def + +TARGET = ../spe-main + +SRCS_TMP = $(wildcard *.cc) +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +CC = spu-g++ +CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT) +INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L../${CERIUM}/TaskManager -lspemanager + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +clean: + rm -f $(TARGET) $(OBJS) + rm -f *~ \#* diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Print.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Print.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,92 @@ +#include +#include +#include "Print.h" +#include "Func.h" +#include "WordCount.h" + +/* 綽 */ +SchedDefineTask1(Print,run_print); + +static int +run_print(SchedTask *s, void *rbuf, void *wbuf) +{ + WordCount *w = *(WordCount**)rbuf; + unsigned long long *idata = w->o_data; + // long task_num = w->task_num; + long status_num = w->status_num; + int out_task_num = w->out_task_num; + + /* + * head_flag + * o_data[0] + * o_data[1] + * + */ + unsigned long long word_data[2]; + + int flag_cal_sum = 0; + //printf("pad %d\n",pad); + + + /* head_tail_flag : task = 2 : 1 + * + * head_tail_flag[2] + * ___________ __________ + * | | | + * | head_flag | tail_fag | + * |___________|__________| + * [0] [1] + * + * |----------------------| + * unsigned long long + * 16byte + * + * head_flag 帥 + * 絨障 tail_flag 帥 + * 綵膀峨絨丈絖壕鴻若剛札紊(tail_flag = 1)с + * 綵膀蚊絖壕鴻若鴻(head_flag = 0)翫 + * 茯違 +1 с翫с + * + * ex. + * task_num 4 + * head_tail_flag[8] + * + * 0 1 2 3 4 5 6 7 + * ___ ___ ___ ___ ___ ___ ___ ___ + * | h | t | h | t | h | t | h | t | + * |___|___|___|___|___|___|___|___| + * |-------|-------|-------| + * 罸莠 罸莠 罸莠 + * + */ + + s->printf("start sum\n"); + + for (int i = 0; i < status_num; i++) { + word_data[i] = 0; + } + + for (int i = 0; i < out_task_num ; i++) { + word_data[0] += idata[i*w->out_size+0]; + word_data[1] += idata[i*w->out_size+1]; + unsigned long long *head_tail_flag = + &idata[i*w->out_size+2]; + if((i!=out_task_num-1)&& + (head_tail_flag[1] == 1) && (head_tail_flag[4] == 0)) { + flag_cal_sum++; + } + } + + word_data[0] += flag_cal_sum; + + for (int i = status_num-1; i >=0; i--) { + s->printf("%llu ",word_data[i]); + } + + //printf("j = %d\n",j); + + + s->printf("\n"); + + return 0; +} diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/Print.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/Print.h Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_PRINT +#define INCLUDED_TASK_PRINT + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif diff -r daab9cd6f91f -r 32584e896fe7 example/word_count_run16array/spe/spe-main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_run16array/spe/spe-main.cc Fri May 21 19:00:48 2010 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "SchedTask.h" + +SchedExternTask(Print); +SchedExternTask(Exec); + +/** + * ∽違 SpeScheduler 若違 + * 綽∽医с蕁障 + */ +void +task_init(Scheduler *s) +{ + SchedRegisterTask(TASK_PRINT, Print); + SchedRegisterTask(TASK_EXEC, Exec); +}