[Beignet] [PATCH 2/2] Refine error check in clCreateProgramFromSource() and clCreateKernel()
Ruiling Song
ruiling.song at intel.com
Wed Jun 12 18:40:17 PDT 2013
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
src/cl_api.c | 15 +++++++++++----
src/cl_program.c | 7 -------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index fd707e5..f14bee4 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -616,8 +616,17 @@ clCreateProgramWithSource(cl_context context,
{
cl_program program = NULL;
cl_int err = CL_SUCCESS;
+ cl_uint i;
CHECK_CONTEXT (context);
+ INVALID_VALUE_IF (count == 0);
+ INVALID_VALUE_IF (strings == NULL);
+ for(i = 0; i < count; i++) {
+ if(UNLIKELY(strings[i] == NULL)) {
+ err = CL_INVALID_VALUE;
+ goto error;
+ }
+ }
program = cl_program_create_from_source(context,
count,
strings,
@@ -691,10 +700,7 @@ clBuildProgram(cl_program program,
/* Everything is easy. We only support one device anyway */
if (num_devices != 0) {
assert(program->ctx);
- if (UNLIKELY(device_list[0] != program->ctx->device)) {
- err = CL_INVALID_DEVICE;
- goto error;
- }
+ INVALID_DEVICE_IF (device_list[0] != program->ctx->device);
}
/* TODO support create program from binary */
@@ -752,6 +758,7 @@ clCreateKernel(cl_program program,
err = CL_INVALID_PROGRAM_EXECUTABLE;
goto error;
}
+ INVALID_VALUE_IF (kernel_name == NULL);
kernel = cl_program_create_kernel(program, kernel_name, &err);
error:
diff --git a/src/cl_program.c b/src/cl_program.c
index 0c48ef3..6acf31f 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -236,8 +236,6 @@ cl_program_create_from_source(cl_context ctx,
cl_uint i;
assert(ctx);
- INVALID_VALUE_IF (count == 0);
- INVALID_VALUE_IF (strings == NULL);
// the real compilation step will be done at build time since we do not have
// yet the compilation options
@@ -297,11 +295,6 @@ cl_program_create_kernel(cl_program p, const char *name, cl_int *errcode_ret)
cl_int err = CL_SUCCESS;
uint32_t i = 0;
- if (UNLIKELY(name == NULL)) {
- err = CL_INVALID_KERNEL_NAME;
- goto error;
- }
-
/* Find the program first */
for (i = 0; i < p->ker_n; ++i) {
assert(p->ker[i]);
--
1.7.9.5
More information about the Beignet
mailing list