Package: beignet
Version: 0.8-1
Tags: patch

As discussed earlier [0-1], if no compatible hardware is present clGetDeviceIDs should report this to the caller (allowing it to try another ICD if more than one is installed, or to continue without using OpenCL), but in beignet it instead calls exit(-1). This fixes this.

Warning: I don't have any Intel GPUs to test whether it still works when the hardware is present.

[0] http://lists.alioth.debian.org/pipermail/pkg-opencl-devel/Week-of-Mon-20140217/000096.html [1] http://lists.alioth.debian.org/pipermail/pkg-opencl-devel/Week-of-Mon-20140217/000100.html
Description: If no device, return CL_DEVICE_NOT_FOUND instead of exiting

If no Intel GPU is present, beignet currently exits on
clGetDeviceIDs.  This patch instead returns CL_DEVICE_NOT_FOUND,
allowing the calling application to decide what to do
(e.g. try a different platform).

Author: Rebecca Palmer
Forwarded: no

--- beignet-0.8.orig/src/cl_api.c
+++ beignet-0.8/src/cl_api.c
@@ -167,6 +167,7 @@ cl_check_device_type(cl_device_type devi
 static cl_int
 cl_device_id_is_ok(const cl_device_id device)
 {
+  if(UNLIKELY(device == NULL)) return CL_FALSE;
   return device != cl_get_gt_device() ? CL_FALSE : CL_TRUE;
 }
 
--- beignet-0.8.orig/src/cl_device_id.c
+++ beignet-0.8/src/cl_device_id.c
@@ -184,7 +184,7 @@ ivb_gt2_break:
       break;
     default:
       printf("cl_get_gt_device(): error, unknown device\n");
-      exit(1);
+      ret = NULL;
   }
 
   return ret;
--- beignet-0.8.orig/src/cl_device_data.h
+++ beignet-0.8/src/cl_device_data.h
@@ -20,6 +20,8 @@
 #ifndef __CL_DEVICE_DATA_H__
 #define __CL_DEVICE_DATA_H__
 
+#define INVALID_CHIP_ID -1 //returned by intel_get_device_id if no device found
+
 #define PCI_CHIP_GM45_GM                0x2A42
 #define PCI_CHIP_IGD_E_G                0x2E02
 #define PCI_CHIP_Q45_G                  0x2E12
--- beignet-0.8.orig/src/intel/intel_driver.c
+++ beignet-0.8/src/intel/intel_driver.c
@@ -175,7 +175,7 @@ intel_driver_init(intel_driver_t *driver
 #endif /* EMULATE_GEN */
 }
 
-static void
+static cl_int
 intel_driver_open(intel_driver_t *intel, cl_context_prop props)
 {
   int cardi;
@@ -185,7 +185,7 @@ intel_driver_open(intel_driver_t *intel,
       && props->gl_type != CL_GL_GLX_DISPLAY
       && props->gl_type != CL_GL_EGL_DISPLAY) {
     printf("Unsupported gl share type %d.\n", props->gl_type);
-    exit(-1);
+    return CL_INVALID_OPERATION;
   }
 
   intel->x11_display = XOpenDisplay(NULL);
@@ -216,7 +216,7 @@ intel_driver_open(intel_driver_t *intel,
   }
   if(!intel_driver_is_active(intel)) {
     printf("Device open failed\n");
-    exit(-1);
+    return CL_DEVICE_NOT_FOUND;
   }
 
 #ifdef HAS_EGL
@@ -224,6 +224,7 @@ intel_driver_open(intel_driver_t *intel,
     assert(props->egl_display);
   }
 #endif
+  return CL_SUCCESS;
 }
 
 static void
@@ -361,7 +362,7 @@ intel_get_device_id(void)
 
   driver = intel_driver_new();
   assert(driver != NULL);
-  intel_driver_open(driver, NULL);
+  if(UNLIKELY(intel_driver_open(driver, NULL) != CL_SUCCESS)) return INVALID_CHIP_ID;
   intel_device_id = driver->device_id;
   intel_driver_close(driver);
   intel_driver_terminate(driver);
@@ -385,7 +386,7 @@ cl_intel_driver_new(cl_context_prop prop
 {
   intel_driver_t *driver = NULL;
   TRY_ALLOC_NO_ERR (driver, intel_driver_new());
-  intel_driver_open(driver, props);
+  if(UNLIKELY(intel_driver_open(driver, props) != CL_SUCCESS)) goto error;
   /* We use the first 2 slots(0,1) for all the bufs.
    * Notify the gbe this base index, thus gbe can avoid conflicts
    * when it allocates slots for images*/

Reply via email to