[Beignet] [PATCH 6/9] runtime: fix clLinkProgram bug.

xionghu.luo at intel.com xionghu.luo at intel.com
Thu Nov 12 00:41:52 PST 2015


From: Luo Xionghu <xionghu.luo at intel.com>

clLinkProgram need check the existence of "-cl-kernel-arg-info" build_option
of all the input_programs. User may link two SPIR program and call
clGetKernelArgInfo to query kernel args.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 src/cl_program.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/cl_program.c b/src/cl_program.c
index 891d51a..6ffc1e8 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -632,6 +632,8 @@ cl_program_link(cl_context            context,
     err = CL_INVALID_LINKER_OPTIONS;
     goto error;
   }
+  const char kernel_arg_option[] = "-cl-kernel-arg-info";
+  cl_bool option_exist = CL_TRUE;
   for(i = 0; i < num_input_programs; i++) {
     //num_input_programs >0 and input_programs MUST not NULL, so compare with input_programs[0] directly.
     if(input_programs[i]->binary_type == CL_PROGRAM_BINARY_TYPE_LIBRARY ||
@@ -639,6 +641,9 @@ cl_program_link(cl_context            context,
        input_programs[i]->binary_type == CL_PROGRAM_BINARY_TYPE_INTERMEDIATE) {
       avialable_program++;
     }
+    if(input_programs[i]->build_opts == NULL || strstr(input_programs[i]->build_opts, kernel_arg_option) == NULL ) {
+      option_exist = CL_FALSE;
+    }
   }
 
   //None of program contain a compilerd binary or library.
@@ -658,6 +663,11 @@ cl_program_link(cl_context            context,
       goto error;
   }
 
+  if(option_exist) {
+      TRY_ALLOC (p->build_opts, cl_calloc(strlen(kernel_arg_option) + 1, sizeof(char)));
+      memcpy(p->build_opts, kernel_arg_option, strlen(kernel_arg_option));
+  }
+
   if (!check_cl_version_option(p, options)) {
     err = CL_BUILD_PROGRAM_FAILURE;
     goto error;
@@ -744,6 +754,9 @@ cl_program_compile(cl_program            p,
       memcpy(p->build_opts, options, strlen(options));
 
       p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
+      if (strstr(options, "-x spir")) {
+        p->source_type = FROM_LLVM_SPIR;
+      }
     }
   }
 
-- 
1.9.1



More information about the Beignet mailing list