diff options
author | Zhigang Gong <zhigang.gong@intel.com> | 2013-12-11 13:40:51 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2013-12-16 09:20:46 +0800 |
commit | 625d5aa18446206cd6a00a52d8a2094948fd9d93 (patch) | |
tree | d8e71909e55cd012591472b93e5e5825d97df21d /utests/utest_helper.cpp | |
parent | 4957110d5238b999c78b382bb1bf92092757447f (diff) | |
download | beignet-625d5aa18446206cd6a00a52d8a2094948fd9d93.tar.gz |
Accelerate utest.
For some test cases which include more than one kernel, the current
implementation always build the program for a new sub test case.
That wastes a lot of time. This patch introduce a new macro
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM which has an extra parameter
to specify whether to keep the previous program and avoid the extra
build. The normal usage is:
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM(fn1, true);
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM(fn2, true);
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM(fn3, true);
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM(fn4, true);
MAKE_UTEST_FROM_FUNCTION_KEEP_PROGRAM(fn5, false);
The scenario is that the above fn1-5 are included in the same kernel
file and we define the sub cases in the same cpp file. We already
have some examples of this usage in the compiler_abs.cpp, compiler_abs_diff.cpp
compiler_basic_arithmetic.cpp, compiler_vector_load_store.cpp, etc.
This patch reduces 2/3 of the utests execution time.
v2: should always destroy the program when run one specific test case.
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
Diffstat (limited to 'utests/utest_helper.cpp')
-rw-r--r-- | utests/utest_helper.cpp | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index 65af7275..b264c1b4 100644 --- a/utests/utest_helper.cpp +++ b/utests/utest_helper.cpp @@ -237,30 +237,32 @@ cl_kernel_init(const char *file_name, const char *kernel_name, int format, const cl_file_map_t *fm = NULL; char *ker_path = NULL; cl_int status = CL_SUCCESS; + static const char *prevFileName = NULL; /* Load the program and build it */ - if (program) - clReleaseProgram(program); - ker_path = cl_do_kiss_path(file_name, device); - if (format == LLVM) - program = clCreateProgramWithLLVMIntel(ctx, 1, &device, ker_path, &status); - else if (format == SOURCE) { - 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); - } else - FATAL("Not able to create program from binary"); - - if (status != CL_SUCCESS) { - fprintf(stderr, "error calling clCreateProgramWithBinary\n"); - goto error; + if (!program || (program && (!prevFileName || strcmp(prevFileName, file_name)))) { + if (program) clReleaseProgram(program); + ker_path = cl_do_kiss_path(file_name, device); + if (format == LLVM) + program = clCreateProgramWithLLVMIntel(ctx, 1, &device, ker_path, &status); + else if (format == SOURCE) { + 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); + } else + FATAL("Not able to create program from binary"); + + if (status != CL_SUCCESS) { + fprintf(stderr, "error calling clCreateProgramWithBinary\n"); + goto error; + } + prevFileName = file_name; } - /* OCL requires to build the program even if it is created from a binary */ OCL_CALL (clBuildProgram, program, 1, &device, build_opt, NULL, NULL); @@ -278,6 +280,7 @@ exit: cl_file_map_delete(fm); return status; error: + prevFileName = NULL; goto exit; } @@ -413,12 +416,16 @@ error: } void -cl_kernel_destroy(void) +cl_kernel_destroy(bool needDestroyProgram) { - if (kernel) clReleaseKernel(kernel); - if (program) clReleaseProgram(program); - kernel = NULL; - program = NULL; + if (kernel) { + clReleaseKernel(kernel); + kernel = NULL; + } + if (needDestroyProgram && program) { + clReleaseProgram(program); + program = NULL; + } } void |