summaryrefslogtreecommitdiff
path: root/utests/runtime_compile_link.cpp
diff options
context:
space:
mode:
authorLuo <xionghu.luo@intel.com>2014-06-27 08:27:03 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-07-01 10:30:03 +0800
commitff4eaa52340ab666c0fb5f8b2476aaf855422a96 (patch)
tree0e4bb83f71dda0099d54ba05d195e4984e16b320 /utests/runtime_compile_link.cpp
parent3aa325c8a047f7176f3e00be597139eff8c9da32 (diff)
downloadbeignet-ff4eaa52340ab666c0fb5f8b2476aaf855422a96.tar.gz
add the usage of link program from llvm binary.
user A could compile and link kernel source to llvm binary first, then query the binary to save to file; With the binary, user B can call clCreateProgramWithBinary without compile the source again. this usage could protect those who need to protect the kernel source. Signed-off-by: Luo <xionghu.luo@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/runtime_compile_link.cpp')
-rw-r--r--utests/runtime_compile_link.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/utests/runtime_compile_link.cpp b/utests/runtime_compile_link.cpp
index 8aeea31a..4a39b6a7 100644
--- a/utests/runtime_compile_link.cpp
+++ b/utests/runtime_compile_link.cpp
@@ -67,12 +67,47 @@ void runtime_compile_link(void)
OCL_ASSERT(err==CL_SUCCESS);
cl_program input_programs[2] = { program_A, program_B};
- cl_program linked_program = clLinkProgram(ctx, 0, NULL, NULL, 2, input_programs, NULL, NULL, &err);
-
+ cl_program linked_program = clLinkProgram(ctx, 0, NULL, "-create-library", 2, input_programs, NULL, NULL, &err);
OCL_ASSERT(linked_program != NULL);
OCL_ASSERT(err == CL_SUCCESS);
+ size_t binarySize;
+ unsigned char *binary;
+
+ // Get the size of the resulting binary (only one device)
+ err= clGetProgramInfo( linked_program, CL_PROGRAM_BINARY_SIZES, sizeof( binarySize ), &binarySize, NULL );
+ OCL_ASSERT(err==CL_SUCCESS);
+
+ // Create a buffer and get the actual binary
+ binary = (unsigned char*)malloc(sizeof(unsigned char)*binarySize);
+ if (binary == NULL) {
+ OCL_ASSERT(0);
+ return ;
+ }
+
+ unsigned char *buffers[ 1 ] = { binary };
+ // Do another sanity check here first
+ size_t size;
+ cl_int loadErrors[ 1 ];
+ err = clGetProgramInfo( linked_program, CL_PROGRAM_BINARIES, 0, NULL, &size );
+ OCL_ASSERT(err==CL_SUCCESS);
+ if( size != sizeof( buffers ) ){
+ free(binary);
+ return ;
+ }
+
+ err = clGetProgramInfo( linked_program, CL_PROGRAM_BINARIES, sizeof( buffers ), &buffers, NULL );
+ OCL_ASSERT(err==CL_SUCCESS);
+
+ cl_device_id deviceID;
+ err = clGetProgramInfo( linked_program, CL_PROGRAM_DEVICES, sizeof( deviceID), &deviceID, NULL );
+ OCL_ASSERT(err==CL_SUCCESS);
+
+ cl_program program_with_binary = clCreateProgramWithBinary(ctx, 1, &deviceID, &binarySize, (const unsigned char**)buffers, loadErrors, &err);
+ OCL_ASSERT(err==CL_SUCCESS);
+ cl_program new_linked_program = clLinkProgram(ctx, 1, &deviceID, NULL, 1, &program_with_binary, NULL, NULL, &err);
+ OCL_ASSERT(err==CL_SUCCESS);
// link success, run this kernel.
const size_t n = 16;
@@ -104,7 +139,7 @@ void runtime_compile_link(void)
OCL_UNMAP_BUFFER(0);
OCL_UNMAP_BUFFER(1);
- kernel = clCreateKernel(linked_program, "runtime_compile_link_a", &err);
+ kernel = clCreateKernel(new_linked_program, "runtime_compile_link_a", &err);
OCL_ASSERT(err == CL_SUCCESS);