# HG changeset patch # User Shinji KONO # Date 1259773891 -32400 # Node ID 4615489c5faa3d91e7af5c0f291faaefe9885136 # Parent 4470ff271c5afe86488cde73b2ada3ca7d0ee53b simplify word_count diff -r 4470ff271c5a -r 4615489c5faa TaskManager/Cell/spe/CellScheduler.cc --- a/TaskManager/Cell/spe/CellScheduler.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/TaskManager/Cell/spe/CellScheduler.cc Thu Dec 03 02:11:31 2009 +0900 @@ -1,5 +1,4 @@ #include -#include #include "CellScheduler.h" #include "CellDmaManager.h" #include "error.h" diff -r 4470ff271c5a -r 4615489c5faa TaskManager/kernel/ppe/TaskManagerImpl.h --- a/TaskManager/kernel/ppe/TaskManagerImpl.h Thu Dec 03 01:16:34 2009 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Thu Dec 03 02:11:31 2009 +0900 @@ -51,26 +51,28 @@ void* allocate(int size, int alignment) { + void *buff; if (size==0) return 0; - #if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) - return malloc(size); - #else - void *buff; +#if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) + buff = malloc(size); +#else posix_memalign(&buff, alignment, size); +#endif + if (buff==0) fprintf(stderr,"Can't allocate memory\n"); return buff; - #endif } void* allocate(int size) { + void *buff; if (size==0) return 0; - #if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) - return malloc(size); - #else - void *buff; +#if defined(__SPU__) || ! defined(HAS_POSIX_MEMALIGN) + buff = malloc(size); +#else posix_memalign(&buff, DEFAULT_ALIGNMENT, size); +#endif + if (buff==0) fprintf(stderr,"Can't allocate memory\n"); return buff; - #endif } Scheduler* get_scheduler() { return scheduler; } diff -r 4470ff271c5a -r 4615489c5faa example/word_count/ppe/Exec.cc --- a/example/word_count/ppe/Exec.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count/ppe/Exec.cc Thu Dec 03 02:11:31 2009 +0900 @@ -12,26 +12,14 @@ char *i_data = (char*)s->get_input(rbuf, 0); unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); long length = (long)s->get_param(0); - long word_flag = (long)s->get_param(1); + long word_flag = 1-(long)s->get_param(1); int word_num = 0; int line_num = 0; - int i; + int i ; - /*先頭の文字まで、飛ぶルーチン*/ - for(i = 0; i < length; i++) { - if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { - //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); - break; - } - //s->printf("[SPE%d]%c",id,i_data[start_num]); - word_num += word_flag; - word_flag = 0; - line_num += (i_data[i] == 0x0A); - } + word_num -= word_flag; - word_flag = 0; - - for (; i < length; i++) { + for (i=0; i < length; i++) { //s->printf("[SPE%d]%c",id,i_data[i]); diff -r 4470ff271c5a -r 4615489c5faa example/word_count/ppe/Print.cc --- a/example/word_count/ppe/Print.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count/ppe/Print.cc Thu Dec 03 02:11:31 2009 +0900 @@ -26,8 +26,8 @@ } } - for (int i = 0; i < status_num; i++) { - s->printf("%llu ",word_data[i]); + for (int i = status_num; i > 0; i--) { + s->printf("%llu ",word_data[i-1]); } s->printf("\n"); diff -r 4470ff271c5a -r 4615489c5faa example/word_count/spe/Exec.cc --- a/example/word_count/spe/Exec.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count/spe/Exec.cc Thu Dec 03 02:11:31 2009 +0900 @@ -6,66 +6,45 @@ /* これは必須 */ SchedDefineTask(Exec); -// typedef char *cvector __attribute__ ((vector_size (16))); -typedef char *cvector; - static int run(SchedTask *s, void *rbuf, void *wbuf) { - cvector i_data ; - i_data = (cvector)s->get_input(rbuf, 0); + char *i_data = (char*)s->get_input(rbuf, 0); unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); - int length = (long)s->get_param(0); - int word_flag = (long)s->get_param(1); + long length = (long)s->get_param(0); + long word_flag = 1-(long)s->get_param(1); int word_num = 0; int line_num = 0; - int i; - static char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; - cvector space = (cvector)spaces; - static char newlines []= {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; - cvector newline = (cvector)newlines; - + int i ; - /*先頭の文字まで、飛ぶルーチン*/ - for(i = 0; i < length; i++) { - if ((i_data[i] != space[i%16]) && (i_data[i] != newline[i%16])) { - //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); - break; - } - //s->printf("[SPE%d]%c",id,i_data[start_num]); - word_num += word_flag; - word_flag = 0; - line_num += (i_data[i] == newline[i%16]); - } + word_num -= word_flag; - word_flag = 0; - - for (; i < length; i++) { + for (i=0; i < length; i++) { //s->printf("[SPE%d]%c",id,i_data[i]); + if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { + //s->printf("文字 数 = %d\n", word_num + word_flag); + word_num += word_flag; + word_flag = 0; + } - if (i_data[i] == space[i%16]) { - //s->printf("スペース\n"); + if (i_data[i] == 0x20) { + //printf("スペース\n"); word_flag = 1; } - else if (i_data[i] == newline[i%16]) { - //s->printf("改行\n"); + if (i_data[i] == 0x0A) { + //printf("改行\n"); line_num += 1; word_flag = 1; } - else { - word_num += word_flag; - word_flag = 0; - } - } word_num += word_flag; - //s->printf("%d %d\n",word_num,line_num); + // printf("PPE 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; diff -r 4470ff271c5a -r 4615489c5faa example/word_count/spe/Exec.cc.vector --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count/spe/Exec.cc.vector Thu Dec 03 02:11:31 2009 +0900 @@ -0,0 +1,62 @@ +#include +#include +#include "Exec.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(Exec); + +// typedef char *cvector __attribute__ ((vector_size (16))); +typedef char *cvector; + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + cvector i_data ; + i_data = (cvector)s->get_input(rbuf, 0); + unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); + int length = (long)s->get_param(0); + int word_flag = 1-(long)s->get_param(1); + int word_num = 0; + int line_num = 0; + int i; + static char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; + cvector space = (cvector)spaces; + static char newlines []= {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; + cvector newline = (cvector)newlines; + + // word_flag ==1 not in a word + word_num -= word_flag; + + for (; i < length; i++) { + + //s->printf("[SPE%d]%c",id,i_data[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; + + //s->printf("%d %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 4470ff271c5a -r 4615489c5faa example/word_count_test/main.cc --- a/example/word_count_test/main.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count_test/main.cc Thu Dec 03 02:11:31 2009 +0900 @@ -129,6 +129,7 @@ static int blocks = 192; +static int division = 16; // in Kbyte static void run_start(TaskManager *manager, char *filename) @@ -148,10 +149,9 @@ w->file_mmap = st_mmap.file_mmap; /* 1task分のデータサイズ(byte) */ - if (w->size >= 4096*4) { - w->division_size = 4096 * 4;/*16kbyte*/ - } - else { + if (w->size >= 1024*division) { + w->division_size = 1024 * division;/*16kbyte*/ + } else { w->division_size = w->size; } @@ -209,6 +209,8 @@ 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]); } diff -r 4470ff271c5a -r 4615489c5faa example/word_count_test/ppe/Print.cc --- a/example/word_count_test/ppe/Print.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count_test/ppe/Print.cc Thu Dec 03 02:11:31 2009 +0900 @@ -78,7 +78,7 @@ word_data[0] += flag_cal_sum; - for (int i = 0; i < status_num; i++) { + for (int i = status_num-1; i >= 0; i--) { s->printf("%llu ",word_data[i]); }