[Beignet] [PATCH 2/2] Modify program Info using cl_get_info_helper.
junyan.he at inbox.com
junyan.he at inbox.com
Sun Oct 9 09:15:38 UTC 2016
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/CMakeLists.txt | 1 +
src/cl_api.c | 122 --------------------------------------
src/cl_api_program.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 163 insertions(+), 122 deletions(-)
create mode 100644 src/cl_api_program.c
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 18fbcda..d73616e 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 3811842..1c9dbb9 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -837,128 +837,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 {
- 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 0000000..43bc2c3
--- /dev/null
+++ b/src/cl_api_program.c
@@ -0,0 +1,162 @@
+/*
+ * 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_program.h"
+#include "cl_context.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 = "";
+
+ if (!CL_OBJECT_IS_PROGRAM(program)) {
+ return CL_INVALID_PROGRAM;
+ }
+
+ if (param_name == CL_PROGRAM_REFERENCE_COUNT) {
+ cl_int ref = CL_OBJECT_GET_REF(program);
+ src_ptr = &ref;
+ src_size = sizeof(cl_int);
+ } else if (param_name == CL_PROGRAM_CONTEXT) {
+ cl_context context = program->ctx;
+ src_ptr = &context;
+ src_size = sizeof(cl_context);
+ } else if (param_name == CL_PROGRAM_NUM_DEVICES) {
+ cl_uint num_dev = 1; // Just 1 dev now.
+ src_ptr = &num_dev;
+ src_size = sizeof(cl_uint);
+ } else if (param_name == CL_PROGRAM_DEVICES) {
+ cl_device_id dev_id = program->ctx->device;
+ src_ptr = &dev_id;
+ src_size = sizeof(cl_device_id);
+ } else if (param_name == CL_PROGRAM_NUM_KERNELS) {
+ cl_uint 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 = "";
+
+ 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 {
+ return CL_INVALID_VALUE;
+ }
+
+ return cl_get_info_helper(src_ptr, src_size,
+ param_value, param_value_size, param_value_size_ret);
+}
--
2.7.4
More information about the Beignet
mailing list