diff options
author | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-07-04 18:41:20 +0200 |
---|---|---|
committer | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-07-04 18:41:20 +0200 |
commit | 3e09da53bb5f165983f4531ee152acebb85670db (patch) | |
tree | 0983c83a74a3c7eda90bd50571423e98092fdabe /tests | |
parent | 03c6bcd18e3bc6c933b09ff72f6331c9534695e6 (diff) |
Implement clGetProgramInfo and program binaries
Source code can be compiled in a LLVM module that is dumped in a byte
array, accessible with clGetProgramInfo.
Tests added for clGetProgramInfo and clCreateProgramWithBinary.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_program.cpp | 98 |
1 files changed, 87 insertions, 11 deletions
diff --git a/tests/test_program.cpp b/tests/test_program.cpp index 30ee8c9..bc8d73c 100644 --- a/tests/test_program.cpp +++ b/tests/test_program.cpp @@ -2,6 +2,7 @@ #include "CL/cl.h" #include <stdio.h> +#include <stdlib.h> const char program_source[] = "#define __global __attribute__((address_space(1)))\n" @@ -21,52 +22,126 @@ START_TEST (test_create_program) cl_context ctx; cl_program program; cl_int result; - + const char *src = program_source; size_t program_len = sizeof(program_source); - + result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 1, &device, 0); fail_if( result != CL_SUCCESS, "unable to get the default device" ); - + ctx = clCreateContext(0, 1, &device, 0, 0, &result); fail_if( result != CL_SUCCESS || ctx == 0, "unable to create a valid context" ); - + program = clCreateProgramWithSource(ctx, 0, &src, 0, &result); fail_if( result != CL_INVALID_VALUE, "count cannot be 0" ); - + program = clCreateProgramWithSource(ctx, 1, 0, 0, &result); fail_if( result != CL_INVALID_VALUE, "strings cannot be NULL" ); - + program = clCreateProgramWithSource(ctx, 1, &src, &program_len, &result); fail_if( result != CL_SUCCESS, "cannot create a program from source with sane arguments" ); - + clReleaseProgram(program); // Sorry - + program = clCreateProgramWithSource(ctx, 1, &src, 0, &result); fail_if( result != CL_SUCCESS, "lengths can be NULL and it must work" ); - + result = clBuildProgram(program, 1, &device, "", 0, 0); - printf("result : %i\n", result); - + fail_if( + result != CL_SUCCESS, + "cannot build a valid program" + ); + + clReleaseProgram(program); + clReleaseContext(ctx); +} +END_TEST + +START_TEST (test_program_binary) +{ + cl_platform_id platform = 0; + cl_device_id device; + cl_context ctx; + cl_program program; + cl_int result, binary_status; + + const char *src = program_source; + size_t program_len = sizeof(program_source); + + result = clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 1, &device, 0); + fail_if( + result != CL_SUCCESS, + "unable to get the default device" + ); + + ctx = clCreateContext(0, 1, &device, 0, 0, &result); + fail_if( + result != CL_SUCCESS || ctx == 0, + "unable to create a valid context" + ); + + program = clCreateProgramWithSource(ctx, 1, &src, &program_len, + &result); + fail_if( + result != CL_SUCCESS, + "cannot create a program from source with sane arguments" + ); + + result = clBuildProgram(program, 1, &device, "", 0, 0); + fail_if( + result != CL_SUCCESS, + "cannot build a valid program" + ); + + size_t binary_size = 0; + unsigned char *binary_data = 0; + + result = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), + (void *)&binary_size, 0); + fail_if( + result != CL_SUCCESS || binary_size == 0, + "cannot get the binary size of the program" + ); + + binary_data = (unsigned char *)malloc(binary_size); + + result = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(unsigned char *), + (void *)&binary_data, 0); + fail_if( + result != CL_SUCCESS, + "cannot get the program's binary" + ); + + clReleaseProgram(program); + + program = clCreateProgramWithBinary(ctx, 1, &device, &binary_size, + (const unsigned char **)&binary_data, + &binary_status, &result); + fail_if( + result != CL_SUCCESS || binary_status != CL_SUCCESS, + "cannot create a program from a previously-built binary" + ); + + clReleaseProgram(program); clReleaseContext(ctx); } END_TEST @@ -76,5 +151,6 @@ TCase *cl_program_tcase_create(void) TCase *tc = NULL; tc = tcase_create("program"); tcase_add_test(tc, test_create_program); + tcase_add_test(tc, test_program_binary); return tc; } |