Mercurial > hg > Game > Cerium
changeset 1448:3ee29c1733d1 draft
separate function for GpuTest
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 24 Apr 2012 13:52:41 +0900 |
parents | e8ff87511f46 |
children | a193b282952b |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/kernel/schedule/Scheduler.cc TaskManager/test/GpuThreadTest/GpuThreadsTest.cc |
diffstat | 3 files changed, 81 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Mon Apr 23 22:53:59 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Tue Apr 24 13:52:41 2012 +0900 @@ -39,9 +39,9 @@ clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, nextTask->r_size, nextTask->rbuf, 0, NULL, NULL); } // カーネル引数の設定 - + clEnqueueTask(command_queue, kernel, 0, NULL, NULL); - + if ( nextTask->w_size != 0 ) { cl_mem memobj = clCreateBuffer(context, CL_MEM_READ_WRITE, nextTask->w_size, NULL, &ret); clEnqueueWriteBuffer(command_queue, memobj, CL_TRUE, 0, nextTask->w_size, nextTask->wbuf, 0, NULL, NULL);
--- a/TaskManager/kernel/schedule/Scheduler.cc Mon Apr 23 22:53:59 2012 +0900 +++ b/TaskManager/kernel/schedule/Scheduler.cc Tue Apr 24 13:52:41 2012 +0900 @@ -94,18 +94,18 @@ SchedTaskBase* task3 = new SchedNop(); // main loop do { - - task1->read(); - task2->exec(); - task3->write(); - - delete task3; - + + task1->read(); + task2->exec(); + task3->write(); + + delete task3; + task3 = task2; task2 = task1; - //SchedMailの場合、Mailの待ちが入る - task1 = task1->next(this, 0); - + //SchedMailの場合、Mailの待ちが入る + task1 = task1->next(this, 0); + } while (task1); delete task3;
--- a/TaskManager/test/GpuThreadTest/GpuThreadsTest.cc Mon Apr 23 22:53:59 2012 +0900 +++ b/TaskManager/test/GpuThreadTest/GpuThreadsTest.cc Tue Apr 24 13:52:41 2012 +0900 @@ -1,26 +1,85 @@ #include <stdio.h> +#include <OpenCL/opencl.h> #include "GpuThreads.h" #include "GpuScheduler.h" #include "CellTaskManagerImpl.h" +#define DEFAULT 5 void -tester(GpuThreads* gpuThreads){ - GpuSchedRegister(1, "twice.cl","Twice"); +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 *data,int num){ + //チェック } void -test1(){ - GpuThreads* c = GpuThreads::getInstance(); - c->init(); - tester(c); - delete c; +test(int task_array_num){ + + GpuThreads* gpuThreads = GpuThreads::getInstance(); + gpuThreads->init(); + + int *indata,*outdata; + int count; + indata = (int *)malloc(sizeof(int)*task_array_num); + outdata = (int *)malloc(sizeof(int)*task_array_num); + for (count=0; count < task_array_num ;count++) { + indata[count] = count; + } + printf("%d",count); + + GpuSchedRegister(1, "twice.cl","Twice"); + + cl_int ret; + cl_context context = gpuThreads->context; + cl_mem memobj_in, memobj_out, data_count = NULL; + memobj_in = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + memobj_out = clCreateBuffer(context, CL_MEM_READ_WRITE, sizeof(int)*count, NULL, &ret); + 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); + + print_data(indata, count, "before"); + + cl_kernel *kernel = task_list[1].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; + 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"); + + free(indata); + free(outdata); + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + tester(indata,count); + delete gpuThreads; } int main(int argc, char* argv[]) { - test1(); + int task_array_num; + if ( ((task_array_num = atoi(argv[1])) == 0) || argc != 1 ){ + // 無効な引数ならデフォルトの値として5を設定 + task_array_num = DEFAULT; + } + test(task_array_num); printf("regist task succeed\n"); } - -/* end */