[Beignet] [PATCH] Fail gracefully on unsupported hardware
Yang, Rong R
rong.r.yang at intel.com
Mon Aug 11 23:54:34 PDT 2014
Yes, should return correct status. LGTM, pushed, thanks.
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Rebecca Palmer
> Sent: Friday, August 08, 2014 7:07 PM
> To: beignet at lists.freedesktop.org
> Subject: [Beignet] [PATCH] Fail gracefully on unsupported hardware
>
> If no compatible hardware is present, clGetDeviceIDs is supposed to report
> CL_DEVICE_NOT_FOUND to the caller, but in Beignet this currently ends the
> whole program with exit(-1) or assert(0). This fixes this.
>
> This is required to have a "just works" OpenCL in Debian/Ubuntu, as their
> package manager doesn't know the hardware and hence commonly will install
> Beignet on hardware that doesn't support it; returning an error allows the
> caller to try other ICDs until it finds the right one, or to run without using
> OpenCL. Previous discussion:
> http://lists.alioth.debian.org/pipermail/pkg-opencl-devel/Week-of-Mon-201402
> 17/000096.html
> http://lists.alioth.debian.org/pipermail/pkg-opencl-devel/Week-of-Mon-201402
> 17/000100.html
>
> Testing if you only have supported hardware: use a chroot, the GPU isn't visible
> from inside.
>
> Identical patch in case line wrap mangles this:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=27;filename=fail_gracefull
> y_without_hardware;att=1;bug=745363
>
> Signed-off-by: Rebecca Palmer <rebecca_palmer at zoho.com>
>
> --- beignet-0.9.3git.orig/src/cl_api.c
> +++ beignet-0.9.3git/src/cl_api.c
> @@ -170,6 +170,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.9.3git.orig/src/cl_device_data.h
> +++ beignet-0.9.3git/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.9.3git.orig/src/intel/intel_driver.c
> +++ beignet-0.9.3git/src/intel/intel_driver.c
> @@ -193,7 +193,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;
> @@ -203,7 +203,7 @@ intel_driver_open(intel_driver_t *intel,
> && props->gl_type != CL_GL_GLX_DISPLAY
> && props->gl_type != CL_GL_EGL_DISPLAY) {
> fprintf(stderr, "Unsupported gl share type %d.\n", props->gl_type);
> - exit(-1);
> + return CL_INVALID_OPERATION;
> }
>
> intel->x11_display = XOpenDisplay(NULL); @@ -239,7 +239,7 @@
> intel_driver_open(intel_driver_t *intel,
>
> if(!intel_driver_is_active(intel)) {
> fprintf(stderr, "Device open failed, aborting...\n");
> - exit(-1);
> + return CL_DEVICE_NOT_FOUND;
> }
>
> #ifdef HAS_EGL
> @@ -247,6 +247,7 @@ intel_driver_open(intel_driver_t *intel,
> assert(props->egl_display);
> }
> #endif
> + return CL_SUCCESS;
> }
>
> static void
> @@ -399,7 +400,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_context_destroy(driver);
> intel_driver_close(driver);
> @@ -426,7 +427,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;
> exit:
> return driver;
> error:
> --- beignet-0.9.3git.orig/src/intel/intel_gpgpu.c
> +++ beignet-0.9.3git/src/intel/intel_gpgpu.c
> @@ -1500,6 +1500,4 @@ intel_set_gpgpu_callbacks(int device_id)
> intel_gpgpu_get_scratch_index = intel_gpgpu_get_scratch_index_gen7;
> intel_gpgpu_post_action = intel_gpgpu_post_action_gen7;
> }
> - else
> - assert(0);
> }
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list