From 8726605ea77b5633c1f31c71e5a20aadcc38ed44 Mon Sep 17 00:00:00 2001 From: Pan Xiuli Date: Tue, 24 Jan 2017 16:47:58 +0800 Subject: Utest: Add OCL20 into utest and check version in runtime The utest should always be built and we can check ocl version at the test begin. Contributor: Rebecca N. Palmer Signed-off-by: Pan Xiuli Reviewed-by: Yang Rong --- utests/CMakeLists.txt | 22 +++++++++------------- utests/compiler_atomic_functions_20.cpp | 4 +++- utests/compiler_device_enqueue.cpp | 4 +++- utests/compiler_generic_atomic.cpp | 2 ++ utests/compiler_generic_pointer.cpp | 2 ++ utests/compiler_pipe_builtin.cpp | 9 ++++++--- utests/compiler_program_global.cpp | 2 ++ utests/compiler_sampler.cpp | 2 ++ utests/runtime_pipe_query.cpp | 2 ++ utests/utest_helper.cpp | 22 ++++++++++++++++------ utests/utest_helper.hpp | 4 ++-- 11 files changed, 49 insertions(+), 26 deletions(-) diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt index db61844f..43cf7f35 100644 --- a/utests/CMakeLists.txt +++ b/utests/CMakeLists.txt @@ -289,7 +289,15 @@ set (utests_sources compiler_mix.cpp compiler_math_3op.cpp compiler_bsort.cpp - builtin_kernel_block_motion_estimate_intel.cpp) + builtin_kernel_block_motion_estimate_intel.cpp + compiler_program_global.cpp + compiler_generic_atomic.cpp + compiler_atomic_functions_20.cpp + compiler_sampler.cpp + compiler_generic_pointer.cpp + runtime_pipe_query.cpp + compiler_pipe_builtin.cpp + compiler_device_enqueue.cpp) if (LLVM_VERSION_NODOT VERSION_GREATER 34) SET(utests_sources @@ -297,18 +305,6 @@ if (LLVM_VERSION_NODOT VERSION_GREATER 34) compiler_overflow.cpp) endif (LLVM_VERSION_NODOT VERSION_GREATER 34) -if (ENABLE_OPENCL_20) - SET(utests_sources - ${utests_sources} - compiler_program_global.cpp - compiler_generic_atomic.cpp - compiler_atomic_functions_20.cpp - compiler_sampler.cpp - compiler_generic_pointer.cpp - runtime_pipe_query.cpp - compiler_pipe_builtin.cpp - compiler_device_enqueue.cpp) -endif (ENABLE_OPENCL_20) if (NOT_BUILD_STAND_ALONE_UTEST) if (X11_FOUND) diff --git a/utests/compiler_atomic_functions_20.cpp b/utests/compiler_atomic_functions_20.cpp index ea1ace51..e11d0772 100644 --- a/utests/compiler_atomic_functions_20.cpp +++ b/utests/compiler_atomic_functions_20.cpp @@ -58,6 +58,8 @@ static void cpu_compiler_atomic(int *dst, int *src) static void compiler_atomic_functions(const char* kernel_name) { + if(!cl_check_ocl20(false)) + return; const size_t n = GROUP_NUM * LOCAL_SIZE; int cpu_dst[24] = {0}, cpu_src[256]; @@ -65,7 +67,7 @@ static void compiler_atomic_functions(const char* kernel_name) locals[0] = LOCAL_SIZE; // Setup kernel and buffers - OCL_CREATE_KERNEL_FROM_FILE("compiler_atomic_functions_20", kernel_name); + OCL_CALL(cl_kernel_init, "compiler_atomic_functions_20.cl", kernel_name, SOURCE, "-cl-std=CL2.0"); OCL_CREATE_BUFFER(buf[0], 0, 24 * sizeof(int), NULL); OCL_CREATE_BUFFER(buf[1], 0, locals[0] * sizeof(int), NULL); OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); diff --git a/utests/compiler_device_enqueue.cpp b/utests/compiler_device_enqueue.cpp index a9e3e2df..698be4d8 100644 --- a/utests/compiler_device_enqueue.cpp +++ b/utests/compiler_device_enqueue.cpp @@ -2,12 +2,14 @@ void compiler_device_enqueue(void) { + if(!cl_check_ocl20(false)) + return; const size_t n = 32; const uint32_t global_sz = 3; uint32_t result = 0; // Setup kernel and buffers - OCL_CREATE_KERNEL("compiler_device_enqueue"); + OCL_CALL(cl_kernel_init, "compiler_device_enqueue.cl", "compiler_device_enqueue", SOURCE, "-cl-std=CL2.0"); OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(uint32_t), NULL); OCL_SET_ARG(0, sizeof(uint32_t), &global_sz); OCL_SET_ARG(1, sizeof(cl_mem), &buf[0]); diff --git a/utests/compiler_generic_atomic.cpp b/utests/compiler_generic_atomic.cpp index 9ed5f531..e35e994a 100644 --- a/utests/compiler_generic_atomic.cpp +++ b/utests/compiler_generic_atomic.cpp @@ -3,6 +3,8 @@ template void test_atomic(const char* kernelName) { + if(!cl_check_ocl20(false)) + return; const int n = 16; T cpu_src[16]; diff --git a/utests/compiler_generic_pointer.cpp b/utests/compiler_generic_pointer.cpp index 5984694b..318312ad 100644 --- a/utests/compiler_generic_pointer.cpp +++ b/utests/compiler_generic_pointer.cpp @@ -3,6 +3,8 @@ template void test(const char* kernelName) { + if(!cl_check_ocl20(false)) + return; const int n = 16; T cpu_src[16]; diff --git a/utests/compiler_pipe_builtin.cpp b/utests/compiler_pipe_builtin.cpp index c8ec077e..99270d19 100644 --- a/utests/compiler_pipe_builtin.cpp +++ b/utests/compiler_pipe_builtin.cpp @@ -8,11 +8,13 @@ typedef struct{ #define PIPE_BUILTIN(TYPE,GROUP) \ static void compiler_pipe_##GROUP##_##TYPE(void) \ { \ + if(!cl_check_ocl20(false))\ + return;\ const size_t w = 16; \ uint32_t ans_host = 0; \ uint32_t ans_device = 0; \ /* pipe write kernel*/ \ - OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_"#GROUP"_write_"#TYPE); \ + OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_"#GROUP"_write_"#TYPE, SOURCE, "-cl-std=CL2.0");\ OCL_CALL2(clCreatePipe, buf[0], ctx, 0, sizeof(TYPE), w, NULL);\ OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, w * sizeof(TYPE), NULL);\ OCL_MAP_BUFFER(1);\ @@ -26,7 +28,7 @@ static void compiler_pipe_##GROUP##_##TYPE(void) \ OCL_NDRANGE(1);\ OCL_CALL(clReleaseKernel, kernel);\ /* pipe read kernel */\ - OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_"#GROUP"_read_"#TYPE);\ + OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_"#GROUP"_read_"#TYPE, SOURCE, "-cl-std=CL2.0");\ OCL_CREATE_BUFFER(buf[2], CL_MEM_READ_WRITE, w * sizeof(TYPE), NULL);\ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);\ OCL_SET_ARG(1, sizeof(cl_mem), &buf[2]);\ @@ -52,8 +54,9 @@ PIPE_BUILTIN(mystruct, workgroup) static void compiler_pipe_query(void) { const size_t w = 32; const size_t sz = 16; + if(!cl_check_ocl20(false)){return;} /* pipe write kernel */ - OCL_CREATE_KERNEL_FROM_FILE("compiler_pipe_builtin", "compiler_pipe_query"); + OCL_CALL(cl_kernel_init, "compiler_pipe_builtin.cl", "compiler_pipe_query", SOURCE, "-cl-std=CL2.0"); OCL_CALL2(clCreatePipe, buf[0], ctx, 0, sizeof(uint32_t), w, NULL); OCL_CREATE_BUFFER(buf[1], CL_MEM_READ_WRITE, sz * sizeof(uint32_t), NULL); OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); diff --git a/utests/compiler_program_global.cpp b/utests/compiler_program_global.cpp index a583c60a..caadf8b8 100644 --- a/utests/compiler_program_global.cpp +++ b/utests/compiler_program_global.cpp @@ -21,6 +21,8 @@ static int init_program(const char* name, cl_context ctx, cl_program *pg ) void compiler_program_global() { + if(!cl_check_ocl20(false)) + return; const int n = 16; cl_int err; diff --git a/utests/compiler_sampler.cpp b/utests/compiler_sampler.cpp index f8bf622c..853e052c 100644 --- a/utests/compiler_sampler.cpp +++ b/utests/compiler_sampler.cpp @@ -3,6 +3,8 @@ void compiler_sampler(void) { + if(!cl_check_ocl20(false)) + return; OCL_CREATE_KERNEL("compiler_sampler"); OCL_ASSERT(ctx != 0); diff --git a/utests/runtime_pipe_query.cpp b/utests/runtime_pipe_query.cpp index 3ce82580..e46f5ff9 100644 --- a/utests/runtime_pipe_query.cpp +++ b/utests/runtime_pipe_query.cpp @@ -1,6 +1,8 @@ #include #include "utest_helper.hpp" static void runtime_pipe_query(void) { + if(!cl_check_ocl20(false)) + return; const size_t w = 16; const size_t sz = 8; cl_uint retnum, retsz; diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index b57d2ada..7052a149 100644 --- a/utests/utest_helper.cpp +++ b/utests/utest_helper.cpp @@ -939,13 +939,14 @@ int cl_check_subgroups_short(void) return 1; } -int cl_check_ocl20(void) +int cl_check_ocl20(bool or_beignet) { size_t param_value_size; size_t ret_sz; OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_OPENCL_C_VERSION, 0, 0, ¶m_value_size); if(param_value_size == 0) { printf("Not OpenCL 2.0 device, "); + if(or_beignet){ if(cl_check_beignet()) { printf("Beignet extension test!"); return 1; @@ -953,6 +954,10 @@ int cl_check_ocl20(void) printf("Not beignet device , Skip!"); return 0; } + }else{ + printf("Skip!"); + return 0; + } } char* device_version_str = (char* )malloc(param_value_size * sizeof(char) ); OCL_CALL(clGetDeviceInfo, device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, (void*)device_version_str, &ret_sz); @@ -961,11 +966,16 @@ int cl_check_ocl20(void) if(!strstr(device_version_str, "2.0")) { free(device_version_str); printf("Not OpenCL 2.0 device, "); - if(cl_check_beignet()) { - printf("Beignet extension test!"); - return 1; - } else { - printf("Not beignet device , Skip!"); + if(or_beignet){ + if(cl_check_beignet()) { + printf("Beignet extension test!"); + return 1; + } else { + printf("Not beignet device , Skip!"); + return 0; + } + }else{ + printf("Skip!"); return 0; } } diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp index a7613258..1bc810cf 100644 --- a/utests/utest_helper.hpp +++ b/utests/utest_helper.hpp @@ -310,8 +310,8 @@ extern clGetKernelSubGroupInfoKHR_cb* utestclGetKernelSubGroupInfoKHR; /* Check if cl_intel_motion_estimation enabled. */ extern int cl_check_motion_estimation(void); -/* Check is cl version 2.0. */ -extern int cl_check_ocl20(void); +/* Check is cl version 2.0 or Beignet extension. */ +extern int cl_check_ocl20(bool or_beignet = true); /* Check is FP16 enabled. */ extern int cl_check_half(void); -- cgit v1.2.1