Mercurial > hg > Game > Cerium
changeset 1807:8f7052d19157 draft
minor fix
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 10 Dec 2013 19:14:48 +0900 |
parents | a77876642bb3 |
children | c25aa7edd1ba |
files | TaskManager/Gpu/GpuScheduler.cc TaskManager/Gpu/GpuScheduler.h |
diffstat | 2 files changed, 47 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/TaskManager/Gpu/GpuScheduler.cc Tue Dec 10 16:51:58 2013 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Tue Dec 10 19:14:48 2013 +0900 @@ -63,31 +63,34 @@ } void -GpuScheduler::initGpuBuffer(GpuBufferPtr m) { - m->size = 0; - m->alllocate_size = 64; - m->buf = (cl_mem*)malloc(m->alllocate_size*sizeof(cl_mem*)); - m->event = (cl_event*)malloc(m->alllocate_size*sizeof(cl_event*)); +GpuScheduler::initGpuBuffer(GpuBuffer m) { + m.size = 0; + m.allocate_size = 64; + m.buf = (cl_mem*)malloc(m.allocate_size*sizeof(cl_mem*)); + m.event = (cl_event*)malloc(m.allocate_size*sizeof(cl_event*)); } - +void +GpuScheduler::destroyGpuBuffer(GpuBuffer m) { + // TODO +} cl_mem -GpuScheduler::createBuffer(GpuBufferPtr m, int i, cl_context context, cl_mem_flags flags, size_t size, cl_int *error) { - if (i > m->alllocate_size) { +GpuScheduler::createBuffer(GpuBuffer m, int i, cl_context context, cl_mem_flags flags, size_t size, cl_int *error) { + if (i > m.allocate_size) { // reallocate buffer size - m->allocate_size *= 2; - m->buf = (cl_mem*)realloc(m->buf, m->alllocate_size*sizeof(cl_mem*)); - m->event = (cl_event*)realloc(m->event, m->alllocate_size*sizeof(cl_event*)); + m.allocate_size *= 2; + m.buf = (cl_mem*)realloc(m.buf, m.allocate_size*sizeof(cl_mem*)); + m.event = (cl_event*)realloc(m.event, m.allocate_size*sizeof(cl_event*)); } - if (m->buf[i]) { - clReleaseMemObject(m->buf); + if (m.buf[i]) { + clReleaseMemObject(m.buf[i]); } flags |= CL_MEM_USE_HOST_PTR; - void *buf = m->buf[i]; - clCreateBuffer(context, flags, size, buf, error); + void *buf = m.buf[i]; + return clCreateBuffer(context, flags, size, buf, error); } #define NOP_REPLY NULL @@ -97,7 +100,7 @@ * kernel_event, memout_event */ void -GpuScheduler::wait_for_event(cl_event* kernel_event, GpuBufferPtr memout, memaddr* reply,TaskListPtr taskList, int cur) { +GpuScheduler::wait_for_event(cl_event* kernel_event, GpuBufferPtr memout, memaddr* reply, TaskListPtr *taskList, int cur) { if (kernel_event[1-cur] == NOP_REPLY) { if(reply[1-cur]) { connector->mail_write(reply[1-cur]); @@ -109,12 +112,14 @@ error(convert_error_status(ret)); } clReleaseEvent(kernel_event[1-cur]); - kernel_evetn[1-cur] = 0; + kernel_event[1-cur] = 0; } if (memout[1-cur].size > 0) { - int ret=clWaitForEvents(memout[1-cur].size, &memout[1-cur].event); - if (ret<0) { - error(convert_error_status(ret)); + for (int i=0; i < memout[1-cur].size; i++) { + int ret=clWaitForEvents(memout[1-cur].size, &memout[1-cur].event[i]); + if (ret<0) { + error(convert_error_status(ret)); + } } for (int i=0; i < memout[1-cur].size; i++) { clReleaseEvent(memout[1-cur].event[i]); @@ -125,14 +130,13 @@ connector->mail_write(reply[1-cur]); reply[1-cur]=0; } - - if (tasklist[1-cur]!=NULL) { + if (taskList[1-cur]!=NULL){ cl_ulong start = 0; cl_ulong end = 0; - clGetEventProfilingInfo(event[1-cur],CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL); - clGetEventProfilingInfo(event[1-cur],CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end, NULL); - tasklist[1-cur]->task_start_time = start; - tasklist[1-cur]->task_end_time = end; + clGetEventProfilingInfo(kernel_event[1-cur],CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL); + clGetEventProfilingInfo(kernel_event[1-cur],CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end, NULL); + taskList[1-cur]->task_start_time = start; + taskList[1-cur]->task_end_time = end; } } @@ -159,8 +163,8 @@ clFinish(command_queue); if (kernel[0]) clReleaseKernel(kernel[0]); if (kernel[1]) clReleaseKernel(kernel[1]); - if (kernel_event[0] && kernel_event[0]!=NOP_REPLY) clReleaseEvent(event[0]); - if (kernel_event[1] && kernel_event[1]!=NOP_REPLY) clReleaseEvent(event[1]); + if (kernel_event[0] && kernel_event[0]!=NOP_REPLY) clReleaseEvent(kernel_event[0]); + if (kernel_event[1] && kernel_event[1]!=NOP_REPLY) clReleaseEvent(kernel_event[1]); destroyGpuBuffer(memout[cur-1]); destroyGpuBuffer(memout[cur]); destroyGpuBuffer(memin[cur]); @@ -246,7 +250,7 @@ const char *msg=convert_error_status(ret); error(msg); } - ret = clEnqueueWriteBuffer(command_queue, memin[cur][i+1], CL_TRUE, 0, + ret = clEnqueueWriteBuffer(command_queue, memin[cur].buf[i+1], CL_TRUE, 0, input_buf->size, input_buf->addr, 0, NULL, &memin[cur].event[i+1]); if (ret<0) { @@ -284,7 +288,7 @@ ret = clEnqueueWriteBuffer(command_queue, memout[cur].buf[i+1], CL_TRUE, 0, input_buf->size, input_buf->addr, - 0, NULL, memout[cur].event[i+1]); + 0, NULL, &memout[cur].event[i+1]); if (ret<0) { const char *msg=convert_error_status(ret); error(msg); @@ -298,8 +302,8 @@ param++; } - memin[cur].size = taskList[cur]->inDataSize+1; // +1 means param - memout[cur].size = taskList[cur]->outDataSize; + memin[cur].size = nextTask->inData_count+1; // +1 means param + memout[cur].size = nextTask->outData_count; tasklist[cur]->task_start_time = gettime(); if (tasklist[cur]->dim > 0) { ret = clEnqueueNDRangeKernel(command_queue, kernel[cur], tasklist[cur]->dim, @@ -318,7 +322,8 @@ ListElement *output_buf = flag.flip? nextTask->inData(i) :nextTask->outData(i); if (output_buf->size==0) break; ret = clEnqueueReadBuffer(command_queue, memout[cur].buf[i], CL_FALSE, 0, - output_buf->size, output_buf->addr, 1, kernel_event[cur], memout[cur].event[i]); + output_buf->size, output_buf->addr, 1, &kernel_event[cur], &memout[cur].event[i]); + if (ret<0) { const char *msg=convert_error_status(ret); error(msg); @@ -328,15 +333,14 @@ tasklist[cur]->task_end_time = gettime(); if (ret<0) { - const char *msg=convert_error_status(ret); - error(msg); + error(convert_error_status(ret)); nop_reply: - event[cur] = NOP_REPLY; + kernel_event[cur] = NOP_REPLY; kernel[cur] = 0; - memout[cur] = 0; - memin[cur] = 0; + memout[cur].buf = 0; + memin[cur].buf = 0; } - +nop_skip: reply[cur] = (memaddr)tasklist[cur]->waiter; // wait kernel[1-cur] and write[1-cur]
--- a/TaskManager/Gpu/GpuScheduler.h Tue Dec 10 16:51:58 2013 +0900 +++ b/TaskManager/Gpu/GpuScheduler.h Tue Dec 10 19:14:48 2013 +0900 @@ -27,7 +27,7 @@ virtual ~GpuScheduler(); void init_impl(int useRefDma); void init_gpu(); - void wait_for_event(cl_event* event,memaddr* reply,int cur); + void wait_for_event(cl_event* event,GpuBufferPtr m, memaddr* reply,TaskListPtr* taskList,int cur); void run(); void mail_write_from_host(memaddr data) { @@ -58,7 +58,9 @@ private: FifoDmaManager *fifoDmaManager; int load_kernel(int cmd); - cl_mem createBuffer(GpuBufferPtr m, int i, cl_context context, cl_mem_flags flags, size_t size, cl_int *error); + cl_mem createBuffer(GpuBuffer m, int i, cl_context context, cl_mem_flags flags, size_t size, cl_int *error); + void initGpuBuffer(GpuBuffer m); + void destroyGpuBuffer(GpuBuffer m); }; #define GpuSchedRegister(str, filename, functionname) \