summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuo Xionghu <xionghu.luo@intel.com>2015-03-09 11:24:25 +0800
committerZhigang Gong <zhigang.gong@intel.com>2015-03-09 16:05:39 +0800
commitce584ec4976e79a7635eaaafe4a035100397e732 (patch)
tree4b89b29fcdd58be3bbd6d70a2e06533146626e90 /src
parentcf053b0a24ed85a15d2495b9fbb4e3defa883bea (diff)
enable cl_khr_spir extension to build and run from SPIR binary.
the SPIR are built by clang generating a standard llvm Module file, beignet need insert one byte before the module repesents binary type then parse the module to link. enable cl_khr_spir extension output string; enable the SPIR calling conversion of CallingConv::SPIR_KERNEL; get_global_id shoud be OVERLOADABLE; fix some bugs in prinf parse and backend. v2: move OVERLOADABLE change to another patch to keep clean; rename FROM_INTERMEDIATE to FROM_LLVM_SPIR. Signed-off-by: Luo Xionghu <xionghu.luo@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/cl_api.c1
-rw-r--r--src/cl_extensions.c4
-rw-r--r--src/cl_program.c21
-rw-r--r--src/cl_program.h3
4 files changed, 26 insertions, 3 deletions
diff --git a/src/cl_api.c b/src/cl_api.c
index 972c687e..3e72deb2 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -941,6 +941,7 @@ clBuildProgram(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_build(program, options)) != CL_SUCCESS) {
goto error;
diff --git a/src/cl_extensions.c b/src/cl_extensions.c
index d07a5257..cea2dd8a 100644
--- a/src/cl_extensions.c
+++ b/src/cl_extensions.c
@@ -34,8 +34,12 @@ void check_opt1_extension(cl_extensions_t *extensions)
{
int id;
for(id = OPT1_EXT_START_ID; id <= OPT1_EXT_END_ID; id++)
+ {
if (id == EXT_ID(khr_icd))
extensions->extensions[id].base.ext_enabled = 1;
+ if (id == EXT_ID(khr_spir))
+ extensions->extensions[id].base.ext_enabled = 1;
+ }
}
void
diff --git a/src/cl_program.c b/src/cl_program.c
index c30f85e1..db537575 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -231,7 +231,21 @@ cl_program_create_from_binary(cl_context ctx,
program->binary_sz = lengths[0];
program->source_type = FROM_BINARY;
- if(isBitcode((unsigned char*)program->binary+1, (unsigned char*)program->binary+program->binary_sz)) {
+ if(isBitcode((unsigned char*)program->binary, (unsigned char*)program->binary+program->binary_sz)) {
+
+ char* typed_binary;
+ TRY_ALLOC(typed_binary, cl_calloc(lengths[0]+1, sizeof(char)));
+ memcpy(typed_binary+1, binaries[0], lengths[0]);
+ *typed_binary = 1;
+ program->opaque = compiler_program_new_from_llvm_binary(program->ctx->device->vendor_id, typed_binary, program->binary_sz+1);
+ cl_free(typed_binary);
+ if (UNLIKELY(program->opaque == NULL)) {
+ err = CL_INVALID_PROGRAM;
+ goto error;
+ }
+
+ program->source_type = FROM_LLVM_SPIR;
+ }else if(isBitcode((unsigned char*)program->binary+1, (unsigned char*)program->binary+program->binary_sz)) {
if(*program->binary == 1){
program->binary_type = CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT;
}else if(*program->binary == 2){
@@ -499,6 +513,9 @@ cl_program_build(cl_program p, const char *options)
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;
+ }
}
}
@@ -526,7 +543,7 @@ cl_program_build(cl_program p, const char *options)
/* Create all the kernels */
TRY (cl_program_load_gen_program, p);
- } else if (p->source_type == FROM_LLVM) {
+ } else if (p->source_type == FROM_LLVM || p->source_type == FROM_LLVM_SPIR) {
if (!CompilerSupported()) {
err = CL_COMPILER_NOT_AVAILABLE;
goto error;
diff --git a/src/cl_program.h b/src/cl_program.h
index 3ab7acd0..7af02062 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -33,7 +33,8 @@ struct _gbe_program;
enum {
FROM_SOURCE = 0,
FROM_LLVM = 1,
- FROM_BINARY = 2
+ FROM_BINARY = 2,
+ FROM_LLVM_SPIR = 3
};
/* This maps an OCL file containing some kernels */