[Beignet] [fix merge issue 1/2] add [opencl-1.2] API clCreateProgramWithBuiltInKernels.
xionghu.luo at intel.com
xionghu.luo at intel.com
Wed May 21 20:32:03 PDT 2014
From: Luo <xionghu.luo at intel.com>
This API creates a built-in program object for a context, and loads the
built-in kernels into this program object.
---
backend/src/ir/image.cpp | 5 ++++
src/cl_api.c | 24 ++++++++++++++++
src/cl_context.c | 8 ++++++
src/cl_context.h | 2 ++
src/cl_gt_device.h | 24 +++++++++++++++-
src/cl_program.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
src/cl_program.h | 7 +++++
7 files changed, 143 insertions(+), 1 deletion(-)
diff --git a/backend/src/ir/image.cpp b/backend/src/ir/image.cpp
index 8c34d70..87bafc0 100644
--- a/backend/src/ir/image.cpp
+++ b/backend/src/ir/image.cpp
@@ -125,7 +125,12 @@ namespace ir {
void ImageSet::getData(struct ImageInfo *imageInfos) const {
for(auto &it : regMap)
+ {
+ int t = it.second->idx - gbe_get_image_base_index();
+ if(t < 0)
+ continue;
imageInfos[it.second->idx - gbe_get_image_base_index()] = *it.second;
+ }
}
ImageSet::~ImageSet() {
diff --git a/src/cl_api.c b/src/cl_api.c
index 4b1deda..3a77dcd 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -816,6 +816,30 @@ error:
*errcode_ret = err;
return program;
}
+
+cl_program
+clCreateProgramWithBuiltInKernels(cl_context context,
+ cl_uint num_devices,
+ const cl_device_id * device_list,
+ const char * kernel_names,
+ cl_int * errcode_ret)
+{
+ cl_program program = NULL;
+ cl_int err = CL_SUCCESS;
+
+ CHECK_CONTEXT (context);
+ INVALID_VALUE_IF (kernel_names == NULL);
+ program = cl_program_create_with_built_in_kernles(context,
+ num_devices,
+ device_list,
+ kernel_names,
+ &err);
+error:
+ if (errcode_ret)
+ *errcode_ret = err;
+ return program;
+}
+
cl_int
clRetainProgram(cl_program program)
{
diff --git a/src/cl_context.c b/src/cl_context.c
index 293af94..6172ecc 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -206,8 +206,16 @@ cl_context_delete(cl_context ctx)
cl_program_delete(ctx->internal_prgs[i]);
ctx->internal_prgs[i] = NULL;
}
+
+ if (ctx->internel_kernels[i]) {
+ cl_kernel_delete(ctx->built_in_kernels[i]);
+ ctx->built_in_kernels[i] = NULL;
+ }
}
+ cl_program_delete(ctx->built_in_prgs);
+ ctx->built_in_prgs = NULL;
+
/* All object lists should have been freed. Otherwise, the reference counter
* of the context cannot be 0
*/
diff --git a/src/cl_context.h b/src/cl_context.h
index 4de954c..e037634 100644
--- a/src/cl_context.h
+++ b/src/cl_context.h
@@ -103,6 +103,8 @@ struct _cl_context {
/* All programs internal used, for example clEnqueuexxx api use */
cl_kernel internel_kernels[CL_INTERNAL_KERNEL_MAX];
/* All kernels for clenqueuexxx api, for example clEnqueuexxx api use */
+ cl_program built_in_prgs; /*all built-in kernels belongs to this program only*/
+ cl_kernel built_in_kernels[CL_INTERNAL_KERNEL_MAX];
uint32_t ver; /* Gen version */
struct _cl_context_prop props;
cl_context_properties * prop_user; /* a copy of user passed context properties when create context */
diff --git a/src/cl_gt_device.h b/src/cl_gt_device.h
index 7e45b4e..3e2502c 100644
--- a/src/cl_gt_device.h
+++ b/src/cl_gt_device.h
@@ -75,7 +75,29 @@ DECL_INFO_STRING(version, LIBCL_VERSION_STRING)
DECL_INFO_STRING(profile, "FULL_PROFILE")
DECL_INFO_STRING(opencl_c_version, LIBCL_C_VERSION_STRING)
DECL_INFO_STRING(extensions, "")
-DECL_INFO_STRING(built_in_kernels, "")
+DECL_INFO_STRING(built_in_kernels, "__cl_copy_region_align4;"
+ "__cl_copy_region_align16;"
+ "__cl_cpy_region_unalign_same_offset;"
+ "__cl_copy_region_unalign_dst_offset;"
+ "__cl_copy_region_unalign_src_offset;"
+ "__cl_copy_buffer_rect;"
+ "__cl_copy_image_2d_to_2d;"
+ "__cl_copy_image_3d_to_2d;"
+ "__cl_copy_image_2d_to_3d;"
+ "__cl_copy_image_3d_to_3d;"
+ "__cl_copy_image_2d_to_buffer;"
+ "__cl_copy_image_3d_to_buffer;"
+ "__cl_copy_buffer_to_image_2d;"
+ "__cl_copy_buffer_to_image_3d;"
+ "__cl_fill_region_unalign;"
+ "__cl_fill_region_align2;"
+ "__cl_fill_region_align4;"
+ "__cl_fill_region_align8_2;"
+ "__cl_fill_region_align8_4;"
+ "__cl_fill_region_align8_8;"
+ "__cl_fill_region_align8_16;"
+ "__cl_fill_region_align128;")
+
DECL_INFO_STRING(driver_version, LIBCL_DRIVER_VERSION_STRING)
#undef DECL_INFO_STRING
diff --git a/src/cl_program.c b/src/cl_program.c
index 184d6b5..87a1e6b 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -209,6 +209,80 @@ error:
}
LOCAL cl_program
+cl_program_create_with_built_in_kernles(cl_context ctx,
+ cl_uint num_devices,
+ const cl_device_id * devices,
+ const char * kernel_names,
+ cl_int * errcode_ret)
+{
+ cl_int err = CL_SUCCESS;
+
+ assert(ctx);
+ INVALID_DEVICE_IF (num_devices != 1);
+ INVALID_DEVICE_IF (devices == NULL);
+ INVALID_DEVICE_IF (devices[0] != ctx->device);
+
+ extern char cl_internal_built_in_kernel_str[];
+ extern int cl_internal_built_in_kernel_str_size;
+ char* p_built_in_kernel_str =cl_internal_built_in_kernel_str;
+ cl_int binary_status = CL_SUCCESS;
+
+ ctx->built_in_prgs = cl_program_create_from_binary(ctx, 1,
+ &ctx->device,
+ (size_t*)&cl_internal_built_in_kernel_str_size,
+ (const unsigned char **)&p_built_in_kernel_str,
+ &binary_status, &err);
+
+ if (!ctx->built_in_prgs)
+ return NULL;
+
+ err = cl_program_build(ctx->built_in_prgs, NULL);
+ if (err != CL_SUCCESS)
+ return NULL;
+
+ ctx->built_in_prgs->is_built = 1;
+
+ char delims[] = ";";
+ char* saveptr = NULL;
+ char* local_kernel_names;
+ char* kernel = NULL;
+ char* matched_kernel;
+ int i = 0;
+
+ //copy the content to local_kernel_names to protect the kernel_names.
+ TRY_ALLOC(local_kernel_names, cl_calloc(strlen(kernel_names)+1, sizeof(char) ) );
+ memcpy(local_kernel_names, kernel_names, strlen(kernel_names)+1);
+
+ kernel = strtok_r( local_kernel_names, delims , &saveptr);
+ while( kernel != NULL ) {
+ matched_kernel = strstr(ctx->device->built_in_kernels, kernel);
+ if(matched_kernel){
+ for (i = 0; i < ctx->built_in_prgs->ker_n; ++i) {
+ assert(ctx->built_in_prgs->ker[i]);
+ const char *ker_name = cl_kernel_get_name(ctx->built_in_prgs->ker[i]);
+ if (strcmp(ker_name, kernel) == 0) {
+ break;
+ }
+ }
+
+ ctx->built_in_kernels[i] = cl_program_create_kernel(ctx->built_in_prgs, kernel, NULL);
+ }
+ kernel = strtok_r((char*)saveptr , delims, &saveptr );
+ }
+
+ cl_free(local_kernel_names);
+
+exit:
+ if (errcode_ret)
+ *errcode_ret = err;
+ return ctx->built_in_prgs;
+error:
+ goto exit;
+
+ return CL_SUCCESS;
+}
+
+LOCAL cl_program
cl_program_create_from_llvm(cl_context ctx,
cl_uint num_devices,
const cl_device_id *devices,
diff --git a/src/cl_program.h b/src/cl_program.h
index a6d75da..989bb8d 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -92,6 +92,13 @@ cl_program_create_from_binary(cl_context context,
cl_int * binary_status,
cl_int * errcode_ret);
+/* Create a program with built-in kernels*/
+extern cl_program
+cl_program_create_with_built_in_kernles(cl_context context,
+ cl_uint num_devices,
+ const cl_device_id * device_list,
+ const char * kernel_names,
+ cl_int * errcode_ret);
/* Directly create a program from a LLVM source file */
extern cl_program
cl_program_create_from_llvm(cl_context context,
--
1.8.1.2
More information about the Beignet
mailing list