Mercurial > hg > Game > Cerium
changeset 1519:9a5f87f4b60f draft
add spe_cpu for gpu
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 10 Nov 2012 18:21:16 +0900 |
parents | 940ffd32e5bd |
children | 031f26b15ae6 |
files | TaskManager/Gpu/GpuScheduler.cc example/many_task/Makefile.gpu example/many_task/main.cc example/many_task/sort-compat.cc example/many_task/sort.cc example/many_task/task_init.cc |
diffstat | 6 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Sat Nov 10 11:15:00 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Sat Nov 10 18:21:16 2012 +0900 @@ -175,29 +175,29 @@ const char *filename = (const char *)task_list[cmd].gputask->kernel; const char *functionname = task_list[cmd].name; - int fp; + int fd; char *source_str; size_t source_size; - fp = open(filename, O_RDONLY); + fd = open(filename, O_RDONLY); - if (!fp) { - fprintf(stderr, "Failed to load kernel.\n"); + if (fd<0) { + fprintf(stderr, "Failed to load kernel %s.\n",filename); exit(1); } struct stat stats; - fstat(fp,&stats); + fstat(fd,&stats); off_t size = stats.st_size; - if (!size) { + if (size<=0) { fprintf(stderr, "Failed to load kernel.\n"); exit(1); } source_str = (char*)alloca(size); - source_size = read(fp, source_str, size); - close(fp); + source_size = read(fd, source_str, size); + close(fd); cl_program program = clCreateProgramWithSource(context, 1,
--- a/example/many_task/Makefile.gpu Sat Nov 10 11:15:00 2012 +0900 +++ b/example/many_task/Makefile.gpu Sat Nov 10 18:21:16 2012 +0900 @@ -11,6 +11,8 @@ TASK_SRCS = $(filter-out $(TASK_DIR)/$(TASK_SRCS_EXCLUDE),$(TASK_SRCS_TMP)) TASK_OBJS = $(TASK_SRCS:.cc=.o) +CFLAGS += -D__CERIUM_GPU__ + LIBS += -lGpuManager -framework opencl `sdl-config --libs` .SUFFIXES: .cc .o
--- a/example/many_task/main.cc Sat Nov 10 11:15:00 2012 +0900 +++ b/example/many_task/main.cc Sat Nov 10 18:21:16 2012 +0900 @@ -25,6 +25,7 @@ static double ed_time; static int length = 1200; +CPU_TYPE spe_cpu = SPE_ANY; // prototype void TMend(TaskManager *); @@ -53,6 +54,9 @@ if (strcmp(argv[i], "-a") == 0 ) { all = 1; } + if (strcmp(argv[i], "-g") == 0 ) { + spe_cpu = GPU_0; + } if (strcmp(argv[i], "-c") == 0 ) { sort_task = SortCompat; }
--- a/example/many_task/sort-compat.cc Sat Nov 10 11:15:00 2012 +0900 +++ b/example/many_task/sort-compat.cc Sat Nov 10 18:21:16 2012 +0900 @@ -6,6 +6,7 @@ extern void check_data(); extern int all; // allocate task at once +extern CPU_TYPE spe_cpu; SchedDefineTask1(SortCompat, sort_start_compat ); @@ -37,7 +38,7 @@ if (i<s->split_num-2 && s->bsort[i]) { s->fsort[i]->wait_for(s->bsort[i]); } - s->fsort[i]->set_cpu(SPE_ANY); + s->fsort[i]->set_cpu(spe_cpu); } // 最後の block は端数なので last_block_num を使う @@ -50,7 +51,7 @@ if (i>0 && s->bsort[i-1]) { s->fsort[i]->wait_for(s->bsort[i-1]); } - s->fsort[i]->set_cpu(SPE_ANY); + s->fsort[i]->set_cpu(spe_cpu); } if (s->split_num > 1) { @@ -62,7 +63,7 @@ sizeof(Data)*block_num); s->bsort[i]->set_outData(0,&s->data[i*block_num+half_block_num], sizeof(Data)*block_num); - s->bsort[i]->set_cpu(SPE_ANY); + s->bsort[i]->set_cpu(spe_cpu); } { @@ -74,7 +75,7 @@ sizeof(Data)*last_half_block_num); s->bsort[i]->set_outData(0,&s->data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num); - s->bsort[i]->set_cpu(SPE_ANY); + s->bsort[i]->set_cpu(spe_cpu); } for (int i = 0; i < half_num; i++) {
--- a/example/many_task/sort.cc Sat Nov 10 11:15:00 2012 +0900 +++ b/example/many_task/sort.cc Sat Nov 10 18:21:16 2012 +0900 @@ -6,6 +6,7 @@ extern int get_split_num(int len, int num); extern int all; // allocate task at once +extern CPU_TYPE spe_cpu ; /** * 一つの block にある data の数が MAX_BLOCK_SIZE 超えないような @@ -71,7 +72,7 @@ if (i<s->split_num-2 && s->bsort[i]) { s->fsort[i]->wait_for(s->bsort[i]); } - s->fsort[i]->set_cpu(SPE_ANY); + s->fsort[i]->set_cpu(spe_cpu); s->fsort[i]->set_param(0,(memaddr)block_num); } @@ -86,7 +87,7 @@ if (i>0 && s->bsort[i-1]) { s->fsort[i]->wait_for(s->bsort[i-1]); } - s->fsort[i]->set_cpu(SPE_ANY); + s->fsort[i]->set_cpu(spe_cpu); s->fsort[i]->set_param(0,(memaddr)last_block_num); } @@ -98,7 +99,7 @@ (memaddr)&s->data[i*block_num+half_block_num], sizeof(Data)*block_num, (memaddr)&s->data[i*block_num+half_block_num], sizeof(Data)*block_num); s->bsort[i]->flip(); - s->bsort[i]->set_cpu(SPE_ANY); + s->bsort[i]->set_cpu(spe_cpu); s->bsort[i]->set_param(0,(memaddr)block_num); } @@ -110,7 +111,7 @@ (memaddr)&s->data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num, (memaddr)&s->data[i*block_num+half_block_num], sizeof(Data)*last_half_block_num); s->bsort[i]->flip(); - s->bsort[i]->set_cpu(SPE_ANY); + s->bsort[i]->set_cpu(spe_cpu); s->bsort[i]->set_param(0,(memaddr)last_half_block_num); }
--- a/example/many_task/task_init.cc Sat Nov 10 11:15:00 2012 +0900 +++ b/example/many_task/task_init.cc Sat Nov 10 18:21:16 2012 +0900 @@ -1,14 +1,23 @@ #include "Func.h" #include "Scheduler.h" +#include "GpuScheduler.h" +#ifndef __CERIUM_GPU__ SchedExternTask(QuickSort); +#endif // __CERIUM_GPU__ SchedExternTask(SortSimple); SchedExternTask(SortCompat); void task_init(void) { +#ifdef __CERIUM_GPU__ + GpuSchedRegister(QUICK_SORT, "sort.cl", "sort"); +#else SchedRegisterTask(QUICK_SORT, QuickSort); +#endif + + SchedRegister(SortSimple); SchedRegister(SortCompat); }