[Beignet] [Patch v2 05/10] runtime: fix clCompileProgram bug.

xionghu.luo at intel.com xionghu.luo at intel.com
Wed Nov 25 22:00:00 PST 2015


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

forgot to add FROM_LLVM_SPIR in compileProgram; the BINARY_TYPE is
BINARY_TYPE_INTERMIDIATE if create from SPIR binary.

v2: refine the source_type logic: source_type is already set in
clCreateProgramWithSource or clCreateProgramWithBinary, shouldn't be set
in clBuildProgram or clCompileProgram.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 src/cl_api.c     |  1 +
 src/cl_program.c | 17 ++++-------------
 src/cl_program.h |  1 +
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 7cfded9..8387a84 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -987,6 +987,7 @@ clCompileProgram(cl_program            program ,
   /* TODO support create program from binary */
   assert(program->source_type == FROM_LLVM ||
       program->source_type == FROM_SOURCE ||
+      program->source_type == FROM_LLVM_SPIR ||
       program->source_type == FROM_BINARY);
   if((err = cl_program_compile(program, num_input_headers, input_headers, header_include_names, options)) != CL_SUCCESS) {
     goto error;
diff --git a/src/cl_program.c b/src/cl_program.c
index 98b6d51..63e05f7 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -27,6 +27,7 @@
 #include "cl_gbe_loader.h"
 #include "CL/cl.h"
 #include "CL/cl_intel.h"
+#include "CL/cl_ext.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -250,6 +251,7 @@ cl_program_create_from_binary(cl_context             ctx,
     }
 
     program->source_type = FROM_LLVM_SPIR;
+    program->binary_type = CL_PROGRAM_BINARY_TYPE_INTERMEDIATE;
   }else if(isLLVM_C_O((unsigned char*)program->binary) || isLLVM_LIB((unsigned char*)program->binary)) {
     if(*program->binary == BHI_COMPIRED_OBJECT){
       program->binary_type = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
@@ -530,17 +532,10 @@ cl_program_build(cl_program p, const char *options)
       }
       TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
       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;
-      }
     }
   }
 
   if (options == NULL && p->build_opts) {
-    p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
-
     cl_free(p->build_opts);
     p->build_opts = NULL;
   }
@@ -633,7 +628,8 @@ cl_program_link(cl_context            context,
   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 ||
-       input_programs[i]->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT) {
+       input_programs[i]->binary_type == CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT ||
+       input_programs[i]->binary_type == CL_PROGRAM_BINARY_TYPE_INTERMEDIATE) {
       avialable_program++;
     }
   }
@@ -739,14 +735,10 @@ cl_program_compile(cl_program            p,
       }
       TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
       memcpy(p->build_opts, options, strlen(options));
-
-      p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
     }
   }
 
   if (options == NULL && p->build_opts) {
-    p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
-
     cl_free(p->build_opts);
     p->build_opts = NULL;
   }
@@ -810,7 +802,6 @@ cl_program_compile(cl_program            p,
     }
 
     /* Create all the kernels */
-    p->source_type = FROM_LLVM;
     p->binary_type = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
   }else if(p->source_type == FROM_BINARY){
     err = CL_INVALID_OPERATION;
diff --git a/src/cl_program.h b/src/cl_program.h
index 63ad16d..897f283 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -60,6 +60,7 @@ struct _cl_program {
   char *binary;           /* Program binary. */
   size_t binary_sz;       /* The binary size. */
   uint32_t binary_type;   /* binary type: COMPILED_OBJECT(LLVM IR), LIBRARY(LLVM IR with option "-create-library"), or EXECUTABLE(GEN binary). */
+                          /* ext binary type: BINARY_TYPE_INTERMIDIATE. */
   uint32_t ker_n;         /* Number of declared kernels */
   uint32_t source_type:2; /* Built from binary, source or LLVM */
   uint32_t is_built:1;    /* Did we call clBuildProgram on it? */
-- 
1.9.1



More information about the Beignet mailing list