From 7b6c2f6dad0bc4c892788e495c75f169c6917bd5 Mon Sep 17 00:00:00 2001 From: Wilson Fung Date: Wed, 7 Nov 2012 05:40:42 -0800 Subject: nvopencl_wrapper now works on machine with both AMD and NVIDIA GPUs. It will automatically compile the OpenCL kernels on the NVIDIA platform. [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 14558] --- CHANGES | 5 ++++- libopencl/nvopencl_wrapper.cc | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 8119f29..d46de2b 100644 --- a/CHANGES +++ b/CHANGES @@ -25,7 +25,10 @@ Version 3.1.1+edits (development branch) versus 3.1.1 '=' and ';'. This allow options with a long string of sub-options (e.g. DRAM timing) to have a more friendly format. - Changed the DRAM timing option to a more reader-friendly format. -- Add support for the PTX v3 codes generated by new OpenCL drivers. +- Added support for the PTX version 3.0 codes generated by NVIDIA OpenCL + drivers newer than version 256.40. +- nvopencl_wrapper now works on machine with both AMD and NVIDIA GPUs. It will + automatically compile the OpenCL Kernels via the NVIDIA platform. - Bug Fixes: - Fixed a compile error that happens with newer gcc/g++ versions (4.7.1) - Fixed a bug with the association between cuobjdump output and cubin diff --git a/libopencl/nvopencl_wrapper.cc b/libopencl/nvopencl_wrapper.cc index 73e60bb..09d83c6 100644 --- a/libopencl/nvopencl_wrapper.cc +++ b/libopencl/nvopencl_wrapper.cc @@ -130,16 +130,29 @@ int main(int argc, const char **argv) 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); + unsigned use_platform = 0; + if (num_platforms > 1) { + char platformName[1024]; + printf("%s: Multiple OpenCL platforms found. Searching for compatible platform...\n",PREAMBLE); + for (unsigned p = 0; p < num_platforms; p++) { + errcode = clGetPlatformInfo(platforms[p], CL_PLATFORM_NAME, 1024, &platformName, NULL); + if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformInfo returned %d",errcode); + printf("%s: OpenCL platform \'%s\'\n",PREAMBLE, platformName); + if (strstr(platformName, "NVIDIA") != NULL) { + use_platform = p; + } + } + } + errcode = clGetPlatformInfo(platforms[use_platform], CL_PLATFORM_NAME, 1024, &buffer, NULL); if ( errcode != CL_SUCCESS ) myexit(3,"clGetPlatformInfo returned %d",errcode); printf("%s: Generating PTX using OpenCL platform \'%s\'\n",PREAMBLE,buffer); - errcode = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices); + errcode = clGetDeviceIDs(platforms[use_platform], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices); if ( errcode != CL_SUCCESS ) myexit(4,"clGetDeviceIDs returned %d",errcode); printf("%s: found %u native OpenCL devices\n",PREAMBLE,num_devices); 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); + errcode = clGetDeviceIDs(platforms[use_platform], 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); -- cgit v1.3