[Beignet] [Patch V2] Refine error check in clCreateContext()

Zhigang Gong zhigang.gong at linux.intel.com
Thu Jun 6 02:40:37 PDT 2013


Pushed all the three patches, thanks.

On Thu, Jun 06, 2013 at 04:44:27PM +0800, Ruiling Song wrote:
> v2: check is also needed in clCreateContextFromType()
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  src/cl_api.c     |   27 +++++++++++++++++++++++++--
>  src/cl_context.c |   21 +--------------------
>  2 files changed, 26 insertions(+), 22 deletions(-)
> 
> diff --git a/src/cl_api.c b/src/cl_api.c
> index 6887add..a813c65 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -55,6 +55,12 @@ cl_check_device_type(cl_device_type device_type)
>    return CL_SUCCESS;
>  }
>  
> +static cl_int
> +cl_device_id_is_ok(const cl_device_id device)
> +{
> +  return device != cl_get_gt_device() ? CL_FALSE : CL_TRUE;
> +}
> +
>  cl_int
>  clGetPlatformIDs(cl_uint          num_entries,
>                   cl_platform_id * platforms,
> @@ -161,12 +167,27 @@ clCreateContext(const cl_context_properties *  properties,
>                  void *                         user_data,
>                  cl_int *                       errcode_ret)
>  {
> -  return cl_create_context(properties,
> +  cl_int err = CL_SUCCESS;
> +  cl_context context = NULL;
> +
> +  /* Assert parameters correctness */
> +  INVALID_VALUE_IF (devices == NULL);
> +  INVALID_VALUE_IF (num_devices == 0);
> +  INVALID_VALUE_IF (pfn_notify == NULL && user_data != NULL);
> +
> +  /* Now check if the user is asking for the right device */
> +  INVALID_DEVICE_IF (cl_device_id_is_ok(*devices) == CL_FALSE);
> +
> +  context = cl_create_context(properties,
>                             num_devices,
>                             devices,
>                             pfn_notify,
>                             user_data,
> -                           errcode_ret);
> +                           &err);
> +error:
> +  if (errcode_ret)
> +    *errcode_ret = err;
> +  return context;
>  }
>  
>  cl_context
> @@ -181,6 +202,8 @@ clCreateContextFromType(const cl_context_properties *  properties,
>    cl_device_id devices[1];
>    cl_uint num_devices = 1;
>  
> +  INVALID_VALUE_IF (pfn_notify == NULL && user_data != NULL);
> +
>    err = cl_check_device_type(device_type);
>    if(err != CL_SUCCESS) {
>      goto error;
> diff --git a/src/cl_context.c b/src/cl_context.c
> index fc75d62..6cde988 100644
> --- a/src/cl_context.c
> +++ b/src/cl_context.c
> @@ -87,11 +87,7 @@ error:
>    return err;
>  }
>  
> -static cl_int
> -cl_device_id_is_ok(const cl_device_id device)
> -{
> -  return device != cl_get_gt_device() ? CL_FALSE : CL_TRUE;
> -}
> +
>  
>  LOCAL cl_context
>  cl_create_context(const cl_context_properties *  properties,
> @@ -106,28 +102,13 @@ cl_create_context(const cl_context_properties *  properties,
>    cl_context ctx = NULL;
>    cl_int err = CL_SUCCESS;
>  
> -  /* Assert parameters correctness */
> -  INVALID_VALUE_IF (devices == NULL);
> -  INVALID_VALUE_IF (num_devices == 0);
> -  INVALID_VALUE_IF (pfn_notify == NULL && user_data != NULL);
> -
>    /* XXX */
>    FATAL_IF (pfn_notify != NULL || user_data != NULL, "Unsupported call back");
>    FATAL_IF (num_devices != 1, "Only one device is supported");
>  
>    /* Check that we are getting the right platform */
> -//  if (UNLIKELY((err = cl_context_properties_is_ok(properties)) != CL_SUCCESS))
> -//    goto error;
> -
>    if (UNLIKELY(((err = cl_context_properties_process(properties, &props)) != CL_SUCCESS)))
>      goto error;
> -  /* platform = intel_platform; */
> -
> -  /* Now check if the user is asking for the right device */
> -  if (UNLIKELY(cl_device_id_is_ok(*devices) == CL_FALSE)) {
> -    err = CL_INVALID_DEVICE;
> -    goto error;
> -  }
>  
>    /* We are good */
>    if (UNLIKELY((ctx = cl_context_new(&props)) == NULL)) {
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list