Mercurial > hg > Game > Cerium
changeset 1780:17c4dc3573b9 draft
add some files
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Nov 2013 17:34:24 +0900 |
parents | 0dd39c19dbb2 |
children | a96cf4e50524 |
files | example/string_args/Func.h example/string_args/Makefile example/string_args/Makefile.cell example/string_args/Makefile.def example/string_args/Makefile.linux example/string_args/Makefile.macosx example/string_args/main.cc example/string_args/ppe/Exec.cc example/string_args/ppe/Exec.h example/string_args/ppe/task_init.cc example/string_args/spe/Exec.cc example/string_args/spe/Exec.h example/string_args/spe/task_init.cc example/string_args/spe/test.txt |
diffstat | 13 files changed, 348 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/Func.h Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,5 @@ +enum { +#include "SysTasks.h" + TASK_EXEC, +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/Makefile Tue Nov 26 17:34:24 2013 +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/string_args/Makefile.cell Tue Nov 26 17:34:24 2013 +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/string_args/Makefile.def Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,15 @@ +TARGET = string_args + +# include/library path +# ex macosx +#CERIUM = /Users/gongo/Source/Cerium + +# ex linux/ps3 +CERIUM = ../../../Cerium + +CC = clang++ +OPT = -g +CFLAGS = $(OPT) -Wall + +INCLUDE = -I.. -I. -I${CERIUM}/include/TaskManager +LIBS = -L${CERIUM}/TaskManager
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/Makefile.linux Tue Nov 26 17:34:24 2013 +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 -lrt + +.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/string_args/Makefile.macosx Tue Nov 26 17:34:24 2013 +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/string_args/main.cc Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,77 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/time.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); + +static int spe_num = 1; +static int task_num = 1; +static CPU_TYPE spe_cpu = SPE_ANY; +static int one_task_size = 4096 * 4; + +extern TaskManager *manager; +const char *usr_help_str = "Usage: ./string_args [-cpu cpu_num] [-sw search_word] [-t task_num]\n"; + +static char* +init(int argc, char **argv) +{ + char *search_word = 0; + + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "-cpu") == 0) { + spe_num = atoi(argv[i+1]); + } else if (strcmp(argv[i], "-sw") == 0) { + search_word = argv[i+1]; + } else if (strcmp(argv[i], "-t") == 0) { + task_num = atoi(argv[i+1]); + } + } + + if (search_word==0){ + puts(usr_help_str); + exit(1); + } + + return search_word; +} + +static void +run_start(TaskManager *manager,char *search_word,int search_word_len) +{ + HTask *exec; + + exec = manager->create_task(TASK_EXEC); + exec->set_cpu(spe_cpu); + + //ファイルディスクリプタをそのままタスクに渡してあげる + exec->set_inData(0,search_word,search_word_len); + + exec->set_param(0,one_task_size); //1つのタスクが読み込む量 + exec->iterate(task_num); //タスク数分イテレートする +} + + +int +TMmain(TaskManager *manager, int argc, char *argv[]) +{ + char *search_word = 0; + int search_word_len = 0; + + search_word = init(argc,argv); + search_word_len = strlen((const char*)search_word); + + if (search_word < 0) { + return -1; + } + char *sword = (char*)manager->allocate(sizeof(char)*search_word_len); + strcpy(sword,(const char*)search_word); + + task_init(); + run_start(manager, sword, search_word_len); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/ppe/Exec.cc Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <iostream> +#include <vector> +#include <cstdlib> + +#include "SchedTask.h" +#include "Exec.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(Exec); + + + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + char *search_word = (char *)s->get_input(rbuf,0); + + long task_size = (long)s->get_param(0); + + //s->xはiteraterで繰り返した数 + + s->printf("test num : %d\n",task_size); + s->printf("arg word : %s\n",search_word); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/ppe/Exec.h Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#include "SchedTask.h" + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/ppe/task_init.cc Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Exec); + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init(void) +{ + SchedRegisterTask(TASK_EXEC, Exec); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/spe/Exec.cc Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <iostream> +#include <vector> +#include <cstdlib> + +#include "SchedTask.h" +#include "Exec.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(Exec); + + + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + char *search_word = (char *)s->get_input(rbuf,0); + + long task_size = (long)s->get_param(0); + + //s->xはiteraterで繰り返した数 + + s->printf("test num : %d\n",task_size); + s->printf("arg word : %s\n",search_word); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/spe/Exec.h Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,7 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#include "SchedTask.h" + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/string_args/spe/task_init.cc Tue Nov 26 17:34:24 2013 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Exec); + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init(void) +{ + SchedRegisterTask(TASK_EXEC, Exec); +}