Mercurial > hg > Game > Cerium
changeset 1099:3b3b535baa51 draft
add resize wbuff example.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 31 Dec 2010 15:58:32 +0900 |
parents | 3e1caef39798 |
children | dcb025b46cae |
files | TaskManager/kernel/schedule/SchedTask.cc TaskManager/kernel/schedule/SchedTask.h TaskManager/kernel/schedule/SchedTaskArray.cc TaskManager/kernel/schedule/SchedTaskArray.h example/ResizeWritebuf/Func.h example/ResizeWritebuf/Makefile example/ResizeWritebuf/Makefile.cell example/ResizeWritebuf/Makefile.def example/ResizeWritebuf/Makefile.linux example/ResizeWritebuf/Makefile.macosx example/ResizeWritebuf/main.cc example/ResizeWritebuf/ppe/Resize.cc example/ResizeWritebuf/ppe/Resize.h example/ResizeWritebuf/ppe/task_init.cc example/ResizeWritebuf/spe/Makefile example/ResizeWritebuf/spe/Resize.cc example/ResizeWritebuf/spe/Resize.h example/ResizeWritebuf/spe/spe-main.cc |
diffstat | 18 files changed, 484 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/kernel/schedule/SchedTask.cc Thu Dec 23 11:21:52 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.cc Fri Dec 31 15:58:32 2010 +0900 @@ -79,6 +79,11 @@ } +void +SchedTask::setup_outputData() +{ + writebuf = manager->allocate(task->w_size); +} void SchedTask::exec() @@ -86,7 +91,7 @@ task_list[task->command].wait(scheduler,task->command); TaskObjectRun run = task_list[task->command].run; if (task->w_size > 0) { - writebuf = manager->allocate(task->w_size); + setup_outputData(); } scheduler->dma_wait(DMA_READ + this->tag); run(this, readbuf, writebuf); @@ -181,6 +186,7 @@ void* SchedTask::get_output(void *buff, int index) {return writebuf; } memaddr SchedTask::get_outputAddr(int index) { return task->wbuf; } int SchedTask::get_outputSize(int index) { return task->w_size; } +void SchedTask::set_outputSize(int index, int size){task->w_size = size;} memaddr SchedTask::get_param(int index) { return task->param; }
--- a/TaskManager/kernel/schedule/SchedTask.h Thu Dec 23 11:21:52 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTask.h Fri Dec 31 15:58:32 2010 +0900 @@ -39,6 +39,7 @@ int read_size() { return task->r_size; } int write_size() { return task->w_size; } void set_write_size(int w) { task->w_size = w; } + void setup_outputData(); void* get_input(void *buff, int index); void* get_output(void *buff, int index); @@ -49,6 +50,8 @@ int get_inputSize(int index); int get_outputSize(int index); + void set_outputSize(int index, int size); + int get_cpuid(); void* global_alloc(int id, int size);
--- a/TaskManager/kernel/schedule/SchedTaskArray.cc Thu Dec 23 11:21:52 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.cc Fri Dec 31 15:58:32 2010 +0900 @@ -107,6 +107,23 @@ } +void +SchedTaskArray::setup_outputData() +{ + // allocate write buffer + outListData.length = atask->outData_count; + outListData.size = atask->outData_total_size(); + // atask->outData_offset += cur_index + 1 ; // to avoid compiler bug + outListData.element = atask->outData(0); + outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); + bound(&outListData); + + writebuf = manager->allocate(outListData.size); + //if (outListData.element == inListData.element ) { + // printf("bad %x\n",outListData.element); + //} +} + /** * Wait read data and execute task * Start write DMA @@ -117,18 +134,7 @@ task_list[atask->command].wait(scheduler,atask->command); TaskObjectRun run = task_list[atask->command].run; if (atask->outData_count > 0) { - // allocate write buffer - outListData.length = atask->outData_count; - outListData.size = atask->outData_total_size(); - // atask->outData_offset += cur_index + 1 ; // to avoid compiler bug - outListData.element = atask->outData(0); - outListData.bound = (int*)manager->allocate(outListData.length*sizeof(int)); - bound(&outListData); - - writebuf = manager->allocate(outListData.size); - //if (outListData.element == inListData.element ) { - // printf("bad %x\n",outListData.element); - //} + setup_outputData(); } scheduler->dma_wait((DMA_READ + this->tag)); run(this, get_input(readbuf, 0), get_output(writebuf, 0)); @@ -247,6 +253,12 @@ return outListData.element[index].size; } +void +SchedTaskArray::set_outputSize(int index, int size) +{ + outListData.element[index].size = size; +} + memaddr SchedTaskArray::get_param(int index) {
--- a/TaskManager/kernel/schedule/SchedTaskArray.h Thu Dec 23 11:21:52 2010 +0900 +++ b/TaskManager/kernel/schedule/SchedTaskArray.h Fri Dec 31 15:58:32 2010 +0900 @@ -30,12 +30,15 @@ void write(); SchedTaskBase* next(Scheduler *, SchedTaskBase *); + void setup_outputData(); + void* get_input(void*, int); memaddr get_inputAddr(int); int get_inputSize(int); void* get_output(void*, int); memaddr get_outputAddr(int); int get_outputSize(int); + void set_outputSize(int index, int size); memaddr get_param(int); int read_size();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Func.h Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,5 @@ +enum { +#include "SysTasks.h" + RESIZE, +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,24 @@ +default: macosx + +macosx: FORCE + @echo "Make for Mac OS X" + @$(MAKE) -f Makefile.macosx + +fifo64: FORCE + @echo "Make for Mac OS X 64bit mode" + @$(MAKE) -f Makefile.macosx ABIBIT=64 + +linux: FORCE + @echo "Make for Linux" + @$(MAKE) -f Makefile.linux + +cell: FORCE + @echo "Make for PS3 (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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.cell Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,45 @@ +include ./Makefile.def + +ABIBIT=32 +CFLAGS += -m$(ABIBIT) -D__CERIUM_CELL__ + +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) $(CFLAGS) -o $@ $(OBJS) $(TASK_OBJS) $(LIBS) + +speobject: + cd spe; $(MAKE) ABIBIT=$(ABIBIT) + +run: + ./$(TARGET) -cpu 6 + +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.def Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,14 @@ +TARGET = resize + +# include/library path +# ex macosx +#CERIUM = /Users/gongo/Source/Cerium + +# ex linux/ps3 +CERIUM = ../../../Cerium + +CC = g++ -m32 +CFLAGS = -g -Wall -O9 + +INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L${CERIUM}/TaskManager
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.linux Fri Dec 31 15:58:32 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/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/Makefile.macosx Fri Dec 31 15:58:32 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 `sdl-config --libs` + +.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/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/main.cc Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,178 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); + +static int count = 1; +static int spe_num = 1; +static int data_size = 10; +static int data_length = 1; + +extern TaskManager *manager; +int use_task_creater = 0; + +const char *usr_help_str = "Usage: ./resize [-cpu spe_num] [-count N]\n\ + -cpu Number of SPE (default 1) \n\ + -count Number of task is print \"Hello, World!!\""; + +int +init(int argc, char **argv) +{ + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-count") == 0) { + count = atoi(argv[++i]); + } else if (strcmp(argv[i], "-cpu") == 0) { + spe_num = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-length") == 0) { + data_length = atoi(argv[++i]); + } + } + + return 0; +} + + +static void simple_task_creater(int in_total_size, int out_total_size, + int command, int in_data_size, int out_data_size, + void *in_data, void *out_data, TaskManager *manager, + HTask *wait_i, HTask *wait_me) { + + + int in_task_size = 0; + int out_task_size = 0; + + if (in_total_size != 0) { + in_task_size = in_total_size / in_data_size; + if (in_total_size != in_task_size * in_data_size) { + printf("mismatch of in_total_size and in_data_size\n"); + } + } + + if (out_total_size != 0) { + out_task_size = out_total_size / out_data_size; + if (out_total_size != out_task_size * out_data_size) { + printf("mismatch of out_total_size and out_data_size\n"); + } + } + + /*in, out の大きい方に合わせるのがいいかな? Taskの数は1Task分に使うデータの大きいほうを取るような仕様がいいかな*/ + int task_num = (in_task_size > out_task_size) ? in_task_size : out_task_size; + + if (task_num == 0) task_num = 1; + + /*spe分あればいいのかな?*/ + + int array_num = spe_num; + if (task_num < array_num) { + array_num = task_num; + } + + + int array_length = task_num / array_num; + int rest = task_num % array_num; + + HTaskPtr *task_array = (HTask**)manager->allocate(sizeof(HTask*)*array_num); + TaskPtr *t_exec = (Task**)manager->allocate(sizeof(Task*)*array_length*array_num); + + int index = 0; + + for (int k = 0; k < array_num; k++) { + + task_array[k] = manager->create_task_array(command,array_length,0,1,1); + t_exec[k] = 0; + + if (wait_me != 0) { + wait_me->wait_for(task_array[k]); + } + if (wait_i != 0) { + task_array[k]->wait_for(wait_i); + } + + } + + for (int j = 0; j < array_length; j++) { + for (int k = 0; k < array_num; k++) { + + t_exec[k] = task_array[k]->next_task_array(command,t_exec[k]); + t_exec[k]->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); + t_exec[k]->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); + + index++; + + } + } + + for (int k = 0; k < array_num; k++) { + task_array[k]->spawn_task_array(t_exec[k]->next()); + task_array[k]->set_cpu(SPE_ANY); + task_array[k]->spawn(); + } + + for (int k = 0; k < rest; k++) { + HTaskPtr t_exec = manager->create_task(command); + + t_exec->set_inData(0,(char*)in_data + index*in_data_size, in_data_size); + t_exec->set_outData(0,(char*)out_data + index*out_data_size, out_data_size); + + index++; + + if (wait_me != 0) { + wait_me->wait_for(t_exec); + } + if (wait_i != 0) { + t_exec->wait_for(wait_i); + } + + t_exec->set_cpu(SPE_ANY); + t_exec->spawn(); + + } + + +} + +void +checkData(SchedTask *s, void *data, void *arg1) +{ + int *idata = (int*)data; + for (int i = 0;i < data_length;i++) { + int p_data = idata[i]; + printf("data[%d] = %d\n", i, p_data); + } + free(data); +} + + +void +resize_init(TaskManager *manager) +{ + HTaskPtr resize_task = manager->create_task(Resize); + int *obj = (int*)manager->allocate(sizeof(int)*data_size); + + resize_task->set_param(0, (memaddr)data_length); + resize_task->set_inData(0, obj, sizeof(int)*data_size); + resize_task->set_outData(0, obj, 0); + + resize_task->set_post(checkData, (void*)obj, NULL); + resize_task->set_cpu(SPE_ANY); + resize_task->spawn(); +} + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + if (init(argc, argv) < 0) { + return -1; + } + + // Task Register + // ppe/task_init.cc + task_init(); + + resize_init(manager); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/Resize.cc Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,23 @@ +#include <stdio.h> +#include "SchedTask.h" +#include "Resize.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask1(Resize,resize); + +static int +resize(SchedTask *smanager, void *rbuf, void *wbuf) +{ + int length = (int)smanager->get_param(0); + int *idata = (int*)smanager->get_output(rbuf, 0); + + smanager->set_outputSize(0, sizeof(int)*length); + smanager->setup_outputData(); + + for (int i =0; i < length;i++) { + idata[i] = i; + } + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/Resize.h Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_RESIZE +#define INCLUDED_TASK_RESIZE + +#include "SchedTask.h" + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/ppe/task_init.cc Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Resize); + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init() +{ + SchedRegisterTask(RESIZE, Resize); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Makefile Fri Dec 31 15:58:32 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++ -D__CERIUM_CELL__ -DABIBIT=$(ABIBIT) +CFLAGS = -O9 -g -Wall -fno-exceptions -fno-rtti#-DDEBUG +INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. +LIBS = -L../${CERIUM}/TaskManager -lspemanager -Wl,--gc-sections + +.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 *~ \#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Resize.cc Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,13 @@ +#include <stdio.h> +#include "Resize.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask1(Resize,resize); + +static int +resize(SchedTask *smanager, void *rbuf, void *wbuf) +{ + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/Resize.h Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,9 @@ +#ifndef INCLUDED_TASK_RESIZE +#define INCLUDED_TASK_RESIZE + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/ResizeWritebuf/spe/spe-main.cc Fri Dec 31 15:58:32 2010 +0900 @@ -0,0 +1,14 @@ +#include "Func.h" +#include "Scheduler.h" + +SchedExternTask(Resize); + +/** + * この関数は SpeScheduler から呼ばれるので + * 必ずこの関数名でお願いします。 + */ +void +task_init(Scheduler *s) +{ + SchedRegisterTask(RESIZE, Resize); +}