From: Luo <xionghu....@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_program.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ src/cl_program.h | 7 +++++ 6 files changed, 120 insertions(+)
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 9c22819..0a1c4ab 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 65b1728..cba0a0a 100644 --- a/src/cl_context.h +++ b/src/cl_context.h @@ -102,6 +102,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_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 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet