[Beignet] [PATCH 1/3] Implement api clCreateKernelsInProgram.

Yang, Rong R rong.r.yang at intel.com
Wed Oct 9 20:30:41 PDT 2013


Yes, I have send the version2.

-----Original Message-----
From: Zhigang Gong [mailto:zhigang.gong at linux.intel.com] 
Sent: Wednesday, October 09, 2013 5:34 PM
To: Yang, Rong R
Cc: beignet at lists.freedesktop.org
Subject: Re: [Beignet] [PATCH 1/3] Implement api clCreateKernelsInProgram.

On Wed, Oct 09, 2013 at 02:36:25PM +0800, Yang Rong wrote:
> 
> Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> ---
>  src/cl_api.c     | 22 ++++++++++++++++++++--
>  src/cl_program.c | 21 +++++++++++++++++++++  src/cl_program.h |  3 
> +++
>  3 files changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cl_api.c b/src/cl_api.c index ded0e0c..42948e8 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -981,8 +981,26 @@ clCreateKernelsInProgram(cl_program      program,
>                           cl_kernel *     kernels,
>                           cl_uint *       num_kernels_ret)
>  {
> -  NOT_IMPLEMENTED;
> -  return 0;
> +  cl_int err = CL_SUCCESS;
> +  cl_int ret = 0;
> +
> +  CHECK_PROGRAM (program);
> +  if (program->is_built == CL_FALSE) {
> +    err = CL_INVALID_PROGRAM_EXECUTABLE;
> +    goto error;
> +  }
> +  if (kernels && num_kernels < program->ker_n) {
> +    err = CL_INVALID_VALUE;
> +    goto error;
> +  }
> +
> +  ret = cl_program_create_kernels_in_program(program, kernels);
> +
> +  if(num_kernels_ret)
> +    *num_kernels_ret = ret;
> +
> +error:
> +  return err;
>  }
>  
>  cl_int
> diff --git a/src/cl_program.c b/src/cl_program.c index 
> a0e0104..a7caca8 100644
> --- a/src/cl_program.c
> +++ b/src/cl_program.c
> @@ -386,3 +386,24 @@ error:
>    goto exit;
>  }
>  

According to OpenCL spec:
  num_kernels_ret is the number of kernels in program. If num_kernels_ret is NULL, it is ignored.

So the following function seems not fully comply with the spec. The function returns the count of successfully allocated kernels. But according the spec, it should return p->ker_n if it can allocate all kernels successfully. Otherwise, it should generate CL_OUT_OF_HOST_MEMORY error code.

Any thoughts?

> +LOCAL cl_int
> +cl_program_create_kernels_in_program(cl_program p, cl_kernel* ker) {
> +  uint32_t i = 0;
> +  
> +  if(ker == NULL)
> +    return p->ker_n;
> +  
> +  for (i = 0; i < p->ker_n; ++i) {
> +    TRY_ALLOC_NO_ERR(ker[i], cl_kernel_dup(p->ker[i]));    
> +  }
> +  
> +exit:
> +  return i;
> +
> +error:
> +  cl_kernel_delete(ker[i]);
> +  goto exit;
> +  
> +}
> +
> diff --git a/src/cl_program.h b/src/cl_program.h index 
> de82fd5..2cb547a 100644
> --- a/src/cl_program.h
> +++ b/src/cl_program.h
> @@ -68,6 +68,9 @@ extern void cl_program_add_ref(cl_program);
>  /* Create a kernel for the OCL user */  extern cl_kernel 
> cl_program_create_kernel(cl_program, const char*, cl_int*);
>  
> +/* creates kernel objects for all kernel functions in program. */ 
> +extern cl_int cl_program_create_kernels_in_program(cl_program, 
> +cl_kernel*);
> +
>  /* Create a program from OCL source */  extern cl_program  
> cl_program_create_from_source(cl_context ctx,
> --
> 1.8.1.2
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list