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] --- libopencl/nvopencl_wrapper.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'libopencl') 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