Mercurial > hg > Game > Cerium
changeset 312:1db2b3dc6a5a draft
memMain tester
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Jun 2009 23:19:11 +0900 |
parents | 74a1e261e734 |
children | 25dfa7499162 |
files | example/mainMem/Func.h example/mainMem/Makefile example/mainMem/Makefile.cell example/mainMem/Makefile.def example/mainMem/Makefile.linux example/mainMem/Makefile.macosx example/mainMem/README example/mainMem/main.cc example/mainMem/ppe/.#Hello.cc example/mainMem/ppe/Hello.cc example/mainMem/ppe/Hello.h example/mainMem/ppe/task_init.cc example/mainMem/spe/Hello.cc example/mainMem/spe/Hello.h example/mainMem/spe/Makefile example/mainMem/spe/spe-main.cc |
diffstat | 16 files changed, 438 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/Func.h Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,5 @@ +enum { + HELLO_TASK, + RUN_FINISH, +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/Makefile Mon Jun 08 23:19:11 2009 +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 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/mainMem/Makefile.cell Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,42 @@ +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) + +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/mainMem/Makefile.def Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,14 @@ +TARGET = mainMem + +# include/library path +# ex: macosx +#CERIUM = /Users/gongo/Source/Cerium + +# ex: linux/ps3 +CERIUM = ../../../Cerium + +CC = g++ +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/mainMem/Makefile.linux Mon Jun 08 23:19:11 2009 +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/mainMem/Makefile.macosx Mon Jun 08 23:19:11 2009 +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/mainMem/README Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,47 @@ +/* + * $Id: README,v 1.5 2008/11/01 02:37:12 gongo Exp $ + */ + +- 概要 + +"Hello, World!!" を出力するプログラムです。 +タスク Hello が文字列を表示します。 + +- 実行方法 + +% ./hello [-count COUNT] + + -count 表示する "Hello, World!!" の数(つまり、タスク Hello の数)です。 + +- 実行例 (-cpu は Cerium 標準のオプションです) + +% ./hello +[0] Hello, World!! + +% ./hello -count 10 +[0] Hello, World!! +[1] Hello, World!! +[2] Hello, World!! +[3] Hello, World!! +[4] Hello, World!! +[5] Hello, World!! +[6] Hello, World!! +[7] Hello, World!! +[8] Hello, World!! +[9] Hello, World!! + +% ./hello -count 10 -cpu 3 +[0] Hello, World!! +[2] Hello, World!! +[3] Hello, World!! +[5] Hello, World!! +[6] Hello, World!! +[8] Hello, World!! +[9] Hello, World!! +[1] Hello, World!! +[4] Hello, World!! +[7] Hello, World!! + +上の例では、Hello タスク 10 個を、 +3 つの CPU に振り分けて実行しているので +表示が順になっていない -> 並列に実行されていることがわかります。 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/main.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); + +static int count = 1; + +extern TaskManager *manager; + +const char *usr_help_str = "Usage: ./hello [-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]); + } + + } + + return 0; +} + +void +hello_init(void) +{ + HTask *hello; + + for (int i = 0; i < count; i++) { + /** + * Create Task + * create_task(Task ID); + */ + hello = manager->create_task(HELLO_TASK); + + /** + * Select CPU + * SPE_0, SPE_1, SPE_2, SPE_3, SPE_4, SPE_5, SPE_ANY + * if you do not call this, execute PPE. + */ + hello->set_cpu(SPE_ANY); + + /** + * Set 32bits parameter + * add_param(32bit parameter); + */ + hello->add_param(i); + + hello->spawn(); + } +} + +int +TMmain(int argc, char *argv[]) +{ + if (init(argc, argv) < 0) { + return -1; + } + + // Task Register + // ppe/task_init.cc + task_init(); + + hello_init(); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/ppe/.#Hello.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,1 @@ +e065746@nakasone-hiroki-no-macbook.local.1456 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/ppe/Hello.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,42 @@ +#include <stdio.h> +#include "Hello.h" +#include "Func.h" + +/* 綽 */ +SchedDefineTask(Hello); + +#define PP_STORE 3 +#define SIZE (4096*sizeof(int)) + +int +Hello::run(void *rbuf, void *wbuf) +{ + int task_id = get_param(0); + int *ptr = 0; +#if 1 + ptr = (int*)smanager->allocate(SIZE); + + smanager->mainMem_alloc(0, SIZE); + + int i; + for(i=0;i<4096;i++) { + ptr[i] = i; + } +#endif + + void *next = 0; +#if 1 + smanager->mainMem_wait(); + next = (void *)smanager->mainMem_get(0); + + smanager->dma_wait(PP_STORE); + smanager->dma_store(ptr, (uint32)next, + SIZE, PP_STORE); +#endif + + + fprintf(stderr,"sizeof(int) = [%d] sizeof(void*)=[%d]\n", (int)sizeof(int),(int)sizeof(void*)); + fprintf(stderr,"[%d] Main Mem %0x len %d\n", task_id, (unsigned int)next,(int)SIZE); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/ppe/Hello.h Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,15 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + +class Hello : public SchedTask { +public: + SchedConstructor(Hello); + + int run(void *r, void *w); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/ppe/task_init.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 綽篏臀吾 */ +SchedExternTask(Hello); + +/** + * ∽違 ../spe/spe-main c + * у若喝冴違∽違 + * 絅純∽医сk (SchedRegisterTask 綽) + */ + +void +task_init(void) +{ + SchedRegisterTask(HELLO_TASK, Hello); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/spe/Hello.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,35 @@ +#include <stdio.h> +#include "Hello.h" +#include "Func.h" + +/* 綽 */ +SchedDefineTask(Hello); + +#define PP_STORE 3 +#define SIZE (4096*sizeof(int)) + +int +Hello::run(void *rbuf, void *wbuf) +{ + int task_id = get_param(0); + int *ptr = smanager->allocate(SIZE); + + smanager->mainMem_alloc(0, sizeof(PolygonPack)); + + int i; + for(i=0;i<4096;i++) { + ptr[i] = i; + } + + smanager->mainMem_wait(); + void *next = (void *)smanager->mainMem_get(0); + + smanager->dma_wait(PP_STORE); + smanager->dma_store(ptr, (uint32)next, + SIZE, PP_STORE); + + + printf("[%d] Main Mem %0x len %d\n", task_id, (int*)next,SIZE); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/spe/Hello.h Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,15 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif + +class Hello : public SchedTask { +public: + SchedConstructor(Hello); + + int run(void *r, void *w); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/spe/Makefile Mon Jun 08 23:19:11 2009 +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 = -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 *~ \#* \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/mainMem/spe/spe-main.cc Mon Jun 08 23:19:11 2009 +0900 @@ -0,0 +1,14 @@ +#include "Func.h" +#include "Scheduler.h" + +SchedExternTask(Hello); + +/** + * ∽違 SpeScheduler 若違 + * 綽∽医с蕁障 + */ +void +task_init(void) +{ + SchedRegisterTask(HELLO_TASK, Hello); +}