From 7f931254bd1468c2db4fc7a954550e89c3d742f4 Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Mon, 19 Jul 2010 09:30:26 -0800 Subject: updating opencl wrapper support [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6892] --- libopencl/nvopencl_wrapper.cc | 53 ++++++++++++++++++++++++++++++++++------- libopencl/opencl_runtime_api.cc | 21 ++++++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/libopencl/nvopencl_wrapper.cc b/libopencl/nvopencl_wrapper.cc index e68dfca..b52354d 100644 --- a/libopencl/nvopencl_wrapper.cc +++ b/libopencl/nvopencl_wrapper.cc @@ -63,26 +63,62 @@ #include #include #include +#include +void vmyexit(int code, const char *str,va_list ap) +{ + char buffer[1024]; + snprintf(buffer,1024,"GPGPU-Sim API: nvopencl_wrapper ERROR ** %s\n", str); + vprintf(buffer,ap); + if( code ) { + exit(code); + } +} +void myexit(int code, const char *str, ... ) +{ + va_list ap; + va_start(ap,str); + vmyexit(code,str,ap); + va_end(ap); +} int main(int argc, const char **argv) { cl_context context; cl_program pgm; cl_int errcode; + cl_uint num_devices; FILE *fp = fopen(argv[1],"r"); if ( fp == NULL ) exit(1); fseek(fp,0,SEEK_END); size_t source_length = ftell(fp); - if ( source_length == 0 ) exit(2); + if ( source_length == 0 ) myexit(2,"OpenCL file is empty"); char *source = (char*)calloc(source_length+1,1); fseek(fp,0,SEEK_SET); fread(source,1,source_length,fp); - context = clCreateContextFromType(0, CL_DEVICE_TYPE_GPU, NULL, NULL, &errcode); - if ( errcode != CL_SUCCESS ) exit(3); + char buffer[1024]; + cl_uint num_platforms; + cl_platform_id* platforms; + + errcode = clGetPlatformIDs(0, NULL, &num_platforms); + if ( errcode != CL_SUCCESS ) myexit(1,"clGetPlatformaIDs returned %d",errcode); + if ( num_platforms == 0 ) myexit(2,"No OpenCL platforms found"); + platforms = (cl_platform_id*)malloc(num_platforms * sizeof(cl_platform_id)); + errcode = clGetPlatformIDs(num_platforms, platforms, NULL); + if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformIDs returned %d",errcode); + errcode = clGetPlatformInfo(platforms[0], CL_PLATFORM_NAME, 1024, &buffer, NULL); + if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformInfo returned %d",errcode); + printf("GPGPU-Sim OpenCL API: Generating PTX using OpenCL platform \'%s\'\n",buffer); + errcode = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices); + if ( errcode != CL_SUCCESS ) myexit(4,"clGetDeviceIDs returned %d",errcode); + cl_device_id *devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id) ); + errcode = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, num_devices, devices, NULL); + if ( errcode != CL_SUCCESS ) myexit(5,"clGetDeviceIDs returned %d",errcode); + context = clCreateContext(0, num_devices, devices, NULL, NULL, &errcode); + if ( errcode != CL_SUCCESS ) myexit(6,"clCreateContext returned %d",errcode); pgm = clCreateProgramWithSource(context, 1, (const char **)&source, &source_length, &errcode); - if ( errcode != CL_SUCCESS ) exit(4); + if ( errcode != CL_SUCCESS ) myexit(7,"clCreateProgramWithSource returned %d",errcode); char options[4096]; unsigned n=0; @@ -93,17 +129,16 @@ int main(int argc, const char **argv) n+= 2; } errcode = clBuildProgram(pgm, 0, NULL, options, NULL, NULL); - if ( errcode != CL_SUCCESS ) exit(5); + if ( errcode != CL_SUCCESS ) myexit(8,"clBuildProgram returned %d",errcode); size_t nbytes1=0; - cl_uint num_devices; errcode = clGetProgramInfo(pgm,CL_PROGRAM_NUM_DEVICES,sizeof(cl_uint),&num_devices,&nbytes1); - if ( errcode != CL_SUCCESS ) exit(6); + if ( errcode != CL_SUCCESS ) myexit(9,"clGetProgramInfo returned %d",errcode); size_t nbytes2=0; size_t *binary_sizes = (size_t*)calloc(num_devices,sizeof(size_t)); errcode = clGetProgramInfo(pgm,CL_PROGRAM_BINARY_SIZES,sizeof(size_t)*num_devices,binary_sizes,&nbytes2); - if ( errcode != CL_SUCCESS ) exit(7); + if ( errcode != CL_SUCCESS ) myexit(10,"clGetProgramInfo returned %d",errcode); unsigned char **binaries = (unsigned char**)calloc(num_devices,sizeof(unsigned char*)); size_t bytes_to_read = 0; @@ -115,7 +150,7 @@ int main(int argc, const char **argv) size_t nbytes3=0; errcode = clGetProgramInfo(pgm,CL_PROGRAM_BINARIES,bytes_to_read,binaries,&nbytes3); - if ( errcode != CL_SUCCESS ) exit(8); + if ( errcode != CL_SUCCESS ) myexit(11,"clGetProgramInfo returned %d",errcode); fp = fopen(argv[2],"w"); fprintf(fp,"%s",binaries[0]); diff --git a/libopencl/opencl_runtime_api.cc b/libopencl/opencl_runtime_api.cc index 22119c9..d49cc6e 100644 --- a/libopencl/opencl_runtime_api.cc +++ b/libopencl/opencl_runtime_api.cc @@ -515,6 +515,8 @@ void _cl_program::Build(const char *options) if( result != 0 ) { printf("GPGPU-Sim OpenCL API: ERROR ** while calling NVIDIA driver to convert OpenCL to PTX (%u)\n", result ); + printf("GPGPU-Sim OpenCL API: LD_LIBRARY_PATH was \'%s\'\n", nvopencl_libdir); + printf("GPGPU-Sim OpenCL API: command line was \'%s\'\n", commandline); exit(1); } // clean up files... @@ -662,6 +664,25 @@ clCreateContextFromType(cl_context_properties * properties, return ctx; } +extern CL_API_ENTRY cl_context CL_API_CALL +clCreateContext( const cl_context_properties * properties, + cl_uint num_devices, + const cl_device_id *devices, + void (*pfn_notify)(const char *, const void *, size_t, void *), + void * user_data, + cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0 +{ + GPGPUSIM_INIT + if( properties != NULL ) { + printf("GPGPU-Sim OpenCL API: do not know how to use properties in %s\n", __my_func__ ); + exit(1); + } + if( errcode_ret ) + *errcode_ret = CL_SUCCESS; + cl_context ctx = new _cl_context; + return ctx; +} + extern CL_API_ENTRY cl_int CL_API_CALL clGetContextInfo(cl_context context, cl_context_info param_name, -- cgit v1.3