Mercurial > hg > Game > Cerium
changeset 1697:ef1099c41449 draft
UtilizationTest
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/ChangeLog Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,6 @@ +2008-05-27 Wataru MIYAGUNI <gongo@cr.ie.u-ryukyu.ac.jp> + + * memo + Fifo バージョンでは確認しました。 + Cell バージョンは、Cerium がまだ未実装なのでそれから +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/Func.h Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,6 @@ +enum { +#include "SysTasks.h" + MULTIPLY_TASK, +}; + +#define DATA_NUM 10000000
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/Makefile Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,28 @@ +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 + +gpu: FORCE + @echo "Make for GPU (open cl)" + @$(MAKE) -f Makefile.gpu + +FORCE: + +clean: + @$(MAKE) -f Makefile.macosx clean + @$(MAKE) -f Makefile.linux clean + @$(MAKE) -f Makefile.gpu clean
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/Makefile.cell Fri Oct 04 16:41:23 2013 +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/Makefile.def Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,15 @@ +TARGET = multiply + +# 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/TaskManager/test/UtilizationTest/Makefile.gpu Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,35 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # ゅ<ゃ吾 +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = gpu +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 += `sdl-config --libs` -lGpuManager -framework opencl + +.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 ppu-gdb ./$(TARGET) + +clean: + rm -f $(TARGET) $(OBJS) $(TASK_OBJS) + rm -f *~ \#* + rm -f gpu/*~ gpu/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/Makefile.linux Fri Oct 04 16:41:23 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/TaskManager/test/UtilizationTest/Makefile.macosx Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,38 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # ゅ<ゃ吾 +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) +ABIBIT=64 + +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 += -m$(ABIBIT) + +.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/TaskManager/test/UtilizationTest/gpu/Multi.cl Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,7 @@ +__kernel void +multi(__global const void *params,__global const float *A, __global const float*B, __global float *C) +{ + int i=get_global_id(0); + + C[i]=A[i]*B[i]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/gpu/gpu_task_init.cc Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "GpuScheduler.h" + +/* 綽篏臀吾 */ + +/** + * ∽違 ../spe/spe-main c + * у若喝冴違∽違 + * 絅純∽医сk (SchedRegisterTask 綽) + */ + +void +gpu_task_init(void) +{ + GpuSchedRegister(MULTIPLY_TASK, "gpu/Multi.cl","multi"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/gpu/task_init.cc Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "GpuScheduler.h" + +/* 綽篏臀吾 */ + +/** + * ∽違 ../spe/spe-main c + * у若喝冴違∽違 + * 絅純∽医сk (SchedRegisterTask 綽) + */ + +void +task_init(void) +{ + GpuSchedRegister(MULTIPLY_TASK, "gpu/Multi.cl","multi"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/main.cc Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,153 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); +static int task = 1; +static int length = DATA_NUM; +const char *usr_help_str = "Usage: ./multiply \n"; +static int print_flag = 0; +void TMend(TaskManager *); + +float *A,*B,*C; + +static double st_time = 0 ; +static double ed_time = 0; + +static double +getTime() { + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec + (double)tv.tv_usec*1e-6; +} + +static void +check_data() { + for(int i=0; i<length;i++) { + if (A[i]*B[i]!=C[i]) { + printf("Multiplication went wrong.\n"); + return; + } + } + printf("Multiplication was succeeded.\n"); + return; +} + +static void +print_result() { + printf("---\n"); + if(print_flag == 1) { + for (int i =0;i<length;i++) { + printf("%f * %f = %f \n",A[i],B[i],C[i]); + } + } + printf("---\n"); +} + + +void +init(int args, char *argv[]) { + for (int i = 1; argv[i]; ++i) { + if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { + length = atoi(argv[++i]); + } else if (strcmp(argv[i], "-t") == 0) { + task = atoi(argv[++i]); + } else if (strcmp(argv[i], "-print") == 0) { + print_flag = 1; + } + } +} + +void +multi_init(TaskManager *manager) +{ + + A = new float[length]; + B = new float[length]; + C = new float[length]; + for(int i=0; i<length; i++) { + A[i]=(float)(i+1000); + B[i]=(float)(i+1)/10.f; + } + + HTask *multiply = manager->create_task(MULTIPLY_TASK); + multiply->set_cpu((CPU_TYPE)((int)SPE_0)); + + multiply->set_inData(0,(memaddr)A, sizeof(float)*length); + multiply->set_inData(1,(memaddr)B, sizeof(float)*length); + + multiply->set_outData(0,(memaddr)C, sizeof(float)*length); + + multiply->spawn(); + + HTask* previous = multiply; + + for(int i=1;i<4;i++) { + multiply = manager->create_task(MULTIPLY_TASK); + multiply->set_cpu((CPU_TYPE)((int)SPE_0+i)); + + multiply->set_inData(0,(memaddr)A, sizeof(float)*length); + multiply->set_inData(1,(memaddr)B, sizeof(float)*length); + + multiply->set_outData(0,(memaddr)C, sizeof(float)*length); + + multiply->wait_for(previous); + + multiply->spawn(); + + previous = multiply; + } + // // HTask* second_multiply = manager->create_task(MULTIPLY_TASK); + // // second_multiply->set_cpu(SPE_1); + + // // second_multiply->set_inData(0,(memaddr)A, sizeof(float)*length); + // // second_multiply->set_inData(1,(memaddr)B, sizeof(float)*length); + + // // second_multiply->set_outData(0,(memaddr)C, sizeof(float)*length); + + // // second_multiply->wait_for(multiply); + + + // second_multiply->spawn(); + + // multiply = manager->create_task(MULTIPLY_TASK); + // multiply->set_cpu(SPE_2); + + // multiply->set_inData(0,(memaddr)A, sizeof(float)*length); + // multiply->set_inData(1,(memaddr)B, sizeof(float)*length); + + // multiply->set_outData(0,(memaddr)C, sizeof(float)*length); + + // multiply->spawn(); +} + + +int +TMmain(TaskManager *manager,int argc, char *argv[]) +{ + init(argc, argv); + // Task Register + task_init(); + for (int i = 0; i < task; ++i) { + multi_init(manager); + } + st_time = getTime(); + manager->set_TMend(TMend); + return 0; +} + +void +TMend(TaskManager *manager) +{ + ed_time = getTime(); + print_result(); + printf("Time: %0.6f\n",ed_time-st_time); + check_data(); + + delete A; + delete B; + delete C; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/ppe/Multi.cc Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,24 @@ +#include <stdio.h> +#include "SchedTask.h" +#include "Multi.h" +#include "Func.h" +#include "GpuScheduler.h" + +/* 綽 */ +SchedDefineTask(Multiply); + +static int +run(SchedTask *s,void *rbuf, void *wbuf) +{ + float *A,*B,*C; + + A = (float*)s->get_input(rbuf, 0); + B = (float*)s->get_input(rbuf, 1); + C = (float*)s->get_output(wbuf, 0); + + // long i = s->x; + for(int i=0; i<DATA_NUM; i++) { + C[i]=A[i]*B[i]; + } + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/ppe/Multi.h Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,16 @@ +#ifndef INCLUDED_TASK_HELLO +#define INCLUDED_TASK_HELLO + +#ifndef INCLUDED_SCHED_TASK +# include "SchedTask.h" +#endif +/* +class Twice : public SchedTask { +public: + SchedConstructor(Twice); + + int run(void *r, void *w); +}; + */ + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/UtilizationTest/ppe/task_init.cc Fri Oct 04 16:41:23 2013 +0900 @@ -0,0 +1,17 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 綽篏臀吾 */ +SchedExternTask(Multiply); + +/** + * ∽違 ../spe/spe-main c + * у若喝冴違∽違 + * 絅純∽医сk (SchedRegisterTask 綽) + */ + +void +task_init(void) +{ + SchedRegisterTask(MULTIPLY_TASK, Multiply); +}