From eb07db6f46b459297fd6916b7486f0941e1ed566 Mon Sep 17 00:00:00 2001 From: Junyan He Date: Sat, 8 Oct 2016 16:47:55 +0800 Subject: Modify clGetContextInfo using cl_get_info_helper. Signed-off-by: Junyan He Reviewed-by: Yang Rong --- src/CMakeLists.txt | 1 + src/cl_api.c | 33 --------------------------- src/cl_api_context.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 src/cl_api_context.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index adf06b13..d1b0ed6d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,6 +73,7 @@ set(OPENCL_SRC cl_api_kernel.c cl_api_command_queue.c cl_api_event.c + cl_api_context.c cl_alloc.c cl_kernel.c cl_program.c diff --git a/src/cl_api.c b/src/cl_api.c index 2bca826d..04b9f67d 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -275,39 +275,6 @@ error: return err; } -cl_int -clGetContextInfo(cl_context context, - cl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) -{ - 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 = CL_OBJECT_GET_REF(context); - 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; - } - -error: - return err; -} - cl_command_queue clCreateCommandQueue(cl_context context, cl_device_id device, diff --git a/src/cl_api_context.c b/src/cl_api_context.c new file mode 100644 index 00000000..21699c49 --- /dev/null +++ b/src/cl_api_context.c @@ -0,0 +1,63 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +#include "cl_context.h" + +cl_int +clGetContextInfo(cl_context context, + cl_context_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) +{ + const void *src_ptr = NULL; + size_t src_size = 0; + cl_uint n, ref; + cl_context_properties p; + + if (!CL_OBJECT_IS_CONTEXT(context)) { + return CL_INVALID_CONTEXT; + } + + if (param_name == CL_CONTEXT_DEVICES) { + src_ptr = &context->device; + src_size = sizeof(cl_device_id); + } else if (param_name == CL_CONTEXT_NUM_DEVICES) { + n = 1; + src_ptr = &n; + src_size = sizeof(cl_uint); + } else if (param_name == CL_CONTEXT_REFERENCE_COUNT) { + ref = CL_OBJECT_GET_REF(context); + src_ptr = &ref; + src_size = sizeof(cl_uint); + } else if (param_name == CL_CONTEXT_PROPERTIES) { + if (context->prop_len > 0) { + src_ptr = context->prop_user; + src_size = sizeof(cl_context_properties) * context->prop_len; + } else { + p = 0; + src_ptr = &p; + src_size = sizeof(cl_context_properties); + } + } else { + return CL_INVALID_VALUE; + } + + return cl_get_info_helper(src_ptr, src_size, + param_value, param_value_size, param_value_size_ret); +} -- cgit v1.2.1