diff options
author | Junyan He <junyan.he@intel.com> | 2016-10-09 17:15:38 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2016-12-15 18:30:41 +0800 |
commit | ab3925f128c701fe862d2980103a07c0feb97be0 (patch) | |
tree | d35eff4b3b156d292a9617a0214555bf349ddbe9 /src | |
parent | 23bfe12767f6ebe2685b8dfce4b67fd325e7b738 (diff) |
Modify program Info using cl_get_info_helper.
Signed-off-by: Junyan He <junyan.he@intel.com>
Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/cl_api.c | 127 | ||||
-rw-r--r-- | src/cl_api_program.c | 169 |
3 files changed, 170 insertions, 127 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c3d6957..af0dee37 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,6 +76,7 @@ set(OPENCL_SRC cl_api_event.c cl_api_context.c cl_api_sampler.c + cl_api_program.c cl_alloc.c cl_kernel.c cl_program.c diff --git a/src/cl_api.c b/src/cl_api.c index 83315a75..de1d322f 100644 --- a/src/cl_api.c +++ b/src/cl_api.c @@ -1331,133 +1331,6 @@ clUnloadPlatformCompiler(cl_platform_id platform) return CL_SUCCESS; } -cl_int -clGetProgramInfo(cl_program program, - cl_program_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) -{ - cl_int err = CL_SUCCESS; - char * ret_str = ""; - - CHECK_PROGRAM (program); - - if (param_name == CL_PROGRAM_REFERENCE_COUNT) { - cl_uint ref = CL_OBJECT_GET_REF(program); - FILL_GETINFO_RET (cl_uint, 1, (&ref), CL_SUCCESS); - } else if (param_name == CL_PROGRAM_CONTEXT) { - cl_context context = program->ctx; - FILL_GETINFO_RET (cl_context, 1, &context, CL_SUCCESS); - } else if (param_name == CL_PROGRAM_NUM_DEVICES) { - cl_uint num_dev = 1; // Just 1 dev now. - FILL_GETINFO_RET (cl_uint, 1, &num_dev, CL_SUCCESS); - } 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) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 0); - }else if( program->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 1); - }else if( program->binary_type == CL_PROGRAM_BINARY_TYPE_LIBRARY) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 2); - }else{ - return CL_INVALID_BINARY; - } - } - - if (program->binary == NULL || program->binary_sz == 0) { - return CL_OUT_OF_RESOURCES; - } - FILL_GETINFO_RET (size_t, 1, (&program->binary_sz), CL_SUCCESS); - } else if (param_name == CL_PROGRAM_BINARIES) { - if (param_value_size_ret) - *param_value_size_ret = sizeof(void*); - if (!param_value) - return CL_SUCCESS; - - /* param_value points to an array of n - pointers allocated by the caller */ - if (program->binary == NULL) { - if( program->binary_type == CL_PROGRAM_BINARY_TYPE_EXECUTABLE) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 0); - }else if( program->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 1); - }else if( program->binary_type == CL_PROGRAM_BINARY_TYPE_LIBRARY) { - program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 2); - }else{ - return CL_INVALID_BINARY; - } - } - - if (program->binary == NULL || program->binary_sz == 0) { - return CL_OUT_OF_RESOURCES; - } - - memcpy(*((void **)param_value), program->binary, program->binary_sz); - return CL_SUCCESS; - } else { - return CL_INVALID_VALUE; - } - -error: - return err; -} - -cl_int -clGetProgramBuildInfo(cl_program program, - cl_device_id device, - cl_program_build_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_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) { - FILL_GETINFO_RET (cl_build_status, 1, &program->build_status, CL_SUCCESS); - } else if (param_name == CL_PROGRAM_BUILD_OPTIONS) { - if (program->is_built && program->build_opts) - ret_str = program->build_opts; - - FILL_GETINFO_RET (char, (strlen(ret_str)+1), ret_str, CL_SUCCESS); - } else if (param_name == CL_PROGRAM_BUILD_LOG) { - FILL_GETINFO_RET (char, program->build_log_sz + 1, program->build_log, CL_SUCCESS); - if (param_value_size_ret) - *param_value_size_ret = program->build_log_sz + 1; - }else if (param_name == CL_PROGRAM_BINARY_TYPE){ - - FILL_GETINFO_RET (cl_uint, 1, &program->binary_type, CL_SUCCESS); - } else if (param_name == CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE) { - size_t global_size = 0; - if (program->is_built) - global_size = cl_program_get_global_variable_size(program); - FILL_GETINFO_RET (size_t, 1, &global_size, CL_SUCCESS); - } else { - return CL_INVALID_VALUE; - } - -error: - return err; -} - cl_kernel clCreateKernel(cl_program program, const char * kernel_name, diff --git a/src/cl_api_program.c b/src/cl_api_program.c new file mode 100644 index 00000000..0e29ab6f --- /dev/null +++ b/src/cl_api_program.c @@ -0,0 +1,169 @@ +/* + * 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 <http://www.gnu.org/licenses/>. + * + */ +#include "cl_context.h" +#include "cl_program.h" +#include <string.h> + +cl_int +clGetProgramInfo(cl_program program, + cl_program_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; + const char *ret_str = ""; + cl_int ref; + cl_uint num_dev, kernels_num; + + if (!CL_OBJECT_IS_PROGRAM(program)) { + return CL_INVALID_PROGRAM; + } + + if (param_name == CL_PROGRAM_REFERENCE_COUNT) { + ref = CL_OBJECT_GET_REF(program); + src_ptr = &ref; + src_size = sizeof(cl_int); + } else if (param_name == CL_PROGRAM_CONTEXT) { + src_ptr = &program->ctx; + src_size = sizeof(cl_context); + } else if (param_name == CL_PROGRAM_NUM_DEVICES) { + num_dev = 1; // Just 1 dev now. + src_ptr = &num_dev; + src_size = sizeof(cl_uint); + } else if (param_name == CL_PROGRAM_DEVICES) { + src_ptr = &program->ctx->device; + src_size = sizeof(cl_device_id); + } else if (param_name == CL_PROGRAM_NUM_KERNELS) { + kernels_num = program->ker_n; + src_ptr = &kernels_num; + src_size = sizeof(cl_uint); + } else if (param_name == CL_PROGRAM_SOURCE) { + if (!program->source) { + src_ptr = ret_str; + src_size = 1; + } else { + src_ptr = program->source; + src_size = strlen(program->source) + 1; + } + } else if (param_name == CL_PROGRAM_KERNEL_NAMES) { + // TODO: need to refine this. + cl_program_get_kernel_names(program, param_value_size, (char *)param_value, param_value_size_ret); + return CL_SUCCESS; + } else if (param_name == CL_PROGRAM_BINARY_SIZES) { + if (program->binary == NULL) { + if (program->binary_type == CL_PROGRAM_BINARY_TYPE_EXECUTABLE) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 0); + } else if (program->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 1); + } else if (program->binary_type == CL_PROGRAM_BINARY_TYPE_LIBRARY) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 2); + } else { + return CL_INVALID_BINARY; + } + } + + if (program->binary == NULL || program->binary_sz == 0) { + return CL_OUT_OF_RESOURCES; + } + src_ptr = &program->binary_sz; + src_size = sizeof(size_t); + } else if (param_name == CL_PROGRAM_BINARIES) { + if (param_value_size_ret) + *param_value_size_ret = sizeof(void *); + if (!param_value) + return CL_SUCCESS; + + /* param_value points to an array of n + pointers allocated by the caller */ + if (program->binary == NULL) { + if (program->binary_type == CL_PROGRAM_BINARY_TYPE_EXECUTABLE) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 0); + } else if (program->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 1); + } else if (program->binary_type == CL_PROGRAM_BINARY_TYPE_LIBRARY) { + program->binary_sz = compiler_program_serialize_to_binary(program->opaque, &program->binary, 2); + } else { + return CL_INVALID_BINARY; + } + } + + if (program->binary == NULL || program->binary_sz == 0) { + return CL_OUT_OF_RESOURCES; + } + + memcpy(*((void **)param_value), program->binary, program->binary_sz); + return CL_SUCCESS; + } else { + return CL_INVALID_VALUE; + } + + return cl_get_info_helper(src_ptr, src_size, + param_value, param_value_size, param_value_size_ret); +} + +cl_int +clGetProgramBuildInfo(cl_program program, + cl_device_id device, + cl_program_build_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; + const char *ret_str = ""; + size_t global_size; + + if (!CL_OBJECT_IS_PROGRAM(program)) { + return CL_INVALID_PROGRAM; + } + + if (device != program->ctx->device) { + return CL_INVALID_DEVICE; + } + + if (param_name == CL_PROGRAM_BUILD_STATUS) { + src_ptr = &program->build_status; + src_size = sizeof(cl_build_status); + } else if (param_name == CL_PROGRAM_BUILD_OPTIONS) { + if (program->is_built && program->build_opts) { + ret_str = program->build_opts; + } + src_ptr = ret_str; + src_size = strlen(ret_str) + 1; + } else if (param_name == CL_PROGRAM_BUILD_LOG) { + src_ptr = program->build_log; + src_size = program->build_log_sz + 1; + } else if (param_name == CL_PROGRAM_BINARY_TYPE) { + src_ptr = &program->binary_type; + src_size = sizeof(cl_uint); + } else if (param_name == CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE) { + global_size = 0; + if (program->is_built) + global_size = cl_program_get_global_variable_size(program); + src_ptr = &global_size; + src_size = sizeof(global_size); + } else { + return CL_INVALID_VALUE; + } + + return cl_get_info_helper(src_ptr, src_size, + param_value, param_value_size, param_value_size_ret); +} |