[Beignet] [PATCH v4 3/5] standalone utest for unified OpenCL implementation.

Yang, Rong R rong.r.yang at intel.com
Wed Apr 27 03:07:24 UTC 2016


LGTM, pushed, thanks.
It's better to  add readme for it.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> xionghu.luo at intel.com
> Sent: Saturday, April 23, 2016 0:37
> To: beignet at lists.freedesktop.org
> Cc: Luo, Xionghu <xionghu.luo at intel.com>
> Subject: [Beignet] [PATCH v4 3/5] standalone utest for unified OpenCL
> implementation.
> 
> From: Luo Xionghu <xionghu.luo at intel.com>
> 
> use the variable NOT_BUILD_STAND_ALONE_UTEST to control the build type:
> for beignet build, set it to 1; for stand alone build, do NOT need set it.
> remove all clXXXIntel extension call and such kind of tests since we intend to
> provide the unit test independently for viariant OpenCL implementation;
> replace the clMapBufferIntel/clMapBufferGTTIntel
> with clEnqueueMapBuffer/clEnqueueMapImage; link the utest binary to
> libOpenCL to follow the icd standard; remove the useless env in setenv.sh
> since we need make install the package after build.
> 
> v2:
> fix the indent error;
> use function pointer for extesion case like vme and libva since we link to
> libOpenCL;
> v3: builtin_kernel_block_motion_estimate_intel released kernel twice;
> v4:
> find OpenCL library for standalone utest and link to libcl for not standalone
> utest; check default variables in setenv.sh whether empty before use.
> 
> Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
> ---
>  CMakeLists.txt                                     |  2 +
>  backend/src/backend/program.cpp                    |  4 ++
>  backend/src/llvm/llvm_bitcode_link.cpp             |  2 +
>  src/cl_gbe_loader.cpp                              |  4 +-
>  utests/CMakeLists.txt                              | 78 ++++++++++++++++++----
>  .../builtin_kernel_block_motion_estimate_intel.cpp | 28 +++++++-
>  utests/compiler_copy_image.cpp                     |  8 +--
>  utests/compiler_copy_image1.cpp                    | 24 +++----
>  utests/compiler_copy_image_1d.cpp                  |  8 +--
>  utests/compiler_fill_image.cpp                     |  4 +-
>  utests/compiler_fill_image_3d.cpp                  |  4 +-
>  utests/compiler_movforphi_undef.cpp                |  8 +--
>  utests/runtime_climage_from_boname.cpp             | 14 +++-
>  utests/runtime_flat_address_space.cpp              |  6 +-
>  utests/utest_helper.cpp                            | 22 ++----
>  utests/utest_helper.hpp                            | 42 ++++++++++--
>  16 files changed, 189 insertions(+), 69 deletions(-)
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt index 97725ca..0af63c1 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -32,6 +32,8 @@ configure_file (
>    "src/OCLConfig.h"
>  )
> 
> +set (NOT_BUILD_STAND_ALONE_UTEST 1)
> +
>  INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}
> ${CMAKE_CURRENT_SOURCE_DIR}
>                      ${CMAKE_CURRENT_SOURCE_DIR}/include)
> 
> diff --git a/backend/src/backend/program.cpp
> b/backend/src/backend/program.cpp index 5eee4cb..9c33827 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -781,6 +781,10 @@ namespace gbe {
>      size_t start = 0, end = 0;
> 
>      std::string hdirs = OCL_HEADER_FILE_DIR;
> +    if(hdirs == "")
> +      hdirs = OCL_HEADER_DIR;
> +    if(dirs == "")
> +      dirs = OCL_PCH_OBJECT;
>      std::istringstream hidirs(hdirs);
>      std::string headerFilePath;
>      bool findOcl = false;
> diff --git a/backend/src/llvm/llvm_bitcode_link.cpp
> b/backend/src/llvm/llvm_bitcode_link.cpp
> index 10fccf6..5f087f8 100644
> --- a/backend/src/llvm/llvm_bitcode_link.cpp
> +++ b/backend/src/llvm/llvm_bitcode_link.cpp
> @@ -36,6 +36,8 @@ namespace gbe
>    static Module* createOclBitCodeModule(LLVMContext& ctx, bool
> strictMath)
>    {
>      std::string bitCodeFiles = OCL_BITCODE_LIB_PATH;
> +    if(bitCodeFiles == "")
> +      bitCodeFiles = OCL_BITCODE_BIN;
>      std::istringstream bitCodeFilePath(bitCodeFiles);
>      std::string FilePath;
>      bool findBC = false;
> diff --git a/src/cl_gbe_loader.cpp b/src/cl_gbe_loader.cpp index
> 0ec6c96..b56748b 100644
> --- a/src/cl_gbe_loader.cpp
> +++ b/src/cl_gbe_loader.cpp
> @@ -90,7 +90,7 @@ struct GbeLoaderInitializer
>    bool LoadInterp(const char*& path)
>    {
>      const char* interpPath = getenv("OCL_INTERP_PATH");
> -    if (interpPath == NULL)
> +    if (interpPath == NULL|| !strcmp(interpPath, ""))
>        interpPath = INTERP_OBJECT_DIR;
> 
>      path = interpPath;
> @@ -274,7 +274,7 @@ struct GbeLoaderInitializer
>      }
> 
>      const char* gbePath = getenv("OCL_GBE_PATH");
> -    if (gbePath == NULL)
> +    if (gbePath == NULL || !strcmp(gbePath, ""))
>        gbePath = GBE_OBJECT_DIR;
> 
>      dlhCompiler = dlopen(gbePath, RTLD_LAZY | RTLD_LOCAL); diff --git
> a/utests/CMakeLists.txt b/utests/CMakeLists.txt index db62e38..4742c4a
> 100644
> --- a/utests/CMakeLists.txt
> +++ b/utests/CMakeLists.txt
> @@ -1,3 +1,44 @@
> +#########################################################
> ##############
> +############ # these configurations are copied from beignet root
> +directory cmake for stand alone build.
> +# do NOT set the NOT_BUILD_STAND_ALONE_UTEST if build the utest
> alone.
> +if (NOT NOT_BUILD_STAND_ALONE_UTEST)
> +  message(STATUS "Building Stand Alone Utest")
> +
> +  CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
> +
> +  INCLUDE (FindPkgConfig)
> +  Find_Package(PythonInterp)
> +
> +  # OpenCL
> +  pkg_check_modules(OPENCL REQUIRED OpenCL)
> +  IF(OPENCL_FOUND)
> +    INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS})
> +  ENDIF(OPENCL_FOUND)
> +
> +  # Force Release with debug info
> +  if (NOT CMAKE_BUILD_TYPE)
> +    set (CMAKE_BUILD_TYPE RelWithDebInfo)  endif (NOT
> CMAKE_BUILD_TYPE)
> + message(STATUS "Building mode: " ${CMAKE_BUILD_TYPE})
> +
> +  set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "assure
> + config" FORCE)
> +
> +  # Threads
> +  Find_Package(Threads)
> +
> +  set (CMAKE_CXX_FLAGS "${CMAKE_C_CXX_FLAGS} -std=c++0x
> +-Wno-invalid-offsetof")
> +  set (CMAKE_C_FLAGS "${CMAKE_C_CXX_FLAGS}")
> +  set (CMAKE_CXX_FLAGS_DEBUG          "-O0 -g -DGBE_DEBUG=1")
> +  set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DGBE_DEBUG=1")
> +  set (CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG -
> DGBE_DEBUG=0")
> +  set (CMAKE_CXX_FLAGS_RELEASE        "-O2 -DNDEBUG -DGBE_DEBUG=0")
> +  set (CMAKE_C_FLAGS_DEBUG          "-O0 -g -DGBE_DEBUG=1")
> +  set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DGBE_DEBUG=1")
> +  set (CMAKE_C_FLAGS_MINSIZEREL     "-Os -DNDEBUG -DGBE_DEBUG=0")
> +  set (CMAKE_C_FLAGS_RELEASE        "-O2 -DNDEBUG -DGBE_DEBUG=0")
> +endif (NOT NOT_BUILD_STAND_ALONE_UTEST)
> +#########################################################
> ##############
> +############
> +
>  INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
>                      ${CMAKE_CURRENT_SOURCE_DIR}/../include)
> 
> @@ -27,7 +68,9 @@ set (utests_basic_sources
>    utest_helper.cpp)
> 
>  # the test case with binary kernel
> -set (utests_binary_kernel_sources load_program_from_bin_file.cpp
> enqueue_built_in_kernels.cpp)
> +if (NOT_BUILD_STAND_ALONE_UTEST)
> +  set (utests_binary_kernel_sources load_program_from_bin_file.cpp
> +enqueue_built_in_kernels.cpp) endif (NOT_BUILD_STAND_ALONE_UTEST)
> 
>  set (utests_sources
>    compiler_basic_arithmetic.cpp
> @@ -208,7 +251,6 @@ set (utests_sources
>    test_printf.cpp
>    enqueue_fill_buf.cpp
>    builtin_kernel_max_global_size.cpp
> -  builtin_kernel_block_motion_estimate_intel.cpp
>    image_1D_buffer.cpp
>    image_from_buffer.cpp
>    compare_image_2d_and_1d_array.cpp
> @@ -234,14 +276,16 @@ if (LLVM_VERSION_NODOT VERSION_GREATER 34)
>        compiler_overflow.cpp)
>  endif (LLVM_VERSION_NODOT VERSION_GREATER 34)
> 
> -if (X11_FOUND)
> -  SET(utests_sources
> +if (NOT_BUILD_STAND_ALONE_UTEST)
> +  if (X11_FOUND)
> +    SET(utests_sources
>        ${utests_sources}
>        runtime_climage_from_boname.cpp)
> -  SET(UTESTS_REQUIRED_X11_LIB ${X11_LIBRARIES} ${XEXT_LIBRARIES})
> -else()
> -  SET(UTESTS_REQUIRED_X11_LIB "")
> -endif (X11_FOUND)
> +    SET(UTESTS_REQUIRED_X11_LIB ${X11_LIBRARIES} ${XEXT_LIBRARIES})
> +  else()
> +    SET(UTESTS_REQUIRED_X11_LIB "")
> +  endif (X11_FOUND)
> +endif (NOT_BUILD_STAND_ALONE_UTEST)
> 
>  if (CMRT_FOUND)
>    SET(utests_sources
> @@ -264,8 +308,10 @@ else(GEN_PCI_ID)
>    DEPENDS ${GBE_BIN_FILE} ${kernel_bin}.cl)
>  endif(GEN_PCI_ID)
> 
> -ADD_CUSTOM_TARGET(kernel_bin.bin
> -    DEPENDS ${kernel_bin}.bin)
> +if (NOT_BUILD_STAND_ALONE_UTEST)
> +  SET(utests_sources ${utests_sources}
> +builtin_kernel_block_motion_estimate_intel.cpp)
> +  ADD_CUSTOM_TARGET(kernel_bin.bin DEPENDS ${kernel_bin}.bin) endif
> +(NOT_BUILD_STAND_ALONE_UTEST)
> 
>  add_custom_command(OUTPUT
> ${CMAKE_CURRENT_SOURCE_DIR}/generated
>      COMMAND mkdir ${CMAKE_CURRENT_SOURCE_DIR}/generated -p @@ -
> 299,11 +345,19 @@ endif ()
> 
>  ADD_LIBRARY(utests SHARED ${utests_sources})
> 
> -TARGET_LINK_LIBRARIES(utests cl m ${OPENGL_LIBRARIES}
> ${UTESTS_REQUIRED_EGL_LIB} ${CMAKE_THREAD_LIBS_INIT}
> ${UTESTS_REQUIRED_X11_LIB})
> +if (NOT_BUILD_STAND_ALONE_UTEST)
> +  TARGET_LINK_LIBRARIES(utests cl m ${OPENGL_LIBRARIES}
> +${UTESTS_REQUIRED_EGL_LIB} ${CMAKE_THREAD_LIBS_INIT}
> +${UTESTS_REQUIRED_X11_LIB})
> +else()
> +  TARGET_LINK_LIBRARIES(utests ${OPENCL_LIBRARIES} m
> +${OPENGL_LIBRARIES} ${UTESTS_REQUIRED_EGL_LIB}
> +${CMAKE_THREAD_LIBS_INIT} ${UTESTS_REQUIRED_X11_LIB})
> +endif()
> 
>  ADD_EXECUTABLE(utest_run utest_run.cpp)
> TARGET_LINK_LIBRARIES(utest_run utests) -ADD_DEPENDENCIES (utest_run
> kernel_bin.bin)
> +
> +if (NOT_BUILD_STAND_ALONE_UTEST)
> +  ADD_DEPENDENCIES (utest_run kernel_bin.bin) endif
> +(NOT_BUILD_STAND_ALONE_UTEST)
> +
>  ADD_DEPENDENCIES (utests utest_generator)
> 
>  ADD_EXECUTABLE(flat_address_space runtime_flat_address_space.cpp)
> diff --git a/utests/builtin_kernel_block_motion_estimate_intel.cpp
> b/utests/builtin_kernel_block_motion_estimate_intel.cpp
> index 12bcb7d..335a6dd 100644
> --- a/utests/builtin_kernel_block_motion_estimate_intel.cpp
> +++ b/utests/builtin_kernel_block_motion_estimate_intel.cpp
> @@ -1,6 +1,11 @@
>  #include "utest_helper.hpp"
>  #include <string.h>
> 
> +typedef cl_accelerator_intel (OCLCREATEACCELERATORINTEL)(cl_context,
> +cl_accelerator_type_intel accel_type, size_t desc_sz, const void* desc,
> +cl_int* errcode_ret); OCLCREATEACCELERATORINTEL *
> +oclCreateAcceleratorIntel = NULL; typedef cl_int
> +(OCLRELEASEACCELERATORINTEL)(cl_accelerator_intel accel_type);
> +OCLRELEASEACCELERATORINTEL * oclReleaseAcceleratorIntel = NULL;
> +
>  void builtin_kernel_block_motion_estimate_intel(void)
>  {
>    char* built_in_kernel_names;
> @@ -29,7 +34,16 @@ void builtin_kernel_block_motion_estimate_intel(void)
>                                            CL_ME_SAD_ADJUST_MODE_NONE_INTEL,   //0x0
>                                            CL_ME_SEARCH_PATH_RADIUS_16_12_INTEL //0x5
>                                            };
> -  cl_accelerator_intel accel = clCreateAcceleratorINTEL(ctx,
> CL_ACCELERATOR_TYPE_MOTION_ESTIMATION_INTEL,sizeof(cl_motion_est
> imation_desc_intel), &vmedesc, &err);
> +#ifdef CL_VERSION_1_2
> +  oclCreateAcceleratorIntel =
> +(OCLCREATEACCELERATORINTEL*)clGetExtensionFunctionAddressForPlatfo
> rm(pl
> +atform, "clCreateAcceleratorINTEL"); #else
> +  oclCreateAcceleratorIntel  =
> +(OCLCREATEACCELERATORINTEL*)clGetExtensionFunctionAddress("clCreat
> eAcce
> +leratorINTEL");
> +#endif
> +  if(!oclCreateAcceleratorIntel){
> +    fprintf(stderr, "Failed to get extension clCreateImageFromLibvaIntel\n");
> +    exit(1);
> +  }
> +  cl_accelerator_intel accel = oclCreateAcceleratorIntel(ctx,
> +CL_ACCELERATOR_TYPE_MOTION_ESTIMATION_INTEL,sizeof(cl_motion_e
> stimation
> +_desc_intel), &vmedesc, &err);
>    OCL_ASSERT(accel != NULL);
> 
>    const size_t w = 71; //80
> @@ -98,8 +112,16 @@ void
> builtin_kernel_block_motion_estimate_intel(void)
>    }
>    OCL_UNMAP_BUFFER(2);
> 
> -  clReleaseAcceleratorINTEL(accel);
> -  clReleaseKernel(kernel);
> +#ifdef CL_VERSION_1_2
> +  oclReleaseAcceleratorIntel =
> +(OCLRELEASEACCELERATORINTEL*)clGetExtensionFunctionAddressForPlatf
> orm(p
> +latform, "clReleaseAcceleratorINTEL"); #else
> +  oclReleaseAcceleratorIntel  =
> +(OCLRELEASEACCELERATORINTEL*)clGetExtensionFunctionAddress("clRele
> aseAc
> +celeratorINTEL");
> +#endif
> +  if(!oclReleaseAcceleratorIntel){
> +    fprintf(stderr, "Failed to get extension clCreateImageFromLibvaIntel\n");
> +    exit(1);
> +  }
> +  oclReleaseAcceleratorIntel(accel);
>    clReleaseProgram(built_in_prog);
>    free(built_in_kernel_names);
>    free(image_data1);
> diff --git a/utests/compiler_copy_image.cpp
> b/utests/compiler_copy_image.cpp index 150fd8a..ca15cc6 100644
> --- a/utests/compiler_copy_image.cpp
> +++ b/utests/compiler_copy_image.cpp
> @@ -44,13 +44,13 @@ static void compiler_copy_image(void)
>    OCL_NDRANGE(2);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> -  OCL_MAP_BUFFER(1);
> +  OCL_MAP_BUFFER_GTT(0);
> +  OCL_MAP_BUFFER_GTT(1);
>    for (uint32_t j = 0; j < h; ++j)
>      for (uint32_t i = 0; i < w; i++)
>        OCL_ASSERT(((uint32_t*)buf_data[0])[j * w + i] ==
> ((uint32_t*)buf_data[1])[j * w + i]);
> -  OCL_UNMAP_BUFFER(0);
> -  OCL_UNMAP_BUFFER(1);
> +  OCL_UNMAP_BUFFER_GTT(0);
> +  OCL_UNMAP_BUFFER_GTT(1);
> 
>    OCL_CALL(clReleaseSampler, sampler);
>  }
> diff --git a/utests/compiler_copy_image1.cpp
> b/utests/compiler_copy_image1.cpp index 659dddc..cc9ef85 100644
> --- a/utests/compiler_copy_image1.cpp
> +++ b/utests/compiler_copy_image1.cpp
> @@ -57,12 +57,12 @@ static void compiler_copy_image1(void)
>    OCL_NDRANGE(2);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> -  OCL_MAP_BUFFER(1);
> -  OCL_MAP_BUFFER(2);
> -  OCL_MAP_BUFFER(3);
> -  OCL_MAP_BUFFER(4);
> -  OCL_MAP_BUFFER(5);
> +  OCL_MAP_BUFFER_GTT(0);
> +  OCL_MAP_BUFFER_GTT(1);
> +  OCL_MAP_BUFFER_GTT(2);
> +  OCL_MAP_BUFFER_GTT(3);
> +  OCL_MAP_BUFFER_GTT(4);
> +  OCL_MAP_BUFFER_GTT(5);
> 
>    for(uint32_t k = 0; k < 5; k++)
>    {
> @@ -70,12 +70,12 @@ static void compiler_copy_image1(void)
>        for (uint32_t i = 0; i < w; i++)
>          OCL_ASSERT(((uint32_t*)buf_data[0])[j * w + i] ==
> ((uint32_t*)buf_data[1 + k])[j * w + i]);
>    }
> -  OCL_UNMAP_BUFFER(0);
> -  OCL_UNMAP_BUFFER(1);
> -  OCL_UNMAP_BUFFER(2);
> -  OCL_UNMAP_BUFFER(3);
> -  OCL_UNMAP_BUFFER(4);
> -  OCL_UNMAP_BUFFER(5);
> +  OCL_UNMAP_BUFFER_GTT(0);
> +  OCL_UNMAP_BUFFER_GTT(1);
> +  OCL_UNMAP_BUFFER_GTT(2);
> +  OCL_UNMAP_BUFFER_GTT(3);
> +  OCL_UNMAP_BUFFER_GTT(4);
> +  OCL_UNMAP_BUFFER_GTT(5);
> 
>    OCL_CALL(clReleaseSampler, sampler);
>  }
> diff --git a/utests/compiler_copy_image_1d.cpp
> b/utests/compiler_copy_image_1d.cpp
> index 5af6a77..6599d30 100644
> --- a/utests/compiler_copy_image_1d.cpp
> +++ b/utests/compiler_copy_image_1d.cpp
> @@ -39,14 +39,14 @@ static void compiler_copy_image_1d(void)
>    OCL_NDRANGE(1);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> -  OCL_MAP_BUFFER(1);
> +  OCL_MAP_BUFFER_GTT(0);
> +  OCL_MAP_BUFFER_GTT(1);
>    for (uint32_t i = 0; i < w; i++) {
>        //printf (" %x", ((uint32_t*)buf_data[1])[i]);
>        OCL_ASSERT(((uint32_t*)buf_data[0])[i] == ((uint32_t*)buf_data[1])[i]);
>    }
> -  OCL_UNMAP_BUFFER(0);
> -  OCL_UNMAP_BUFFER(1);
> +  OCL_UNMAP_BUFFER_GTT(0);
> +  OCL_UNMAP_BUFFER_GTT(1);
>  }
> 
>  MAKE_UTEST_FROM_FUNCTION(compiler_copy_image_1d);
> diff --git a/utests/compiler_fill_image.cpp b/utests/compiler_fill_image.cpp
> index 5a38b8c..0fb53df 100644
> --- a/utests/compiler_fill_image.cpp
> +++ b/utests/compiler_fill_image.cpp
> @@ -34,11 +34,11 @@ static void compiler_fill_image(void)
>    OCL_NDRANGE(2);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> +  OCL_MAP_BUFFER_GTT(0);
>    for (uint32_t j = 0; j < h; ++j)
>      for (uint32_t i = 0; i < w; i++)
>        OCL_ASSERT(((uint32_t*)buf_data[0])[j * w + i] == 0x78563412);
> -  OCL_UNMAP_BUFFER(0);
> +  OCL_UNMAP_BUFFER_GTT(0);
>  }
> 
>  MAKE_UTEST_FROM_FUNCTION(compiler_fill_image);
> diff --git a/utests/compiler_fill_image_3d.cpp
> b/utests/compiler_fill_image_3d.cpp
> index ec96e80..fd84e76 100644
> --- a/utests/compiler_fill_image_3d.cpp
> +++ b/utests/compiler_fill_image_3d.cpp
> @@ -39,12 +39,12 @@ static void compiler_fill_image_3d(void)
>    OCL_NDRANGE(3);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> +  OCL_MAP_BUFFER_GTT(0);
>    for (uint32_t k = 0; k < depth; k++)
>      for (uint32_t j = 0; j < h; ++j)
>        for (uint32_t i = 0; i < w; i++)
>          OCL_ASSERT(((uint32_t*)buf_data[0])[k*w*h + j*w + i] == 0x78563412);
> -  OCL_UNMAP_BUFFER(0);
> +  OCL_UNMAP_BUFFER_GTT(0);
>  }
> 
>  MAKE_UTEST_FROM_FUNCTION(compiler_fill_image_3d);
> diff --git a/utests/compiler_movforphi_undef.cpp
> b/utests/compiler_movforphi_undef.cpp
> index 8f1e66e..01eae06 100644
> --- a/utests/compiler_movforphi_undef.cpp
> +++ b/utests/compiler_movforphi_undef.cpp
> @@ -42,8 +42,8 @@ static void compiler_movforphi_undef(void)
>    OCL_NDRANGE(2);
> 
>    // Check result
> -  OCL_MAP_BUFFER(0);
> -  OCL_MAP_BUFFER(1);
> +  OCL_MAP_BUFFER_GTT(0);
> +  OCL_MAP_BUFFER_GTT(1);
>    // Just compare the initial 2 data is enough for this case, as the initial 2 data
> must in the first
>    // tile box and we can just get the correct coords.
>    for (uint32_t j = 0; j < 1; ++j)
> @@ -52,8 +52,8 @@ static void compiler_movforphi_undef(void)
>        if (i == 0)
>          OCL_ASSERT(((uint32_t*)buf_data[0])[j * w + i + 1] ==
> ((uint32_t*)buf_data[1])[j * w + i]);
>      }
> -  OCL_UNMAP_BUFFER(0);
> -  OCL_UNMAP_BUFFER(1);
> +  OCL_UNMAP_BUFFER_GTT(0);
> +  OCL_UNMAP_BUFFER_GTT(1);
> 
>    OCL_CALL(clReleaseSampler, sampler);
>  }
> diff --git a/utests/runtime_climage_from_boname.cpp
> b/utests/runtime_climage_from_boname.cpp
> index 4e7f06a..2160886 100644
> --- a/utests/runtime_climage_from_boname.cpp
> +++ b/utests/runtime_climage_from_boname.cpp
> @@ -22,6 +22,9 @@ extern "C"
>  #include <X11/extensions/extutil.h>
>  }
> 
> +typedef cl_mem (OCLCREATEIMAGEFROMLIBVAINTEL)(cl_context, const
> +cl_libva_image *, cl_int *); OCLCREATEIMAGEFROMLIBVAINTEL
> +*oclCreateImageFromLibvaIntel = NULL;
> +
>  // part of following code is copy from beignet/src/x11/  typedef struct {
>      CARD8   reqType;
> @@ -151,7 +154,16 @@ void runtime_climage_from_boname(void)
>    imageParam.height = h - hStart;
>    imageParam.row_pitch = w;
> 
> -  cl_mem dst = clCreateImageFromLibvaIntel(ctx, &imageParam, NULL);
> +#ifdef CL_VERSION_1_2
> +  oclCreateImageFromLibvaIntel = (OCLCREATEIMAGEFROMLIBVAINTEL
> +*)clGetExtensionFunctionAddressForPlatform(platform,
> +"clCreateImageFromLibvaIntel"); #else
> +  oclCreateImageFromLibvaIntel = (OCLCREATEIMAGEFROMLIBVAINTEL
> +*)clGetExtensionFunctionAddress("clCreateImageFromLibvaIntel");
> +#endif
> +  if(!oclCreateImageFromLibvaIntel){
> +    fprintf(stderr, "Failed to get extension clCreateImageFromLibvaIntel\n");
> +    exit(1);
> +  }
> +  cl_mem dst = oclCreateImageFromLibvaIntel(ctx, &imageParam, NULL);
> 
>    // Run the kernel
>    OCL_SET_ARG(0, sizeof(cl_mem), &dst); diff --git
> a/utests/runtime_flat_address_space.cpp
> b/utests/runtime_flat_address_space.cpp
> index 9b8bece..6430edb 100644
> --- a/utests/runtime_flat_address_space.cpp
> +++ b/utests/runtime_flat_address_space.cpp
> @@ -53,7 +53,7 @@ main(int argc, char *argv[])
>                                    NULL);
> 
>      // Be sure that everything run fine
> -    dst_buffer = (int *) clMapBufferIntel(dst[j], &status);
> +    dst_buffer = (int *)clEnqueueMapBuffer(queue, dst[j], CL_TRUE,
> + CL_MAP_READ, 0, sizeof(int)*n, 0, NULL, NULL, &status);
>      if (status != CL_SUCCESS)
>        goto error;
>      for (uint32_t i = 0; i < n; ++i)
> @@ -61,13 +61,11 @@ main(int argc, char *argv[])
>          fprintf(stderr, "run-time flat address space failed\n");
>          exit(-1);
>        }
> -    OCL_CALL (clUnmapBufferIntel, dst[j]);
> +    clEnqueueUnmapMemObject(queue, dst[j], dst_buffer, 0, NULL, NULL);
>    }
> 
>    for (uint32_t j = 0; j < 24; ++j) OCL_CALL (clReleaseMemObject, dst[j]);
>    cl_test_destroy();
> -  printf("%i memory leaks\n", clReportUnfreedIntel());
> -  assert(clReportUnfreedIntel() == 0);
> 
>  error:
>    return status;
> diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp index
> 0aab208..426473a 100644
> --- a/utests/utest_helper.cpp
> +++ b/utests/utest_helper.cpp
> @@ -215,13 +215,7 @@ cl_do_kiss_path(const char *file, cl_device_id device)
>    const char *kiss_path = getenv("OCL_KERNEL_PATH");
>    size_t sz = strlen(file);
> 
> -  if (device == NULL)
> -    sub_path = "";
> -  else {
> -    if (clGetGenVersionIntel(device, &ver) != CL_SUCCESS)
> -      clpanic("Unable to get Gen version", -1);
> -    sub_path = "";
> -  }
> +  sub_path = "";
> 
>    if (kiss_path == NULL)
>      clpanic("set OCL_KERNEL_PATH. This is where the kiss kernels are", -1);
> @@ -244,9 +238,9 @@ cl_kernel_init(const char *file_name, const char
> *kernel_name, int format, const
>    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) {
> +    if (format == LLVM) {
> +      assert(0);
> +    } 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?", @@ -561,8 +555,6 @@ cl_test_destroy(void)
> {
>    cl_kernel_destroy();
>    cl_ocl_destroy();
> -  printf("%i memory leaks\n", clReportUnfreedIntel());
> -  assert(clReportUnfreedIntel() == 0);
>  }
> 
>  void
> @@ -571,7 +563,7 @@ cl_buffer_destroy(void)
>    int i;
>    for (i = 0; i < MAX_BUFFER_N; ++i) {
>      if (buf_data[i] != NULL) {
> -      clUnmapBufferIntel(buf[i]);
> +      clEnqueueUnmapMemObject(queue, buf[i], buf_data[i], 0, NULL,
> + NULL);
>        buf_data[i] = NULL;
>      }
>      if (buf[i] != NULL) {
> @@ -589,7 +581,7 @@ cl_report_perf_counters(cl_mem perf)
>    uint32_t i;
>    if (perf == NULL)
>      return;
> -  start = (uint32_t*) clMapBufferIntel(perf, &status);
> +  start = (uint32_t*)clEnqueueMapBuffer(queue, perf, CL_TRUE,
> + CL_MAP_READ, 0,  128 * sizeof(uint32_t)/*size*/, 0, NULL, NULL,
> + &status);
>    assert(status == CL_SUCCESS && start != NULL);
>    end = start + 128;
> 
> @@ -614,7 +606,7 @@ cl_report_perf_counters(cl_mem perf)
>    }
>    printf("\n\n");
> 
> -  clUnmapBufferIntel(perf);
> +  clEnqueueUnmapMemObject(queue, perf, start, 0, NULL, NULL);
>  }
> 
>  struct bmphdr {
> diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp index
> 251fbcf..70b983b 100644
> --- a/utests/utest_helper.hpp
> +++ b/utests/utest_helper.hpp
> @@ -123,24 +123,58 @@ extern EGLSurface  eglSurface;
>  #define OCL_CREATE_SAMPLER(SAMPLER, ADDRESS_MODE, FILTER_MODE)
> \
>      OCL_CALL2(clCreateSampler, SAMPLER, ctx, 0, ADDRESS_MODE,
> FILTER_MODE)
> 
> +#define OCL_CALL_MAP(FN, ID, RET, ...) \
> +  do { \
> +    cl_int status; \
> +    size_t size = 0; \
> +    status = clGetMemObjectInfo(buf[ID], CL_MEM_SIZE, sizeof(size), &size,
> NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    RET = FN(__VA_ARGS__, CL_TRUE, CL_MAP_READ, 0, size, 0, NULL, NULL,
> &status);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +  } while (0)
> +
>  #define OCL_MAP_BUFFER(ID) \
> -    OCL_CALL2(clMapBufferIntel, buf_data[ID], buf[ID])
> +    OCL_CALL_MAP(clEnqueueMapBuffer, ID, buf_data[ID], queue, buf[ID])
> 
>  #define OCL_UNMAP_BUFFER(ID) \
>    do { \
>      if (buf[ID] != NULL) { \
> -      OCL_CALL (clUnmapBufferIntel, buf[ID]); \
> +      OCL_CALL (clEnqueueUnmapMemObject, queue, buf[ID], buf_data[ID],
> + 0, NULL, NULL); \
>        buf_data[ID] = NULL; \
>      } \
>    } while (0)
> 
> +#define OCL_CALL_MAP_GTT(FN, ID, RET, ...) \
> +  do { \
> +    cl_int status; \
> +    size_t image_row_pitch = 0; \
> +    status = clGetImageInfo(buf[ID], CL_IMAGE_ROW_PITCH,
> sizeof(image_row_pitch), &image_row_pitch, NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    size_t image_slice_pitch = 0; \
> +    status = clGetImageInfo(buf[ID], CL_IMAGE_ROW_PITCH,
> sizeof(image_slice_pitch), &image_slice_pitch, NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    size_t image_width = 0; \
> +    status = clGetImageInfo(buf[ID], CL_IMAGE_WIDTH, sizeof(image_width),
> &image_width, NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    size_t image_height = 0; \
> +    status = clGetImageInfo(buf[ID], CL_IMAGE_HEIGHT,
> sizeof(image_height), &image_height, NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    size_t image_depth= 0; \
> +    status = clGetImageInfo(buf[ID], CL_IMAGE_DEPTH, sizeof(image_depth),
> &image_depth, NULL);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +    size_t origin[3] = {0, 0, 0}; \
> +    size_t region[3] = {image_width, image_height, image_depth}; \
> +    RET = FN(__VA_ARGS__, CL_TRUE, CL_MAP_READ, origin, region,
> &image_row_pitch, &image_slice_pitch, 0, NULL, NULL, &status);\
> +    if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \
> +  } while (0)
> +
>  #define OCL_MAP_BUFFER_GTT(ID) \
> -    OCL_CALL2(clMapBufferGTTIntel, buf_data[ID], buf[ID])
> +    OCL_CALL_MAP_GTT(clEnqueueMapImage, ID, buf_data[ID], queue,
> + buf[ID])
> 
>  #define OCL_UNMAP_BUFFER_GTT(ID) \
>    do { \
>      if (buf[ID] != NULL) { \
> -      OCL_CALL (clUnmapBufferGTTIntel, buf[ID]); \
> +      OCL_CALL (clEnqueueUnmapMemObject, queue, buf[ID], buf_data[ID],
> + 0, NULL, NULL); \
>        buf_data[ID] = NULL; \
>      } \
>    } while (0)
> --
> 2.1.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list