Mercurial > hg > Game > Cerium
changeset 1543:890cb39418ca draft
add error routine
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 13 Jan 2013 22:53:50 +0900 |
parents | 9ccfdc408d51 |
children | 5c4e3f0d372a |
files | TaskManager/Gpu/GpuError.h TaskManager/Gpu/GpuScheduler.cc TaskManager/kernel/ppe/TaskManagerImpl.cc TaskManager/kernel/ppe/TaskManagerImpl.h TaskManager/test/GpuRunTest/twice.cl |
diffstat | 5 files changed, 116 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskManager/Gpu/GpuError.h Sun Jan 13 22:53:50 2013 +0900 @@ -0,0 +1,62 @@ +const char* convert_error_status(cl_uint status){ + static const struct { + const cl_uint status; + const char *status_string; + } Error_Status[] = { + {CL_SUCCESS, "CL_SUCCESS"} + ,{CL_DEVICE_NOT_FOUND, "CL_DEVICE_NOT_FOUND"} + ,{CL_DEVICE_NOT_AVAILABLE, "CL_DEVICE_NOT_AVAILABLE"} + ,{CL_COMPILER_NOT_AVAILABLE, "CL_COMPILER_NOT_AVAILABLE"} + ,{CL_MEM_OBJECT_ALLOCATION_FAILURE, "CL_MEM_OBJECT_ALLOCATION_FAILURE"} + ,{CL_OUT_OF_RESOURCES, "CL_OUT_OF_RESOURCES"} + ,{CL_OUT_OF_HOST_MEMORY, "CL_OUT_OF_HOST_MEMORY"} + ,{CL_PROFILING_INFO_NOT_AVAILABLE, "CL_PROFILING_INFO_NOT_AVAILABLE"} + ,{CL_MEM_COPY_OVERLAP, "CL_MEM_COPY_OVERLAP"} + ,{CL_IMAGE_FORMAT_MISMATCH, "CL_IMAGE_FORMAT_MISMATCH"} + ,{CL_IMAGE_FORMAT_NOT_SUPPORTED, "CL_IMAGE_FORMAT_NOT_SUPPORTED"} + ,{CL_BUILD_PROGRAM_FAILURE, "CL_BUILD_PROGRAM_FAILURE"} + ,{CL_MAP_FAILURE, "CL_MAP_FAILURE"} + ,{CL_INVALID_VALUE, "CL_INVALID_VALUE"} + ,{CL_INVALID_DEVICE_TYPE, "CL_INVALID_DEVICE_TYPE"} + ,{CL_INVALID_PLATFORM, "CL_INVALID_PLATFORM"} + ,{CL_INVALID_DEVICE, "CL_INVALID_DEVICE"} + ,{CL_INVALID_CONTEXT, "CL_INVALID_CONTEXT"} + ,{CL_INVALID_QUEUE_PROPERTIES, "CL_INVALID_QUEUE_PROPERTIES"} + ,{CL_INVALID_COMMAND_QUEUE, "CL_INVALID_COMMAND_QUEUE"} + ,{CL_INVALID_HOST_PTR, "CL_INVALID_HOST_PTR"} + ,{CL_INVALID_MEM_OBJECT, "CL_INVALID_MEM_OBJECT"} + ,{CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"} + ,{CL_INVALID_IMAGE_SIZE, "CL_INVALID_IMAGE_SIZE"} + ,{CL_INVALID_SAMPLER, "CL_INVALID_SAMPLER"} + ,{CL_INVALID_BINARY, "CL_INVALID_BINARY"} + ,{CL_INVALID_BUILD_OPTIONS, "CL_INVALID_BUILD_OPTIONS"} + ,{CL_INVALID_PROGRAM, "CL_INVALID_PROGRAM"} + ,{CL_INVALID_PROGRAM_EXECUTABLE, "CL_INVALID_PROGRAM_EXECUTABLE"} + ,{CL_INVALID_KERNEL_NAME, "CL_INVALID_KERNEL_NAME"} + ,{CL_INVALID_KERNEL_DEFINITION, "CL_INVALID_KERNEL_DEFINITION"} + ,{CL_INVALID_KERNEL, "CL_INVALID_KERNEL"} + ,{CL_INVALID_ARG_INDEX, "CL_INVALID_ARG_INDEX"} + ,{CL_INVALID_ARG_VALUE, "CL_INVALID_ARG_VALUE"} + ,{CL_INVALID_ARG_SIZE, "CL_INVALID_ARG_SIZE"} + ,{CL_INVALID_KERNEL_ARGS, "CL_INVALID_KERNEL_ARGS"} + ,{CL_INVALID_WORK_DIMENSION, "CL_INVALID_WORK_DIMENSION"} + ,{CL_INVALID_WORK_GROUP_SIZE, "CL_INVALID_WORK_GROUP_SIZE"} + ,{CL_INVALID_WORK_ITEM_SIZE, "CL_INVALID_WORK_ITEM_SIZE"} + ,{CL_INVALID_GLOBAL_OFFSET, "CL_INVALID_GLOBAL_OFFSET"} + ,{CL_INVALID_EVENT_WAIT_LIST, "CL_INVALID_EVENT_WAIT_LIST"} + ,{CL_INVALID_EVENT, "CL_INVALID_EVENT"} + ,{CL_INVALID_OPERATION, "CL_INVALID_OPERATION"} + ,{CL_INVALID_GL_OBJECT, "CL_INVALID_GL_OBJECT"} + ,{CL_INVALID_BUFFER_SIZE, "CL_INVALID_BUFFER_SIZE"} + ,{CL_INVALID_MIP_LEVEL, "CL_INVALID_MIP_LEVEL"} + ,{0, NULL} + }; + const char* message; + + for(int i=0; Error_Status[i].status_string !=NULL; i++){ + if (Error_Status[i].status == status) { + message = Error_Status[i].status_string; + } + } + return message; +}
--- a/TaskManager/Gpu/GpuScheduler.cc Sun Jan 13 17:55:03 2013 +0900 +++ b/TaskManager/Gpu/GpuScheduler.cc Sun Jan 13 22:53:50 2013 +0900 @@ -4,7 +4,7 @@ #include "PreRefDmaManager.h" #include "SchedTask.h" #include "stdio.h" -// +#include "GpuError.h" #include "ListData.h" #include <fcntl.h> #include <sys/stat.h> @@ -111,10 +111,19 @@ sizeof(memaddr)*nextTask->param_count, NULL, NULL); ret = clEnqueueWriteBuffer(command_queue[cur], memparam, CL_TRUE, 0, sizeof(memaddr)*nextTask->param_count,nextTask->param(0), 0, NULL, NULL); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } + ret = clSetKernelArg(kernel, param, sizeof(memaddr),(void *)&memparam); - + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } + param++; - + cl_mem_flags mem_flag = CL_MEM_READ_ONLY; cl_mem *memin = new cl_mem[nextTask->inData_count]; if (!flag.flip) { // set input data when not flip @@ -123,7 +132,15 @@ ListElement *input_buf = nextTask->inData(i); ret = clEnqueueWriteBuffer(command_queue[cur], memin[i], CL_TRUE, 0, input_buf->size, input_buf->addr, 0, NULL, NULL); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } ret = clSetKernelArg(kernel, param, sizeof(memaddr), (void *)&memin[i]); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } param++; } @@ -142,8 +159,16 @@ ret = clEnqueueWriteBuffer(command_queue[cur], memout[i], CL_TRUE, 0, input_buf->size, input_buf->addr, 0, NULL, NULL); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } } ret = clSetKernelArg(kernel, param, sizeof(memaddr), (void *)&memout[i]); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } param++; } @@ -151,6 +176,10 @@ cl_event ev = NULL; ret = clEnqueueTask(command_queue[cur], kernel, 0, NULL, &ev); + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } // ndrange flagが0ならdim,global_work_size[0],local_work_size[0] = 1で固定に // clEnqueueNDRange // (command_queue[cur], kernel, dim, NULL,global_work_size[0],local_work_size[0],NULL&ev); @@ -159,7 +188,10 @@ ListElement *output_buf = nextTask->outData(i); ret = clEnqueueReadBuffer(command_queue[cur], memout[i], CL_TRUE, 0, output_buf->size, output_buf->addr, 1, &ev, NULL); - + if (ret<0) { + const char *msg=convert_error_status(ret); + error(msg); + } } } @@ -233,12 +265,13 @@ (const size_t *)&source_size, &ret); ret = clBuildProgram(program, 1, &device_id, NULL, NULL, NULL); - char *log = new char[1024]; - size_t s = 1024; if(ret<0) { - int build_ret = clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, s,log,NULL); - printf("\n%s\n",log); - exit(ret); + size_t size; + clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &size); + + char *log = new char[size]; + clGetProgramBuildInfo(program, device_id, CL_PROGRAM_BUILD_LOG, size, log, NULL); + error(log); } cl_kernel *kernel = new cl_kernel; *kernel = clCreateKernel(program, functionname, &ret);
--- a/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Jan 13 17:55:03 2013 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.cc Sun Jan 13 22:53:50 2013 +0900 @@ -382,6 +382,11 @@ tl = next; } } - +void +error(const char *error_message) +{ + fprintf(stderr,"%s \n",error_message); + exit(1); +} /* end */
--- a/TaskManager/kernel/ppe/TaskManagerImpl.h Sun Jan 13 17:55:03 2013 +0900 +++ b/TaskManager/kernel/ppe/TaskManagerImpl.h Sun Jan 13 22:53:50 2013 +0900 @@ -114,4 +114,5 @@ Scheduler* get_scheduler() { return scheduler; } void set_scheduler(Scheduler *s) { scheduler = s; } } __attribute__ ((aligned (DEFAULT_ALIGNMENT))); +extern void error(const char* error_message); #endif
--- a/TaskManager/test/GpuRunTest/twice.cl Sun Jan 13 17:55:03 2013 +0900 +++ b/TaskManager/test/GpuRunTest/twice.cl Sun Jan 13 22:53:50 2013 +0900 @@ -4,8 +4,8 @@ __global int *output_data) { long count = (long)data_count[0]; - for (int i = 0; i<count; i++) { - output_data[i] = input_data[i] * 2; - } - -} \ No newline at end of file + for (int i = 0; i<count; i++) { + output_data[i] = input_data[i] * 2; + } + +}