From d6ae8065f7c422300dba3b6256f4ace53b39a092 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Nov 2010 11:04:05 +0100 Subject: Handle multiple GPUs --- src/cl-utils.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) (limited to 'src/cl-utils.c') diff --git a/src/cl-utils.c b/src/cl-utils.c index a7d23371..1b7b9811 100644 --- a/src/cl-utils.c +++ b/src/cl-utils.c @@ -48,18 +48,87 @@ const char *clError(cl_int err) } -cl_device_id get_first_dev(cl_context ctx) +static char *get_device_string(cl_device_id dev, cl_device_info info) { - cl_device_id dev; + int r; + size_t size; + char *val; + + r = clGetDeviceInfo(dev, info, 0, NULL, &size); + if ( r != CL_SUCCESS ) { + ERROR("Couldn't get device vendor size: %s\n", + clError(r)); + return NULL; + } + val = malloc(size); + r = clGetDeviceInfo(dev, info, size, val, NULL); + if ( r != CL_SUCCESS ) { + ERROR("Couldn't get dev vendor: %s\n", clError(r)); + return NULL; + } + + return val; +} + + +cl_device_id get_cl_dev(cl_context ctx, int n) +{ + cl_device_id *dev; cl_int r; + size_t size; + int i, num_devs; - r = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, sizeof(dev), &dev, NULL); + /* Get the required size of the array */ + r = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, 0, NULL, &size); + if ( r != CL_SUCCESS ) { + ERROR("Couldn't get array size for devices: %s\n", clError(r)); + return 0; + } + + dev = malloc(size); + r = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, size, dev, NULL); if ( r != CL_SUCCESS ) { ERROR("Couldn't get device: %s\n", clError(r)); return 0; } + num_devs = size/sizeof(cl_device_id); + + if ( n >= num_devs ) { + ERROR("Device ID out of range\n"); + return 0; + } + + if ( n < 0 ) { + + STATUS("Available devices:\n"); + for ( i=0; i