[Beignet] [PATCH 1/3] Implement clGetContextInfo

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jul 2 01:20:58 PDT 2013


LGTM, pushed, thanks.
On Mon, Jul 01, 2013 at 01:46:19PM +0800, Ruiling Song wrote:
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  src/cl_api.c     |   41 +++++++++++++++++++++++------------------
>  src/cl_context.c |   14 +++++++++++---
>  src/cl_context.h |    2 ++
>  3 files changed, 36 insertions(+), 21 deletions(-)
> 
> diff --git a/src/cl_api.c b/src/cl_api.c
> index 9467a48..b3d8f71 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -279,25 +279,30 @@ clGetContextInfo(cl_context      context,
>                   void *          param_value,
>                   size_t *        param_value_size_ret)
>  {
> -  switch (param_name) {
> -    case CL_CONTEXT_DEVICES:
> -      if (param_value) {
> -        if (param_value_size < sizeof(cl_device_id))
> -          return CL_INVALID_VALUE;
> -          cl_device_id *device_list = (cl_device_id*)param_value;
> -          device_list[0] = context->device;
> -          if (param_value_size_ret)
> -            *param_value_size_ret = sizeof(cl_device_id);
> -          return CL_SUCCESS;
> -        }
> -        if (param_value_size_ret) {
> -          *param_value_size_ret = sizeof(cl_device_id);
> -          return CL_SUCCESS;
> -        }
> -    default:
> -      NOT_IMPLEMENTED;
> +  cl_int err = CL_SUCCESS;
> +  CHECK_CONTEXT (context);
> +
> +  if (param_name == CL_CONTEXT_DEVICES) {
> +    FILL_GETINFO_RET (cl_device_id, 1, &context->device, CL_SUCCESS);
> +  } else if (param_name == CL_CONTEXT_NUM_DEVICES) {
> +    cl_uint n = 1;
> +    FILL_GETINFO_RET (cl_uint, 1, &n, CL_SUCCESS);
> +  } else if (param_name == CL_CONTEXT_REFERENCE_COUNT) {
> +    cl_uint ref = context->ref_n;
> +    FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
> +  } else if (param_name == CL_CONTEXT_PROPERTIES) {
> +    if(context->prop_len > 0) {
> +      FILL_GETINFO_RET (cl_context_properties, context->prop_len, context->prop_user, CL_SUCCESS);
> +    } else {
> +      cl_context_properties n = 0;
> +      FILL_GETINFO_RET (cl_context_properties, 1, &n, CL_SUCCESS);
> +    }
> +  } else {
> +    return CL_INVALID_VALUE;
>    }
> -  return 0;
> +
> +error:
> +  return err;
>  }
>  
>  cl_command_queue
> diff --git a/src/cl_context.c b/src/cl_context.c
> index 0331151..338706b 100644
> --- a/src/cl_context.c
> +++ b/src/cl_context.c
> @@ -34,10 +34,11 @@
>  #include <stdlib.h>
>  #include <stdint.h>
>  #include <assert.h>
> +#include <string.h>
>  
>  static cl_int
>  cl_context_properties_process(const cl_context_properties *prop,
> -                              struct _cl_context_prop *cl_props)
> +                              struct _cl_context_prop *cl_props, cl_uint * prop_len)
>  {
>    cl_int err = CL_SUCCESS;
>  
> @@ -81,6 +82,7 @@ cl_context_properties_process(const cl_context_properties *prop,
>        goto error;
>      }
>      prop += 2;
> +    *prop_len += 2;
>    }
>  exit:
>  error:
> @@ -101,13 +103,13 @@ cl_create_context(const cl_context_properties *  properties,
>    struct _cl_context_prop props;
>    cl_context ctx = NULL;
>    cl_int err = CL_SUCCESS;
> -
> +  cl_uint prop_len = 0;
>    /* 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_process(properties, &props)) != CL_SUCCESS)))
> +  if (UNLIKELY(((err = cl_context_properties_process(properties, &props, &prop_len)) != CL_SUCCESS)))
>      goto error;
>  
>    /* We are good */
> @@ -116,6 +118,11 @@ cl_create_context(const cl_context_properties *  properties,
>      goto error;
>    }
>  
> +  if(properties != NULL && prop_len > 0) {
> +    TRY_ALLOC (ctx->prop_user, CALLOC_ARRAY(cl_context_properties, prop_len));
> +    memcpy(ctx->prop_user, properties, sizeof(cl_context_properties)*prop_len);
> +  }
> +  ctx->prop_len = prop_len;
>    /* Attach the device to the context */
>    ctx->device = *devices;
>  
> @@ -171,6 +178,7 @@ cl_context_delete(cl_context ctx)
>    assert(ctx->programs == NULL);
>    assert(ctx->buffers == NULL);
>    assert(ctx->drv);
> +  cl_free(ctx->prop_user);
>    cl_driver_delete(ctx->drv);
>    ctx->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
>    cl_free(ctx);
> diff --git a/src/cl_context.h b/src/cl_context.h
> index 5dff2ef..80bf777 100644
> --- a/src/cl_context.h
> +++ b/src/cl_context.h
> @@ -68,6 +68,8 @@ struct _cl_context {
>    pthread_mutex_t sampler_lock;     /* To allocate and deallocate samplers */
>    uint32_t ver;                     /* Gen version */
>    struct _cl_context_prop props;
> +  cl_context_properties * prop_user; /* a copy of user passed context properties when create context */
> +  cl_uint                 prop_len;  /* count of the properties */
>  };
>  
>  /* Implement OpenCL function */
> -- 
> 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