Mercurial > hg > Game > Cerium
changeset 1454:5b79077e4e1f draft
fix GpuRegistTaskTest
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 29 Apr 2012 19:21:26 +0900 |
parents | 756470aab7b3 |
children | 2b886dcc0e7d |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuThreads.cc TaskManager/Gpu/GpuThreads.h TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc |
diffstat | 4 files changed, 62 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Wed Apr 25 20:44:38 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Sun Apr 29 19:21:26 2012 +0900 @@ -20,7 +20,7 @@ // Get OpenCL infomation GpuThreads* gputhreads = GpuThreads::getInstance(); cl_context& context = gputhreads->context; - cl_command_queue& command_queue = gputhreads->command_queue; + cl_command_queue command_queue = gputhreads->command_queue; cl_int ret; if ((memaddr)params_addr == (memaddr)MY_SPE_COMMAND_EXIT) { @@ -56,8 +56,9 @@ gpu_register_task(int cmd, const char* filename, const char* functionname) { GpuThreads* gputhreads = GpuThreads::getInstance(); - cl_context& context = gputhreads->context; - cl_device_id& device_id = gputhreads->device_id; + // gputhreads->init(); + cl_context context = gputhreads->context; + cl_device_id device_id = gputhreads->device_id; int fp; char *source_str; @@ -76,6 +77,7 @@ if (!size) { fprintf(stderr, "Failed to load kernel.\n"); + exit(1); } source_str = (char*)malloc(size); @@ -92,7 +94,7 @@ cl_kernel *kernel = new cl_kernel; *kernel = clCreateKernel(program, functionname, &ret); - + task_list[cmd].run = NULL; task_list[cmd].load = NULL; task_list[cmd].wait = NULL;
--- a/TaskManager/Gpu/GpuThreads.cc Wed Apr 25 20:44:38 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.cc Sun Apr 29 19:21:26 2012 +0900 @@ -33,7 +33,7 @@ args->scheduler = new GpuScheduler(); args->useRefDma = use_refdma; - pthread_create(threads, NULL, &gpu_thread_run, args); + // pthread_create(threads, NULL, &gpu_thread_run, args); }
--- a/TaskManager/Gpu/GpuThreads.h Wed Apr 25 20:44:38 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.h Sun Apr 29 19:21:26 2012 +0900 @@ -38,7 +38,7 @@ cl_device_id device_id; cl_uint ret_num_platforms; cl_uint ret_num_devices; - cl_context context; + cl_context context ; cl_command_queue command_queue; cl_int ret;
--- a/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc Wed Apr 25 20:44:38 2012 +0900 +++ b/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc Sun Apr 29 19:21:26 2012 +0900 @@ -1,9 +1,10 @@ #include <stdio.h> #include <OpenCL/opencl.h> -#include "GpuThreads.h" +#include <fcntl.h> +#include <sys/stat.h> #include "GpuScheduler.h" #include "CellTaskManagerImpl.h" - +#include "GpuThreads.h" #define DEFAULT 5 extern void gpu_register_task(int, const char*, const char*); @@ -19,78 +20,93 @@ void tester(int *indata,int *outdata, int num){ + //チェック - int check; + int check = 0; for (int c=0; c<num; c++){ if(outdata[c] == indata[c]*2){ + // printf("outdata:%d indata:%d\n\n",outdata[c],indata[c]); check++; + }else { + printf("\n\n incorrect number! outdata[%d]:%d indata[%d]:%d\n\n",c,outdata[c],c,indata[c]); } - printf("Computed '%d/%d' correct values",check,num); } + printf("Computed '%d/%d' correct values\n",check,num); } void test(int task_array_num){ - - GpuThreads* gpuThreads = GpuThreads::getInstance(); - gpuThreads->init(); + + int cmd = 1; + GpuThreads* gputhreads = GpuThreads::getInstance(); + gputhreads->init(); + GpuSchedRegister(cmd, "twice.cl", "twice"); + cl_platform_id platform_id = NULL; + cl_uint ret_num_platforms = NULL; + cl_device_id device_id = NULL; + cl_uint ret_num_devices = NULL; + cl_int ret; + clGetPlatformIDs(1, &platform_id, &ret_num_platforms); + clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, + &ret_num_devices); + cl_context context = gputhreads->context; + + cl_command_queue command_queue = gputhreads->command_queue; + int *indata,*outdata; + indata = new int[task_array_num]; + outdata = new int[task_array_num]; 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 = gpu_register_task->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_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); - + 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); + + cl_kernel kernel = NULL; + 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"); - free(indata); - free(outdata); - clReleaseCommandQueue(command_queue); - clReleaseContext(context); - tester(indata,outdata,count); - delete gpuThreads; + delete [] indata; + delete [] outdata; + clReleaseCommandQueue(command_queue); + clReleaseContext(context); + clReleaseKernel(kernel); + + } int main(int argc, char* argv[]) { int task_array_num = DEFAULT; - - if ( argv[1]){ - task_array_num = atoi(argv[1]); - // 無効な引数ならデフォルトの値として5を設定 + if (argc > 1){ + if(atoi(argv[1])){ + task_array_num = atoi(argv[1]); + } } test(task_array_num); printf("regist task succeed\n");