Mercurial > hg > Game > Cerium
changeset 1999:278e6ae50b72 draft
add test
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 02 May 2014 16:41:31 +0900 |
parents | ed30952c240e |
children | ac16a57f5dd7 |
files | TaskManager/test/IterateTest/Func.h TaskManager/test/IterateTest/Makefile TaskManager/test/IterateTest/Makefile.cell TaskManager/test/IterateTest/Makefile.cuda TaskManager/test/IterateTest/Makefile.def TaskManager/test/IterateTest/Makefile.gpu TaskManager/test/IterateTest/Makefile.linux TaskManager/test/IterateTest/Makefile.macosx TaskManager/test/IterateTest/cuda/gpu_task_init.cc TaskManager/test/IterateTest/cuda/multiply.cu TaskManager/test/IterateTest/gpu/Multi.cl TaskManager/test/IterateTest/gpu/gpu_task_init.cc TaskManager/test/IterateTest/main.cc TaskManager/test/IterateTest/ppe/Multi.cc TaskManager/test/IterateTest/ppe/Multi.h TaskManager/test/IterateTest/ppe/Multi_.cc TaskManager/test/IterateTest/ppe/task_init.cc |
diffstat | 17 files changed, 529 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/Func.h Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,7 @@ +enum { +#include "SysTasks.h" + MULTIPLY_TASK, + MULTIPLY_TASK_, +}; + +#define DATA_NUM 60000
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/Makefile Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,33 @@ +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 + +cuda: FORCE + @echo "Make for GPU (cuda)" + @$(MAKE) -f Makefile.cuda + +FORCE: + +clean: + @$(MAKE) -f Makefile.macosx clean + @$(MAKE) -f Makefile.linux clean + @$(MAKE) -f Makefile.gpu clean + @$(MAKE) -f Makefile.cuda clean
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/Makefile.cell Fri May 02 16:41:31 2014 +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/IterateTest/Makefile.cuda Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,49 @@ +include ./Makefile.def + +SRCS_TMP = $(wildcard *.cc) +SRCS_EXCLUDE = # 除外するファイルを書く +SRCS = $(filter-out $(SRCS_EXCLUDE),$(SRCS_TMP)) +OBJS = $(SRCS:.cc=.o) + +TASK_DIR = ppe +CUDA_TASK_DIR = cuda + +TASK_SRCS_TMP = $(wildcard $(TASK_DIR)/*.cc) +TASK_SRCS_EXCLUDE = +TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) $(wildcard $(CUDA_TASK_DIR)/*.cc) +TASK_OBJS = $(TASK_SRCS:.cc=.o) + +CUDA_SRCS_TMP = $(wildcard $(CUDA_TASK_DIR)/*.cu) +CUDA_SRCS_EXCLUDE = # 除外するファイルを書く +CUDA_SRCS = $(filter-out $(CUDA_TASK_DIR)/$(CUDA_SRCS_EXCLUDE),$(CUDA_SRCS_TMP)) +CUDA_OBJS = $(CUDA_SRCS:.cu=.ptx) + +CFLAGS += -D__CERIUM_GPU__ +LIBS += `sdl-config --libs` -lCudaManager -F/Library/Frameworks -framework CUDA + +INCLUDE += -I/Developer/NVIDIA/CUDA-5.5/include + +NVCC = /Developer/NVIDIA/CUDA-5.5/bin/nvcc +NVCCFLAGS = -ptx -arch=sm_20 + +.SUFFIXES: .cc .o + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) $(CUDA_SRCS_TMP) $(CUDA_TASK_DIR) + $(NVCC) $(NVCCFLAGS) $(CUDA_SRCS_TMP) -o $(CUDA_TASK_DIR)/$@.ptx + $(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) $(CUDA_OBJS) + rm -f *~ \#* + rm -f cuda/*~ cuda/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/Makefile.def Fri May 02 16:41:31 2014 +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/IterateTest/Makefile.gpu Fri May 02 16:41:31 2014 +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) + +GPU_TASK_DIR = gpu +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)) $(wildcard $(GPU_TASK_DIR)/*.cc) +TASK_OBJS = $(TASK_SRCS:.cc=.o) +CFLAGS = -D__CERIUM_GPU__ +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/IterateTest/Makefile.linux Fri May 02 16:41:31 2014 +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/IterateTest/Makefile.macosx Fri May 02 16:41:31 2014 +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) +ABIBIT=64 + +TASK_DIR = ppe +#GPU_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 += -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/IterateTest/cuda/gpu_task_init.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "CudaScheduler.h" + +/* 必ずこの位置に書いて */ + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +gpu_task_init(void) +{ + CudaSchedRegister(MULTIPLY_TASK, "cuda/multiply.ptx","multi"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/cuda/multiply.cu Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,8 @@ +extern "C" { + __global__ void multi(long* params, float* A, float* B, float* C) { + int id = blockIdx.x * blockDim.x + threadIdx.x; + long length = params[0]; + // for (int id = 0; id < length; id++) + C[id]=A[id]*B[id]; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/gpu/Multi.cl Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,8 @@ +__kernel void +multi(__global const long *params, __global const float* A, __global const float* B, __global float* C) +{ + // int i=get_global_id(0); + long id = get_global_id(0); + // for(int i=0;i<length;i++) { + C[id]=A[id]*B[id]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/gpu/gpu_task_init.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "GpuScheduler.h" + +/* 必ずこの位置に書いて */ + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でお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/IterateTest/main.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,136 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> +#include "TaskManager.h" +#include "Func.h" + +extern void task_init(void); +extern void gpu_task_init(void); +static int task = 1; +static int length = DATA_NUM; +static CPU_TYPE spe_cpu = SPE_ANY; +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; + } else if (strcmp(argv[i], "-any") == 0) { + spe_cpu = ANY_ANY; + } else if (strcmp(argv[i], "-g") == 0) { + spe_cpu = GPU_0; + } + } +} + +void +multi_init(TaskManager *manager) +{ + HTask* first; + HTask* second; + HTask* third; + + 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; + } + + first = manager->create_task(MULTIPLY_TASK); + first->set_cpu(spe_cpu); + first->set_inData(0,(memaddr)A, sizeof(float)*length); + first->set_inData(1,(memaddr)B, sizeof(float)*length); + first->set_outData(0,(memaddr)C, sizeof(float)*length); + first->iterate(length); + + second = manager->create_task(MULTIPLY_TASK_); + second->set_cpu(spe_cpu); + second->set_inData(0,(memaddr)A,sizeof(float)*length); + second->set_inData(1,(memaddr)B,sizeof(float)*length); + second->set_outData(0,(memaddr)C,sizeof(float)*length); + // second->wait_for(first); + second->iterate(length); + + third = manager->create_task(MULTIPLY_TASK); + third->set_cpu(spe_cpu); + third->set_inData(0,(memaddr)A,sizeof(float)*length); + third->set_inData(1,(memaddr)B,sizeof(float)*length); + third->set_outData(0,(memaddr)C,sizeof(float)*length); + // third->wait_for(second); + third->iterate(length); +} + + +int +TMmain(TaskManager *manager,int argc, char *argv[]) +{ + init(argc, argv); + // Task Register + task_init(); + gpu_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/IterateTest/ppe/Multi.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,25 @@ +#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 length = (long)s->get_param(0); + long i = (long)s->x; + //for(int i=0;i<length;i++) { + C[i]=A[i]*B[i]; + //} + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/ppe/Multi.h Fri May 02 16:41:31 2014 +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/IterateTest/ppe/Multi_.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,25 @@ +#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 length = (long)s->get_param(0); + long i = (long)s->x; + //for(int i=0;i<length;i++) { + C[i]=A[i]*B[i]+1; + //} + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/IterateTest/ppe/task_init.cc Fri May 02 16:41:31 2014 +0900 @@ -0,0 +1,25 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Multiply); +SchedExternTask(Multiply_) +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init(void) +{ + SchedRegisterTask(MULTIPLY_TASK, Multiply); + SchedRegisterTask(MULTIPLY_TASK_, Multiply_); +} +#ifndef __CERIUM_GPU__ +void +gpu_task_init(void) +{ + // nop +} +#endif