[Beignet] [PATCH] add the support of clGetProgramBuildInfo

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jun 18 01:43:42 PDT 2013


Could you also provide a unit test case for this new function? Thanks.

On Mon, Jun 17, 2013 at 06:32:11PM +0800, junyan.he at linux.intel.com wrote:
> From: Junyan He <junyan.he at linux.intel.com>
> 
> CL_BUILD_IN_PROGRESS not support now
> and CL_PROGRAM_BUILD_LOG need do add the info collection
> logic in backend and not support too, just return null
> string now.
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  src/cl_api.c     |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
>  src/cl_program.c |   16 ++++++++++++++++
>  src/cl_program.h |    1 +
>  3 files changed, 64 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cl_api.c b/src/cl_api.c
> index f14bee4..1aa706c 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -741,8 +741,53 @@ clGetProgramBuildInfo(cl_program             program,
>                        void *                 param_value,
>                        size_t *               param_value_size_ret)
>  {
> -  NOT_IMPLEMENTED;
> -  return 0;
> +#define FILL_AND_RET(TYPE, ELT, VAL, RET) \
> +	if (param_value && param_value_size < sizeof(TYPE)*ELT) \
> +	    return CL_INVALID_VALUE;  \
> +	if (param_value) { \
> +	    int i = 0; \
> +	    for (; i < ELT; i++) \
> +	      *((TYPE *)param_value + i) = *(VAL + i); \
> +	} \
> +        \
> +	if (param_value_size_ret) \
> +	    param_value_size_ret = sizeof(TYPE)*ELT; \
> +	return RET;
> +
> +  cl_int err = CL_SUCCESS;
> +  char * ret_str = "";
> +
> +  CHECK_PROGRAM (program);
> +  INVALID_DEVICE_IF (device != program->ctx->device);
> +
> +  if (param_name == CL_PROGRAM_BUILD_STATUS) {
> +    cl_build_status status;
> +
> +    if (!program->is_built)
> +      status = CL_BUILD_NONE;
> +    else if (program->ker_n > 0)
> +      status = CL_BUILD_SUCCESS;
> +    else
> +      status = CL_BUILD_ERROR;
> +    // TODO: Support CL_BUILD_IN_PROGRESS ?
> +
> +    FILL_AND_RET (cl_build_status, 1, &status, CL_SUCCESS);
> +  } else if (param_name == CL_PROGRAM_BUILD_OPTIONS) {
> +    if (program->is_built && program->build_opts)
> +      ret_str = program->build_opts;
> +
> +    FILL_AND_RET (char, (strlen(ret_str)+1), ret_str, CL_SUCCESS);
> +  } else if (param_name == CL_PROGRAM_BUILD_LOG) {
> +    // TODO: need to add logs in backend when compiling.
> +    FILL_AND_RET (char, (strlen(ret_str)+1), ret_str, CL_SUCCESS);
> +  } else {
> +    return CL_INVALID_VALUE;
> +  }
> +
> +error:
> +    return err;
> +
> +#undef FILL_AND_RET
>  }
>  
>  cl_kernel
> diff --git a/src/cl_program.c b/src/cl_program.c
> index 6acf31f..0c4f146 100644
> --- a/src/cl_program.c
> +++ b/src/cl_program.c
> @@ -59,6 +59,12 @@ cl_program_delete(cl_program p)
>    /* Destroy the sources if still allocated */
>    cl_program_release_sources(p);
>  
> +  /* Release the build options. */
> +  if (p->build_opts) {
> +    cl_free(p->build_opts);
> +    p->build_opts = NULL;
> +  }
> +
>    /* Remove it from the list */
>    assert(p->ctx);
>    pthread_mutex_lock(&p->ctx->program_lock);
> @@ -269,6 +275,16 @@ cl_program_build(cl_program p, const char *options)
>  {
>    cl_int err = CL_SUCCESS;
>  
> +  if (options) {
> +    if(p->build_opts) {
> +      cl_free(p->build_opts);
> +      p->build_opts = NULL;
> +    }
> +
> +    TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
> +    memcpy(p->build_opts, options, strlen(options));
> +  }
> +
>    if (p->source_type == FROM_SOURCE) {
>      /* XXX support multiple sources later */
>      FATAL_IF (p->src_n != 1, "Only ONE source file supported");
> diff --git a/src/cl_program.h b/src/cl_program.h
> index 161d858..bee05c5 100644
> --- a/src/cl_program.h
> +++ b/src/cl_program.h
> @@ -52,6 +52,7 @@ struct _cl_program {
>    uint32_t ker_n;         /* Number of declared kernels */
>    uint32_t source_type:2; /* Built from binary, source or LLVM */
>    uint32_t is_built:1;    /* Did we call clBuildProgram on it? */
> +  char *build_opts;       /* The build options for this program */
>  };
>  
>  /* Create a empty program */
> -- 
> 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