[Beignet] [PATCH] Add some API's OpenCL 1.2 parameter support.
Zhigang Gong
zhigang.gong at linux.intel.com
Fri Jun 20 01:06:22 PDT 2014
LGTM, will push latter, thanks.
On Sat, Jun 21, 2014 at 12:15:44AM +0800, Yang Rong wrote:
> Support CL_PROGRAM_KERNEL_NAMES and CL_PROGRAM_NUM_KERNELS in API clGetProgramInfo,
> and CL_DOUBLE_FP_CONFIG in API clGetDeviceInfo.
> Also fix a bug of CL_MEM_HOST_PTR in API clGetMemObjectInfo.
>
> Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> ---
> src/cl_api.c | 5 +++++
> src/cl_device_id.c | 1 +
> src/cl_device_id.h | 1 +
> src/cl_gt_device.h | 1 +
> src/cl_mem.c | 3 ++-
> src/cl_program.c | 41 +++++++++++++++++++++++++++++++++++++++++
> src/cl_program.h | 6 ++++++
> 7 files changed, 57 insertions(+), 1 deletion(-)
>
> diff --git a/src/cl_api.c b/src/cl_api.c
> index d4d8d7c..31ce6bc 100644
> --- a/src/cl_api.c
> +++ b/src/cl_api.c
> @@ -1058,12 +1058,17 @@ clGetProgramInfo(cl_program program,
> } else if (param_name == CL_PROGRAM_DEVICES) {
> cl_device_id dev_id = program->ctx->device;
> FILL_GETINFO_RET (cl_device_id, 1, &dev_id, CL_SUCCESS);
> + } else if (param_name == CL_PROGRAM_NUM_KERNELS) {
> + cl_uint kernels_num = program->ker_n;
> + FILL_GETINFO_RET (cl_uint, 1, &kernels_num, CL_SUCCESS);
> } else if (param_name == CL_PROGRAM_SOURCE) {
>
> if (!program->source)
> FILL_GETINFO_RET (char, 1, &ret_str, CL_SUCCESS);
> FILL_GETINFO_RET (char, (strlen(program->source) + 1),
> program->source, CL_SUCCESS);
> + } else if(param_name == CL_PROGRAM_KERNEL_NAMES) {
> + cl_program_get_kernel_names(program, param_value_size, (char *)param_value, param_value_size_ret);
> } else if (param_name == CL_PROGRAM_BINARY_SIZES) {
> if (program->binary == NULL){
> if( program->binary_type == CL_PROGRAM_BINARY_TYPE_EXECUTABLE) {
> diff --git a/src/cl_device_id.c b/src/cl_device_id.c
> index af8e90c..771eb5c 100644
> --- a/src/cl_device_id.c
> +++ b/src/cl_device_id.c
> @@ -373,6 +373,7 @@ cl_get_device_info(cl_device_id device,
> DECL_FIELD(MEM_BASE_ADDR_ALIGN, mem_base_addr_align)
> DECL_FIELD(MIN_DATA_TYPE_ALIGN_SIZE, min_data_type_align_size)
> DECL_FIELD(SINGLE_FP_CONFIG, single_fp_config)
> + DECL_FIELD(DOUBLE_FP_CONFIG, double_fp_config)
> DECL_FIELD(GLOBAL_MEM_CACHE_TYPE, global_mem_cache_type)
> DECL_FIELD(GLOBAL_MEM_CACHELINE_SIZE, global_mem_cache_line_size)
> DECL_FIELD(GLOBAL_MEM_CACHE_SIZE, global_mem_cache_size)
> diff --git a/src/cl_device_id.h b/src/cl_device_id.h
> index a5449a7..3228a68 100644
> --- a/src/cl_device_id.h
> +++ b/src/cl_device_id.h
> @@ -61,6 +61,7 @@ struct _cl_device_id {
> cl_uint mem_base_addr_align;
> cl_uint min_data_type_align_size;
> cl_device_fp_config single_fp_config;
> + cl_device_fp_config double_fp_config;
> cl_device_mem_cache_type global_mem_cache_type;
> cl_uint global_mem_cache_line_size;
> cl_ulong global_mem_cache_size;
> diff --git a/src/cl_gt_device.h b/src/cl_gt_device.h
> index b8bda5e..08785a6 100644
> --- a/src/cl_gt_device.h
> +++ b/src/cl_gt_device.h
> @@ -51,6 +51,7 @@
> .mem_base_addr_align = sizeof(cl_long) * 16 * 8,
> .min_data_type_align_size = sizeof(cl_long) * 16,
> .single_fp_config = 0, /* XXX */
> +.double_fp_config = 0,
> .global_mem_cache_type = CL_READ_WRITE_CACHE,
> .global_mem_size = 1024 * 1024 * 1024,
> .max_constant_buffer_size = 512 << 10,
> diff --git a/src/cl_mem.c b/src/cl_mem.c
> index ae63137..c54759a 100644
> --- a/src/cl_mem.c
> +++ b/src/cl_mem.c
> @@ -75,6 +75,7 @@ cl_get_mem_object_info(cl_mem mem,
> void *param_value,
> size_t *param_value_size_ret)
> {
> + struct _cl_mem_buffer* buf = (struct _cl_mem_buffer*)mem;
> switch(param_name)
> {
> FIELD_SIZE(MEM_TYPE, cl_mem_object_type);
> @@ -102,7 +103,7 @@ cl_get_mem_object_info(cl_mem mem,
> *((size_t *)param_value) = mem->size;
> break;
> case CL_MEM_HOST_PTR:
> - *((size_t *)param_value) = (size_t)mem->host_ptr;
> + *((size_t *)param_value) = (size_t)mem->host_ptr + buf->sub_offset;
> break;
> case CL_MEM_MAP_COUNT:
> *((cl_uint *)param_value) = mem->map_ref;
> diff --git a/src/cl_program.c b/src/cl_program.c
> index 0dcc59a..7888a8f 100644
> --- a/src/cl_program.c
> +++ b/src/cl_program.c
> @@ -713,3 +713,44 @@ error:
>
> return CL_OUT_OF_HOST_MEMORY;
> }
> +
> +LOCAL void
> +cl_program_get_kernel_names(cl_program p, size_t size, char *names, size_t *size_ret)
> +{
> + int i = 0;
> + const char *ker_name = NULL;
> + size_t len = 0;
> + *size_ret = 0;
> +
> + if(p->ker == NULL) {
> + return;
> + }
> +
> + ker_name = cl_kernel_get_name(p->ker[i]);
> + len = strlen(ker_name);
> + if(names) {
> + strncpy(names, cl_kernel_get_name(p->ker[0]), size - 1);
> + if(size < len - 1) {
> + if(size_ret) *size_ret = size;
> + return;
> + }
> + size = size - len - 1; //sub \0
> + }
> + if(size_ret) *size_ret = strlen(ker_name) + 1; //add NULL
> +
> + for (i = 1; i < p->ker_n; ++i) {
> + ker_name = cl_kernel_get_name(p->ker[i]);
> + len = strlen(ker_name);
> + if(names) {
> + strncat(names, ";", size);
> + if(size >= 1)
> + strncat(names, ker_name, size - 1);
> + if(size < len + 1) {
> + if(size_ret) *size_ret = size;
> + break;
> + }
> + size = size - len - 1;
> + }
> + if(size_ret) *size_ret += len + 1; //add ';'
> + }
> +}
> diff --git a/src/cl_program.h b/src/cl_program.h
> index 52d1ac1..d0336d5 100644
> --- a/src/cl_program.h
> +++ b/src/cl_program.h
> @@ -125,5 +125,11 @@ cl_program_link(cl_context context,
> const cl_program * input_programs,
> const char * options,
> cl_int* errcode_ret);
> +/* Get the kernel names in program */
> +extern void
> +cl_program_get_kernel_names(cl_program p,
> + size_t size,
> + char *names,
> + size_t *size_ret);
> #endif /* __CL_PROGRAM_H__ */
>
> --
> 1.8.3.2
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list