standalone utest for unified OpenCL implementation.

Submitted by Luo, Xionghu on March 18, 2016, 11:36 a.m.

Details

Message ID 1458300960-22122-1-git-send-email-xionghu.luo@intel.com
State New
Headers show
Series "standalone utest for unified OpenCL implementation." ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Luo, Xionghu March 18, 2016, 11:36 a.m.
From: Luo Xionghu <xionghu.luo@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.

Signed-off-by: Luo Xionghu <xionghu.luo@intel.com>
---
 CMakeLists.txt                        |  2 ++
 utests/CMakeLists.txt                 | 58 ++++++++++++++++++++++++++++++-----
 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_flat_address_space.cpp |  6 ++--
 utests/setenv.sh.in                   |  5 ---
 utests/utest_helper.cpp               | 22 +++++--------
 utests/utest_helper.hpp               | 42 ++++++++++++++++++++++---
 12 files changed, 127 insertions(+), 64 deletions(-)

Patch hide | download patch | download mbox

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/utests/CMakeLists.txt b/utests/CMakeLists.txt
index db62e38..7b636ee 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -1,3 +1,37 @@ 
+###################################################################################
+# 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")
+  message(STATUS "Building mode: " ${CMAKE_BUILD_TYPE})
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
+
+INCLUDE (FindPkgConfig)
+Find_Package(PythonInterp)
+
+# Force Release with debug info
+if (NOT CMAKE_BUILD_TYPE)
+  set (CMAKE_BUILD_TYPE RelWithDebInfo)
+endif (NOT 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 +61,9 @@  set (utests_basic_sources
   utest_helper.cpp)
 
 # the test case with binary kernel
+if (NOT_BUILD_STAND_ALONE_UTEST)
 set (utests_binary_kernel_sources load_program_from_bin_file.cpp enqueue_built_in_kernels.cpp)
+endif ()
 
 set (utests_sources
   compiler_basic_arithmetic.cpp
@@ -208,7 +244,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
@@ -233,15 +268,16 @@  if (LLVM_VERSION_NODOT VERSION_GREATER 34)
       ${utests_sources}
       compiler_overflow.cpp)
 endif (LLVM_VERSION_NODOT VERSION_GREATER 34)
-
+if (NOT_BUILD_STAND_ALONE_UTEST)
 if (X11_FOUND)
-  SET(utests_sources
-      ${utests_sources}
-      runtime_climage_from_boname.cpp)
+  # 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)
+endif (NOT_BUILD_STAND_ALONE_UTEST)
 
 if (CMRT_FOUND)
   SET(utests_sources
@@ -264,8 +300,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 ()
 
 add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/generated
     COMMAND mkdir ${CMAKE_CURRENT_SOURCE_DIR}/generated -p
@@ -299,11 +337,15 @@  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})
+TARGET_LINK_LIBRARIES(utests OpenCL m ${OPENGL_LIBRARIES} ${UTESTS_REQUIRED_EGL_LIB} ${CMAKE_THREAD_LIBS_INIT} ${UTESTS_REQUIRED_X11_LIB})
 
 ADD_EXECUTABLE(utest_run utest_run.cpp)
 TARGET_LINK_LIBRARIES(utest_run utests)
+
+if (NOT_BUILD_STAND_ALONE_UTEST)
 ADD_DEPENDENCIES (utest_run kernel_bin.bin)
+endif ()
+
 ADD_DEPENDENCIES (utests utest_generator)
 
 ADD_EXECUTABLE(flat_address_space runtime_flat_address_space.cpp)
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_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/setenv.sh.in b/utests/setenv.sh.in
index 67e3bf1..24f9d6d 100644
--- a/utests/setenv.sh.in
+++ b/utests/setenv.sh.in
@@ -1,10 +1,5 @@ 
 #!/bin/sh
 #
-export OCL_BITCODE_LIB_PATH=@LOCAL_OCL_BITCODE_BIN@
-export OCL_HEADER_FILE_DIR=@LOCAL_OCL_HEADER_DIR@
-export OCL_PCH_PATH=@LOCAL_OCL_PCH_OBJECT@
 export OCL_KERNEL_PATH=@CMAKE_CURRENT_SOURCE_DIR@/../kernels
-export OCL_GBE_PATH=@LOCAL_GBE_OBJECT_DIR@
-export OCL_INTERP_PATH=@LOCAL_INTERP_OBJECT_DIR@
 #disable self-test so we can get something more precise than "doesn't work"
 export OCL_IGNORE_SELF_TEST=1
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)