Mercurial > hg > Game > Cerium
changeset 2016:e904bb51fea9 draft
add flipTest. passed test, but wrong result in fft.
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 10 Jul 2014 17:32:30 +0900 |
parents | 6bf6450bd45a |
children | 1d7d1e398833 |
files | TaskManager/test/flipTest/Func.h TaskManager/test/flipTest/Makefile TaskManager/test/flipTest/Makefile.cuda TaskManager/test/flipTest/Makefile.def TaskManager/test/flipTest/Makefile.macosx TaskManager/test/flipTest/cuda/add.cu TaskManager/test/flipTest/cuda/gpu_task_init.cc TaskManager/test/flipTest/main.cc TaskManager/test/flipTest/ppe/Add.cc TaskManager/test/flipTest/ppe/Add.h TaskManager/test/flipTest/ppe/task_init.cc |
diffstat | 11 files changed, 324 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/Func.h Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,6 @@ +enum { +#include "SysTasks.h" + ADD_TASK, +}; + +#define DATA_NUM 10
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/Makefile Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,19 @@ +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 + +cuda: FORCE + @echo "Make for GPU (cuda)" + @$(MAKE) -f Makefile.cuda + +FORCE: + +clean: + @$(MAKE) -f Makefile.macosx clean + @$(MAKE) -f Makefile.cuda clean
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/Makefile.cuda Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,51 @@ +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$(CUDA_PATH) + +NVCC = nvcc +NVCCFLAGS = -ptx -arch=sm_20 + +.SUFFIXES: .cc .o .cu .ptx + +.cc.o: + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +.cu.ptx: + $(NVCC) $(NVCCFLAGS) $< -o $@ + +all: $(TARGET) + +$(TARGET): $(OBJS) $(TASK_OBJS) $(CUDA_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) $(CUDA_OBJS) + rm -f *~ \#* + rm -f cuda/*~ cuda/\#*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/Makefile.def Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,15 @@ +TARGET = flipTest + +# 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/flipTest/Makefile.macosx Thu Jul 10 17:32:30 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/flipTest/cuda/add.cu Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,6 @@ +extern "C" { + __global__ void add(long* params, int* A) { + int id = blockIdx.x * blockDim.x + threadIdx.x; + A[id] = A[id]+1; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/cuda/gpu_task_init.cc Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "CudaScheduler.h" + +/* 必ずこの位置に書いて */ + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +gpu_task_init(void) +{ + CudaSchedRegister(ADD_TASK, "cuda/add.ptx","add"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/main.cc Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,123 @@ +#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 = 3; +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; +static int flip_flag = 0; +void TMend(TaskManager *); + +int *A; + +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 +print_result() { + printf("---\n"); + if(print_flag == 1) { + for (int i =0;i<length;i++) { + printf("%d\n",A[i]); + } + } + printf("---\n"); +} + +static void +check_data() { + for (int i=0;i<length;i++) { + if(A[i] != i+task) { + puts("Incorrect."); + return; + } + } + puts("Correct."); +} + +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; + } else if (strcmp(argv[i], "--flip") ==0 || strcmp(argv[i], "-f") == 0) { + flip_flag = 1; + } + } +} + +void +add_init(TaskManager *manager) +{ + HTask* add[task]; + + A = new int[length]; + for(int i=0; i<length; i++) + A[i]=i; + + for (int i=0; i<task-1; i++) { + add[i] = manager->create_task(ADD_TASK); + add[i]->set_cpu(spe_cpu); + add[i]->set_inData(0,(memaddr)A, sizeof(int)*length); + add[i]->set_outData(0,(memaddr)A, sizeof(int)*length); + if (flip_flag == 1) + add[i]->flip(); + if (i != 0) + add[i]->wait_for(add[i-1]); + add[i]->iterate(length); + } + + add[task-1] = manager->create_task(ADD_TASK); + add[task-1]->set_cpu(spe_cpu); + add[task-1]->set_inData(0,(memaddr)A, sizeof(int)*length); + add[task-1]->set_outData(0,(memaddr)A, sizeof(int)*length); + add[task-1]->wait_for(add[task-2]); + add[task-1]->iterate(length); +} + + +int +TMmain(TaskManager *manager,int argc, char *argv[]) +{ + init(argc, argv); + // Task Register + task_init(); + gpu_task_init(); + add_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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/ppe/Add.cc Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,17 @@ +#include <stdio.h> +#include "SchedTask.h" +#include "Multi.h" +#include "Func.h" +#include "GpuScheduler.h" + +/* これは必須 */ +SchedDefineTask(Add); + +static int +run(SchedTask *s,void *rbuf, void *wbuf) +{ + int *A = (int*)s->get_input(rbuf, 0); + long i = (long)s->x; + A[i] = A[i]+1; + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/flipTest/ppe/Add.h Thu Jul 10 17:32:30 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/flipTest/ppe/task_init.cc Thu Jul 10 17:32:30 2014 +0900 @@ -0,0 +1,16 @@ +#include "Func.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(Add); +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init(void) +{ + SchedRegisterTask(ADD_TASK, Add); +}