Mercurial > hg > Game > Cerium
changeset 1478:beda5f2f88ce draft
remove singleton
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Jul 2012 05:47:14 +0900 |
parents | 5ca4e9469c65 |
children | 163220e54cc0 |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h TaskManager/Gpu/GpuThreads.h TaskManager/kernel/ppe/CpuThreads.cc TaskManager/kernel/ppe/CpuThreads.h TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc |
diffstat | 6 files changed, 50 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Fri Jul 20 05:47:14 2012 +0900 @@ -35,8 +35,10 @@ return ; } + TaskListPtr tasklist ; + while (params_addr) { - TaskListPtr tasklist = (TaskListPtr)connector->dma_load(this, params_addr, + tasklist = (TaskListPtr)connector->dma_load(this, params_addr, sizeof(TaskList), DMA_READ_TASKLIST); @@ -76,10 +78,8 @@ } void -gpu_register_task(int cmd, const char* filename, const char* functionname) +gpu_register_task(GpuThreads *gputhreads,int cmd, const char* filename, const char* functionname) { - GpuThreads* gputhreads = GpuThreads::getInstance(); - //gputhreads->init(); cl_context context = gputhreads->context; cl_device_id device_id = gputhreads->device_id;
--- a/TaskManager/Gpu/GpuScheduler.h Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/Gpu/GpuScheduler.h Fri Jul 20 05:47:14 2012 +0900 @@ -35,5 +35,5 @@ #endif -#define GpuSchedRegister(str, filename, functionname) \ - gpu_register_task(str, filename, functionname); +#define GpuSchedRegister(gputhreads, str, filename, functionname) \ + gpu_register_task(gputhreads, str, filename, functionname);
--- a/TaskManager/Gpu/GpuThreads.h Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/Gpu/GpuThreads.h Fri Jul 20 05:47:14 2012 +0900 @@ -34,6 +34,7 @@ void add_output_tasklist(int command, memaddr buff, int alloc_size); public: + GpuThreads(); cl_platform_id platform_id; cl_device_id device_id; cl_uint ret_num_platforms; @@ -43,8 +44,6 @@ cl_int ret; private: - GpuThreads(); - gpu_arg *args; pthread_t *threads; int use_refdma;
--- a/TaskManager/kernel/ppe/CpuThreads.cc Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.cc Fri Jul 20 05:47:14 2012 +0900 @@ -13,7 +13,7 @@ CpuThreads::CpuThreads(int num, int useRefDma, int start_id) : cpu_num(num), use_refdma(useRefDma), id_offset(start_id) { #ifdef __CERIUM_GPU__ - gpu = new GpuThreds; + gpu = new GpuThreads(); #endif threads = new pthread_t[cpu_num]; args = new cpu_thread_arg_t[cpu_num]; @@ -40,7 +40,7 @@ delete [] threads; delete [] args; #ifdef __CERIUM_GPU__ - delete gpu; + delete [] gpu; #endif }
--- a/TaskManager/kernel/ppe/CpuThreads.h Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/kernel/ppe/CpuThreads.h Fri Jul 20 05:47:14 2012 +0900 @@ -41,7 +41,7 @@ int use_refdma; int id_offset; #ifdef __CERIUM_GPU__ - GpuThreads gpu; + GpuThreads *gpu; #endif };
--- a/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc Thu Jul 19 14:03:49 2012 +0900 +++ b/TaskManager/test/GpuRegistTaskTest/GpuRegistTaskTest.cc Fri Jul 20 05:47:14 2012 +0900 @@ -5,7 +5,7 @@ #include "CellTaskManagerImpl.h" #define DEFAULT 5 -extern void gpu_register_task(int, char*, char*); +extern void gpu_register_task(GpuThreads*, int, const char*, const char*); void print_data(int *data, int size, const char *title){ @@ -19,51 +19,57 @@ } void -tester(int *indata,int *outdata, int num){ - //チェック - int check; +tester(int *indata,int *outdata, int num) +{ + + //check + 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); } + printf("Computed '%d/%d' correct values\n",check,num); + } void -test(int task_array_num){ +test(int task_array_num) +{ - GpuThreads* gpuThreads = GpuThreads::getInstance(); - gpuThreads->init(); + GpuThreads* gpuThreads = new GpuThreads(); + gpuThreads->init(); int *indata,*outdata; int count; - indata = (int *)malloc(sizeof(int)*task_array_num); - outdata = (int *)malloc(sizeof(int)*task_array_num); + + indata = new int(task_array_num); + outdata = new int(task_array_num); + + // prepare input data for (count=0; count < task_array_num ;count++) { indata[count] = count; } - printf("%d",count); - GpuSchedRegister(1,"./twice.cl","Twice"); + GpuSchedRegister(gpuThreads, 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_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); @@ -77,25 +83,28 @@ print_data(outdata, count, "after"); + tester(indata,outdata,count); - free(indata); - free(outdata); + delete [] indata; + delete [] outdata; + delete gpuThreads; clReleaseCommandQueue(command_queue); clReleaseContext(context); - - tester(indata,outdata,count); - - delete gpuThreads; + } int main(int argc, char* argv[]) { - int task_array_num; - if ( ((task_array_num = atoi(argv[1])) == 0) || argc != 1 ){ - // 無効な引数ならデフォルトの値として5を設定 - task_array_num = DEFAULT; + + int length = DEFAULT; + + if (argc > 1) { // if exist arg + if(atoi(argv[1])) {// if arg is number + length = atoi(argv[1]); + } } - test(task_array_num); - printf("regist task succeed\n"); + + test(length); + }