[Beignet] [PATCH] [version 2] Add clIntelMapBufferGTT, clIntelUnmapBufferGTT, cl_mem_map_gtt and cl_mem_unmap_gtt

Homer Hsing homer.xing at intel.com
Sun Apr 21 18:35:00 PDT 2013


cl_mem_map_gtt calls cl_buffer_map_gtt.
cl_mem_unmap_gtt calls cl_buffer_unmap_gtt.
clIntelMapBufferGTT is a one to one mapping of drm_intel_gem_bo_map_gtt.
clIntelUnmapBufferGTT is a one to one mapping of drm_intel_gem_bo_unmap_gtt.

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 include/CL/cl_intel.h |  8 ++++++++
 src/cl_api.c          | 23 +++++++++++++++++++++++
 src/cl_mem.c          | 15 +++++++++++++++
 src/cl_mem.h          |  6 ++++++
 4 files changed, 52 insertions(+)

diff --git a/include/CL/cl_intel.h b/include/CL/cl_intel.h
index 680f948..ff1860a 100644
--- a/include/CL/cl_intel.h
+++ b/include/CL/cl_intel.h
@@ -40,6 +40,14 @@ clIntelMapBuffer(cl_mem, cl_int*);
 extern CL_API_ENTRY cl_int CL_API_CALL
 clIntelUnmapBuffer(cl_mem);
 
+/* 1 to 1 mapping of drm_intel_gem_bo_map_gtt */
+extern CL_API_ENTRY void* CL_API_CALL
+clIntelMapBufferGTT(cl_mem, cl_int*);
+
+/* 1 to 1 mapping of drm_intel_gem_bo_unmap_gtt */
+extern CL_API_ENTRY cl_int CL_API_CALL
+clIntelUnmapBufferGTT(cl_mem);
+
 /* Pin /Unpin the buffer in GPU memory (must be root) */
 extern CL_API_ENTRY cl_int CL_API_CALL
 clIntelPinBuffer(cl_mem);
diff --git a/src/cl_api.c b/src/cl_api.c
index 2d84ace..6d7dd9a 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1212,6 +1212,29 @@ error:
   return err;
 }
 
+void*
+clIntelMapBufferGTT(cl_mem mem, cl_int *errcode_ret)
+{
+  void *ptr = NULL;
+  cl_int err = CL_SUCCESS;
+  CHECK_MEM (mem);
+  ptr = cl_mem_map_gtt(mem);
+error:
+  if (errcode_ret)
+    *errcode_ret = err;
+  return ptr;
+}
+
+cl_int
+clIntelUnmapBufferGTT(cl_mem mem)
+{
+  cl_int err = CL_SUCCESS;
+  CHECK_MEM (mem);
+  err = cl_mem_unmap_gtt(mem);
+error:
+  return err;
+}
+
 cl_int
 clIntelPinBuffer(cl_mem mem)
 {
diff --git a/src/cl_mem.c b/src/cl_mem.c
index 4bbaee4..e551c1f 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -480,6 +480,21 @@ cl_mem_unmap(cl_mem mem)
   return CL_SUCCESS;
 }
 
+LOCAL void*
+cl_mem_map_gtt(cl_mem mem)
+{
+  cl_buffer_map_gtt(mem->bo);
+  assert(cl_buffer_get_virtual(mem->bo));
+  return cl_buffer_get_virtual(mem->bo);
+}
+
+LOCAL cl_int
+cl_mem_unmap_gtt(cl_mem mem)
+{
+  cl_buffer_unmap_gtt(mem->bo);
+  return CL_SUCCESS;
+}
+
 LOCAL cl_int
 cl_mem_pin(cl_mem mem)
 {
diff --git a/src/cl_mem.h b/src/cl_mem.h
index 836deb4..0294ee9 100644
--- a/src/cl_mem.h
+++ b/src/cl_mem.h
@@ -75,6 +75,12 @@ extern void *cl_mem_map(cl_mem);
 /* Unmap a memory object */
 extern cl_int cl_mem_unmap(cl_mem);
 
+/* Directly map a memory object in GTT mode */
+extern void *cl_mem_map_gtt(cl_mem);
+
+/* Unmap a memory object in GTT mode */
+extern cl_int cl_mem_unmap_gtt(cl_mem);
+
 /* Pin/unpin the buffer in memory (you must be root) */
 extern cl_int cl_mem_pin(cl_mem);
 extern cl_int cl_mem_unpin(cl_mem);
-- 
1.8.1.2



More information about the Beignet mailing list