summaryrefslogtreecommitdiff
path: root/src/cl_program.c
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2013-09-11 18:07:51 +0800
committerZhigang Gong <zhigang.gong@linux.intel.com>2013-09-12 15:44:55 +0800
commitd41f101d64e8ca389da3a628c255b2e42f9eb0fe (patch)
treebb4b3fe10348816cd928b58a6239bf88e06ed173 /src/cl_program.c
parent87fdc4198a987a2ae4cb1382ff947ab4c221b29e (diff)
Implement the clCreateProgramWithBinary to deseralize the binary.
We now do not check the format of the binary. We need to check the binary file format to handle the internal binary, the LLVM binary or the invalid format differently. Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
Diffstat (limited to 'src/cl_program.c')
-rw-r--r--src/cl_program.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/cl_program.c b/src/cl_program.c
index 78705149..a0e01048 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -42,6 +42,15 @@ cl_program_release_sources(cl_program p)
}
}
+static void
+cl_program_release_binary(cl_program p)
+{
+ if (p->binary) {
+ cl_free(p->binary);
+ p->binary = NULL;
+ }
+}
+
LOCAL void
cl_program_delete(cl_program p)
{
@@ -53,8 +62,9 @@ cl_program_delete(cl_program p)
/* We are not done with it yet */
if ((ref = atomic_dec(&p->ref_n)) > 1) return;
- /* Destroy the sources if still allocated */
+ /* Destroy the sources and binary if still allocated */
cl_program_release_sources(p);
+ cl_program_release_binary(p);
/* Release the build options. */
if (p->build_opts) {
@@ -149,7 +159,6 @@ cl_program_create_from_binary(cl_context ctx,
cl_int * binary_status,
cl_int * errcode_ret)
{
-#if 0
cl_program program = NULL;
cl_int err = CL_SUCCESS;
@@ -174,7 +183,16 @@ cl_program_create_from_binary(cl_context ctx,
goto error;
}
- // TRY_ALLOC (program, cl_program_new(ctx, (const char *) binaries[0], lengths[0]));
+ program = cl_program_new(ctx);
+
+ // TODO: Need to check the binary format here to return CL_INVALID_BINARY.
+ TRY_ALLOC(program->binary, cl_calloc(lengths[0], sizeof(char)));
+ memcpy(program->binary, binaries[0], lengths[0]);
+ program->binary_sz = lengths[0];
+ program->source_type = FROM_BINARY;
+
+ if (binary_status)
+ binary_status[0] = CL_SUCCESS;
exit:
if (errcode_ret)
@@ -184,8 +202,7 @@ error:
cl_program_delete(program);
program = NULL;
goto exit;
-#endif
- NOT_IMPLEMENTED;
+
return CL_SUCCESS;
}
@@ -303,6 +320,16 @@ cl_program_build(cl_program p, const char *options)
/* Create all the kernels */
TRY (cl_program_load_gen_program, p);
p->source_type = FROM_LLVM;
+ } else if (p->source_type == FROM_BINARY) {
+ p->opaque = gbe_program_new_from_binary(p->binary, p->binary_sz);
+ if (UNLIKELY(p->opaque == NULL)) {
+ err = CL_INVALID_PROGRAM;
+ goto error;
+ }
+
+ /* Create all the kernels */
+ TRY (cl_program_load_gen_program, p);
+ p->source_type = FROM_LLVM;
}
for (i = 0; i < p->ker_n; i ++) {