Mercurial > hg > Game > Cerium
changeset 1458:a0feb4877a1f draft
create GpuRunTest Recommit
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 09 Jun 2012 21:36:18 +0900 |
parents | 55f92ed3f244 |
children | d62b5d9faba0 |
files | TaskManager/Gpu/GpuFunc.h TaskManager/Gpu/task_init.cc TaskManager/test/GpuRunTest/GpuRunTest.cc TaskManager/test/GpuRunTest/Makefile TaskManager/test/GpuRunTest/Makefile.bk TaskManager/test/GpuRunTest/Makefile.def TaskManager/test/GpuRunTest/twice.cl |
diffstat | 7 files changed, 219 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuFunc.h Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,5 @@ +enum { +#include "SysTasks.h" + SchedRun, + RUN_FINISH, +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/task_init.cc Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,17 @@ +#include "GpuFunc.h" +#include "Scheduler.h" + +/* 必ずこの位置に書いて */ +SchedExternTask(SchedRun); + +/** + * この関数は ../spe/spe-main と違って + * 自分で呼び出せばいい関数なので + * 好きな関数名でおk (SchedRegisterTask は必須) + */ + +void +task_init() +{ + SchedRegister(SchedRun); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/GpuRunTest.cc Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,121 @@ +#include <stdio.h> +#include <fcntl.h> +#include <sys/stat.h> +#include "TaskManager.h" +#include "GpuScheduler.h" +#include "GpuThreads.h" +#include "GpuFunc.h" +#define DEFAULT 5 + + +extern void gpu_register_task(int, const char*, const char*); +extern void task_init(void); + +void +print_data(int *data, int size, const char *title) +{ + printf("%s ---\n", title); + for ( int i = 0; i < size; i++) { + printf("%2d ", data[i]); + } + printf("\n"); +} + + + +void +tester(int *indata, int *outdata, int num){ + + //チェック + int check = 0; + for (int c=0; c<num; c++) { + if(outdata[c] == indata[c]*2) { + check++; + } + } + + printf("Computed '%d/%d' correct values\n",check,num); + +} + +void +test(TaskManager *manager, long int length){ + + int cmd = 1; + GpuThreads* gputhreads = GpuThreads::getInstance(); + gputhreads->init(); + + GpuSchedRegister(cmd, "twice.cl", "twice"); + + int *indata = (int *)manager->allocate(sizeof(int)*length);//new int[length]; + int *outdata = new int[length]; + int count; + for (count=0; count < length ;count++) { + indata[count] = count; + } + print_data(indata, count, "before"); + + HTaskPtr schedtask = manager->create_task(SchedRun); + schedtask->set_inData(0, indata, sizeof (int)*length); + schedtask->set_outData(1, outdata, sizeof (int)*length); + schedtask->set_inData(2, &count, sizeof (int)); + schedtask->set_cpu(SPE_ANY); + schedtask->spawn(); + + + //以下をGpuScheduler のrunへ + /* + cl_int ret = gputhreads->ret; + cl_context context = gputhreads->context; + cl_mem memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + cl_mem data_count = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + + cl_command_queue command_queue = gputhreads->command_queue; + ret = clEnqueueWriteBuffer(command_queue, memobj_in, CL_TRUE, 0, + sizeof(int)*count, indata, 0, NULL, NULL); + ret = clEnqueueWriteBuffer(command_queue, data_count, CL_TRUE, 0, + sizeof(count), &count, 0, NULL, NULL); + + cl_kernel kernel = *(task_list[cmd].kernel); + + clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&memobj_in); + + + clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&memobj_out); + clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&data_count); + + cl_event ev = NULL; + clEnqueueTask(command_queue, kernel, 0, NULL, &ev); + + clEnqueueReadBuffer(command_queue, memobj_out, CL_TRUE, 0, + sizeof(int)*count, outdata, 1, &ev, NULL); + + print_data(outdata, count, "after"); + tester(indata,outdata,count); + + delete [] indata; + delete [] outdata; + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + clReleaseKernel(kernel); + */ + + } + +int +TMmain(TaskManager *manager, int argc, char* argv[]) +{ + long int length = DEFAULT; + + if (argc > 1) { //引数が渡されていて、 + if(atoi(argv[1])) {//数字なら + length = atoi(argv[1]); + } + } + task_init(); + + test(manager, length); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile Sat Jun 09 21:36:18 2012 +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 += ../../libGpuManager.a -framework opencl `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 *~ \#* +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile.bk Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def + +CPPFLAGS += -g -Wall -I../../../include/TaskManager -m$(ABIBIT) + +TARGET=GpuRunTest + + + +LIBS += ../../libGpuManager.a -framework opencl + +GpuRunTest : GpuRunTest.o + $(CC) $(CFLAGS) -o $@ $? $(LIBS) + +clean: + rm -rf *.o $(TARGET)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/test/GpuRunTest/Makefile.def Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,15 @@ +include ../../Makefile.def +TARGET = GpuRunTest + +# 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/TaskManager/test/GpuRunTest/twice.cl Sat Jun 09 21:36:18 2012 +0900 @@ -0,0 +1,11 @@ +__kernel void +twice(__global int *input_data, + __global int *output_data, + __global int *data_count) +{ + int count = *data_count; + for (int i = 0; i<count; i++) { + output_data[i] = input_data[i] * 2; + } + +} \ No newline at end of file