[Beignet] [PATCH 1/3] Implement api clCreateKernelsInProgram.

Yang Rong rong.r.yang at intel.com
Tue Oct 8 23:36:25 PDT 2013


Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 src/cl_api.c     | 22 ++++++++++++++++++++--
 src/cl_program.c | 21 +++++++++++++++++++++
 src/cl_program.h |  3 +++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index ded0e0c..42948e8 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -981,8 +981,26 @@ clCreateKernelsInProgram(cl_program      program,
                          cl_kernel *     kernels,
                          cl_uint *       num_kernels_ret)
 {
-  NOT_IMPLEMENTED;
-  return 0;
+  cl_int err = CL_SUCCESS;
+  cl_int ret = 0;
+
+  CHECK_PROGRAM (program);
+  if (program->is_built == CL_FALSE) {
+    err = CL_INVALID_PROGRAM_EXECUTABLE;
+    goto error;
+  }
+  if (kernels && num_kernels < program->ker_n) {
+    err = CL_INVALID_VALUE;
+    goto error;
+  }
+
+  ret = cl_program_create_kernels_in_program(program, kernels);
+
+  if(num_kernels_ret)
+    *num_kernels_ret = ret;
+
+error:
+  return err;
 }
 
 cl_int
diff --git a/src/cl_program.c b/src/cl_program.c
index a0e0104..a7caca8 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -386,3 +386,24 @@ error:
   goto exit;
 }
 
+LOCAL cl_int
+cl_program_create_kernels_in_program(cl_program p, cl_kernel* ker)
+{
+  uint32_t i = 0;
+  
+  if(ker == NULL)
+    return p->ker_n;
+  
+  for (i = 0; i < p->ker_n; ++i) {
+    TRY_ALLOC_NO_ERR(ker[i], cl_kernel_dup(p->ker[i]));    
+  }
+  
+exit:
+  return i;
+
+error:
+  cl_kernel_delete(ker[i]);
+  goto exit;
+  
+}
+
diff --git a/src/cl_program.h b/src/cl_program.h
index de82fd5..2cb547a 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -68,6 +68,9 @@ extern void cl_program_add_ref(cl_program);
 /* Create a kernel for the OCL user */
 extern cl_kernel cl_program_create_kernel(cl_program, const char*, cl_int*);
 
+/* creates kernel objects for all kernel functions in program. */
+extern cl_int cl_program_create_kernels_in_program(cl_program, cl_kernel*);
+
 /* Create a program from OCL source */
 extern cl_program
 cl_program_create_from_source(cl_context ctx,
-- 
1.8.1.2



More information about the Beignet mailing list