# HG changeset patch # User Shohei KOKUBO # Date 1391120107 -32400 # Node ID 4eefec26e3e2a22b48a58df7a09aed471303dee3 # Parent 777bdbf6c072d87a84396726462f55fe086ea156 add file diff -r 777bdbf6c072 -r 4eefec26e3e2 TaskManager/Cuda/CudaScheduler.h --- a/TaskManager/Cuda/CudaScheduler.h Fri Jan 31 06:08:13 2014 +0900 +++ b/TaskManager/Cuda/CudaScheduler.h Fri Jan 31 07:15:07 2014 +0900 @@ -58,3 +58,5 @@ #define CudaSchedRegister(str, filename, functionname) \ cuda_register_task(str, filename, functionname); #endif + +extern void cuda_register_task(int cmd, const char* filename, const char* functionname); diff -r 777bdbf6c072 -r 4eefec26e3e2 example/Cuda/Makefile --- a/example/Cuda/Makefile Fri Jan 31 06:08:13 2014 +0900 +++ b/example/Cuda/Makefile Fri Jan 31 07:15:07 2014 +0900 @@ -19,9 +19,6 @@ .cc.o: $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ -.SUFFIXES: .cu .ptx - $(NVCC) $(NVCCFLAGS) $< $@ - all: $(TARGET) $(TARGET): $(OBJS) $(TASK_OBJS) $(CUDA_SRCS_TMP) diff -r 777bdbf6c072 -r 4eefec26e3e2 example/multiply/Makefile --- a/example/multiply/Makefile Fri Jan 31 06:08:13 2014 +0900 +++ b/example/multiply/Makefile Fri Jan 31 07:15:07 2014 +0900 @@ -20,6 +20,10 @@ @echo "Make for GPU (open cl)" @$(MAKE) -f Makefile.gpu +cuda: FORCE + @echo "Make for GPU (cuda)" + @$(MAKE) -f Makefile.cuda + FORCE: clean: diff -r 777bdbf6c072 -r 4eefec26e3e2 example/multiply/Makefile.cuda --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/multiply/Makefile.cuda Fri Jan 31 07:15:07 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 = 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) + $(NVCC) $(NVCCFLAGS) $(CUDA_SRCS_TMP) + $(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 gpu/*~ gpu/\#* diff -r 777bdbf6c072 -r 4eefec26e3e2 example/multiply/cuda/gpu_task_init.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/multiply/cuda/gpu_task_init.cc Fri Jan 31 07:15:07 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, "gpu/Multi.ptx","multi"); +} diff -r 777bdbf6c072 -r 4eefec26e3e2 example/multiply/cuda/multiply.cu --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/multiply/cuda/multiply.cu Fri Jan 31 07:15:07 2014 +0900 @@ -0,0 +1,6 @@ +extern "C" { + __global__ void multi(float* A, float* B, float* C) { + int id = blockIdx.x * blockDim.x + threadIdx.x; + C[id]=A[id]*B[id]; + } +} diff -r 777bdbf6c072 -r 4eefec26e3e2 example/multiply/main.cc --- a/example/multiply/main.cc Fri Jan 31 06:08:13 2014 +0900 +++ b/example/multiply/main.cc Fri Jan 31 07:15:07 2014 +0900 @@ -71,7 +71,7 @@ multi_init(TaskManager *manager) { HTask* multiply; - HTask* hoge; + // HTask* hoge; A = new float[length]; B = new float[length]; @@ -98,14 +98,12 @@ */ multiply->set_inData(0,(memaddr)A, sizeof(float)*length); multiply->set_inData(1,(memaddr)B, sizeof(float)*length); - multiply->set_inData(2,(memaddr)C,sizeof(float)*length); /** * Set of OutPut area * add_outData(address of output area, size of output area); */ multiply->set_outData(0,(memaddr)C, sizeof(float)*length); // param 0に0~length-1をsetしたtaskをlength個spawnする - multiply->set_param(0,(long)1); multiply->iterate(length); // hoge = manager->create_task(MULTIPLY_TASK);