diff options
author | Manasi Navare <manasi.d.navare@intel.com> | 2015-10-12 07:53:07 -0400 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2015-10-13 14:53:05 +0800 |
commit | 15ced6f6ed456f63401ac053c5ec109524af8ca8 (patch) | |
tree | b0a7230abb8ad49a52cd8d8d520bec869d42e9c9 /utests/utest_helper.cpp | |
parent | 430384ccae4cba983e533e507557dd5a50303601 (diff) |
utests: Added unit tests to test LLVM and ASM dump generation in a two step build process with clCompile and clLink APIs.
This patch adds two new tests to the unit tests. It uses the existing
framework and data structures and tests the llvm/asm dump generation
when these flags (-dump-opt-llvm, -dump-opt-asm) are passed as compile and link
options to clCompileProgram and clLinkProgram APIs along with the dump file names.
Method added:
1) get_compile_llvm_info() tests LLVM dump generation after clCompileProgram() stage
2) get_link_asm_info() tests Gen ASM dump generation after clLinkProgram() stage
Signed-off-by: Manasi Navare <manasi.d.navare@intel.com>
Reviewed-by: Ruiling Song <ruiling.song@intel.com>
Diffstat (limited to 'utests/utest_helper.cpp')
-rw-r--r-- | utests/utest_helper.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index 8f772fd4..664046c5 100644 --- a/utests/utest_helper.cpp +++ b/utests/utest_helper.cpp @@ -286,6 +286,115 @@ error: goto exit; } +int +cl_kernel_compile(const char *file_name, const char *kernel_name, const char * compile_opt) +{ + cl_file_map_t *fm = NULL; + char *ker_path = NULL; + cl_int status = CL_SUCCESS; + static const char *prevFileName = NULL; + cl_int err; + + /* Load the program and build it */ + if (!program || (program && (!prevFileName || strcmp(prevFileName, file_name)))) { + if (program) clReleaseProgram(program); + ker_path = cl_do_kiss_path(file_name, device); + cl_file_map_t *fm = cl_file_map_new(); + FATAL_IF (cl_file_map_open(fm, ker_path) != CL_FILE_MAP_SUCCESS, + "Failed to open file \"%s\" with kernel \"%s\". Did you properly set OCL_KERNEL_PATH variable?", + file_name, kernel_name); + const char *src = cl_file_map_begin(fm); + const size_t sz = cl_file_map_size(fm); + program = clCreateProgramWithSource(ctx, 1, &src, &sz, &status); + cl_file_map_delete(fm); + + if (status != CL_SUCCESS) { + fprintf(stderr, "error calling clCreateProgramWithSource\n"); + goto error; + } + prevFileName = file_name; + + OCL_CALL (clCompileProgram, program, + 1, &device, // num_devices & device_list + compile_opt, // compile_options + 0, // num_input_headers + NULL, + NULL, + NULL, NULL); + OCL_ASSERT(err==CL_SUCCESS); + + } + +exit: + free(ker_path); + cl_file_map_delete(fm); + return status; +error: + prevFileName = NULL; + goto exit; +} + +int +cl_kernel_link(const char *file_name, const char *kernel_name, const char * link_opt) +{ + cl_file_map_t *fm = NULL; + char *ker_path = NULL; + cl_int status = CL_SUCCESS; + static const char *prevFileName = NULL; + cl_int err; + + /* Load the program and build it */ + if (!program || (program && (!prevFileName || strcmp(prevFileName, file_name)))) { + if (program) clReleaseProgram(program); + ker_path = cl_do_kiss_path(file_name, device); + cl_file_map_t *fm = cl_file_map_new(); + FATAL_IF (cl_file_map_open(fm, ker_path) != CL_FILE_MAP_SUCCESS, + "Failed to open file \"%s\" with kernel \"%s\". Did you properly set OCL_KERNEL_PATH variable?", + file_name, kernel_name); + const char *src = cl_file_map_begin(fm); + const size_t sz = cl_file_map_size(fm); + program = clCreateProgramWithSource(ctx, 1, &src, &sz, &status); + cl_file_map_delete(fm); + + if (status != CL_SUCCESS) { + fprintf(stderr, "error calling clCreateProgramWithSource\n"); + goto error; + } + prevFileName = file_name; + + OCL_CALL (clCompileProgram, program, + 1, &device, // num_devices & device_list + NULL, // compile_options + 0, // num_input_headers + NULL, + NULL, + NULL, NULL); + OCL_ASSERT(err==CL_SUCCESS); + cl_program input_programs[1] = {program}; + program = clLinkProgram(ctx, 1, &device, link_opt, 1, input_programs, NULL, NULL, &err); + OCL_ASSERT(program != NULL); + OCL_ASSERT(err == CL_SUCCESS); + } + + /* Create a kernel from the program */ + if (kernel) + clReleaseKernel(kernel); + kernel = clCreateKernel(program, kernel_name, &status); + if (status != CL_SUCCESS) { + fprintf(stderr, "error calling clCreateKernel\n"); + goto error; + } + +exit: + free(ker_path); + cl_file_map_delete(fm); + return status; +error: + prevFileName = NULL; + goto exit; +} + + #define GET_PLATFORM_STR_INFO(LOWER_NAME, NAME) \ { \ size_t param_value_size; \ |