From b6f33ba4b6665f6b650b7ec6c20a3349ea91d3a5 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Mon, 16 Jun 2014 03:58:46 -0400
Subject: [PATCH] remove cpp side hostbuffer in memory_object

---
 src/c_wrapper/buffer.cpp      |  9 +++++++--
 src/c_wrapper/buffer.h        |  9 ++-------
 src/c_wrapper/gl_obj.h        | 12 ++++++------
 src/c_wrapper/image.cpp       | 15 +++++++++------
 src/c_wrapper/image.h         | 10 ++--------
 src/c_wrapper/memory_object.h | 10 +---------
 6 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/src/c_wrapper/buffer.cpp b/src/c_wrapper/buffer.cpp
index 6b777fab..f72a787d 100644
--- a/src/c_wrapper/buffer.cpp
+++ b/src/c_wrapper/buffer.cpp
@@ -5,6 +5,12 @@
 
 namespace pyopencl {
 
+PYOPENCL_USE_RESULT static PYOPENCL_INLINE buffer*
+new_buffer(cl_mem mem)
+{
+    return pyopencl_convert_obj(buffer, clReleaseMemObject, mem);
+}
+
 #if PYOPENCL_CL_VERSION >= 0x1010
 PYOPENCL_USE_RESULT buffer*
 buffer::get_sub_region(size_t origin, size_t size, cl_mem_flags flags) const
@@ -64,8 +70,7 @@ create_buffer(clobj_t *buffer, clobj_t _ctx, cl_mem_flags flags,
                     return pyopencl_call_guarded(clCreateBuffer, ctx,
                                                  flags, size, hostbuf);
                 });
-            *buffer = new_buffer(mem, (flags & CL_MEM_USE_HOST_PTR ?
-                                       hostbuf : nullptr));
+            *buffer = new_buffer(mem);
         });
 }
 
diff --git a/src/c_wrapper/buffer.h b/src/c_wrapper/buffer.h
index d76bbdcd..4681b192 100644
--- a/src/c_wrapper/buffer.h
+++ b/src/c_wrapper/buffer.h
@@ -12,8 +12,8 @@ class buffer : public memory_object {
 public:
     PYOPENCL_DEF_CL_CLASS(BUFFER);
     PYOPENCL_INLINE
-    buffer(cl_mem mem, bool retain, void *hostbuf=0)
-        : memory_object(mem, retain, hostbuf)
+    buffer(cl_mem mem, bool retain)
+        : memory_object(mem, retain)
     {}
 
 #if PYOPENCL_CL_VERSION >= 0x1010
@@ -21,11 +21,6 @@ public:
                                                cl_mem_flags flags) const;
 #endif
 };
-PYOPENCL_USE_RESULT static PYOPENCL_INLINE buffer*
-new_buffer(cl_mem mem, void *buff=0)
-{
-    return pyopencl_convert_obj(buffer, clReleaseMemObject, mem, buff);
-}
 
 // }}}
 
diff --git a/src/c_wrapper/gl_obj.h b/src/c_wrapper/gl_obj.h
index 09ebc507..3ff225db 100644
--- a/src/c_wrapper/gl_obj.h
+++ b/src/c_wrapper/gl_obj.h
@@ -24,8 +24,8 @@ class gl_buffer : public memory_object {
 public:
     PYOPENCL_DEF_CL_CLASS(GL_BUFFER);
     PYOPENCL_INLINE
-    gl_buffer(cl_mem mem, bool retain, void *hostbuf=0)
-        : memory_object(mem, retain, hostbuf)
+    gl_buffer(cl_mem mem, bool retain)
+        : memory_object(mem, retain)
     {}
 };
 
@@ -33,16 +33,16 @@ class gl_renderbuffer : public memory_object {
 public:
     PYOPENCL_DEF_CL_CLASS(GL_RENDERBUFFER);
     PYOPENCL_INLINE
-    gl_renderbuffer(cl_mem mem, bool retain, void *hostbuf=0)
-        : memory_object(mem, retain, hostbuf)
+    gl_renderbuffer(cl_mem mem, bool retain)
+        : memory_object(mem, retain)
     {}
 };
 
 class gl_texture : public image {
   public:
     PYOPENCL_INLINE
-    gl_texture(cl_mem mem, bool retain, void *hostbuf=0)
-      : image(mem, retain, hostbuf)
+    gl_texture(cl_mem mem, bool retain)
+      : image(mem, retain)
     {}
     PYOPENCL_USE_RESULT generic_info
     get_gl_texture_info(cl_gl_texture_info param_name) const;
diff --git a/src/c_wrapper/image.cpp b/src/c_wrapper/image.cpp
index c6100e09..1ac7c3d5 100644
--- a/src/c_wrapper/image.cpp
+++ b/src/c_wrapper/image.cpp
@@ -5,6 +5,12 @@
 
 namespace pyopencl {
 
+PYOPENCL_USE_RESULT static PYOPENCL_INLINE image*
+new_image(cl_mem mem, const cl_image_format *fmt)
+{
+    return pyopencl_convert_obj(image, clReleaseMemObject, mem, fmt);
+}
+
 generic_info
 image::get_image_info(cl_image_info param) const
 {
@@ -119,8 +125,7 @@ create_image_2d(clobj_t *img, clobj_t _ctx, cl_mem_flags flags,
                         clCreateImage2D, ctx, flags,
                         fmt, width, height, pitch, buffer);
                 });
-            *img = new_image(mem, (flags & CL_MEM_USE_HOST_PTR ?
-                                   buffer : nullptr), fmt);
+            *img = new_image(mem, fmt);
         });
 }
 
@@ -136,8 +141,7 @@ create_image_3d(clobj_t *img, clobj_t _ctx, cl_mem_flags flags,
                         clCreateImage3D, ctx, flags, fmt, width,
                         height, depth, pitch_x, pitch_y, buffer);
                 });
-            *img = new_image(mem, (flags & CL_MEM_USE_HOST_PTR ?
-                                   buffer : nullptr), fmt);
+            *img = new_image(mem, fmt);
         });
 }
 
@@ -151,8 +155,7 @@ create_image_from_desc(clobj_t *img, clobj_t _ctx, cl_mem_flags flags,
     return c_handle_error([&] {
             auto mem = pyopencl_call_guarded(clCreateImage, ctx, flags, fmt,
                                              desc, buffer);
-            *img = new_image(mem, (flags & CL_MEM_USE_HOST_PTR ?
-                                   buffer : nullptr), fmt);
+            *img = new_image(mem, fmt);
         });
 }
 
diff --git a/src/c_wrapper/image.h b/src/c_wrapper/image.h
index ee96d588..74faa71d 100644
--- a/src/c_wrapper/image.h
+++ b/src/c_wrapper/image.h
@@ -14,9 +14,8 @@ private:
 public:
     PYOPENCL_DEF_CL_CLASS(IMAGE);
     PYOPENCL_INLINE
-    image(cl_mem mem, bool retain, void *hostbuf=0,
-          const cl_image_format *fmt=0)
-        : memory_object(mem, retain, hostbuf)
+    image(cl_mem mem, bool retain, const cl_image_format *fmt=0)
+        : memory_object(mem, retain)
     {
         if (fmt) {
             m_format = *fmt;
@@ -43,11 +42,6 @@ public:
         }
     }
 };
-PYOPENCL_USE_RESULT static PYOPENCL_INLINE image*
-new_image(cl_mem mem, void *buff, const cl_image_format *fmt)
-{
-    return pyopencl_convert_obj(image, clReleaseMemObject, mem, buff, fmt);
-}
 
 // }}}
 
diff --git a/src/c_wrapper/memory_object.h b/src/c_wrapper/memory_object.h
index 83248b66..07f17d58 100644
--- a/src/c_wrapper/memory_object.h
+++ b/src/c_wrapper/memory_object.h
@@ -13,16 +13,14 @@ extern template class clobj<cl_mem>;
 class memory_object : public clobj<cl_mem> {
 private:
     mutable volatile std::atomic_bool m_valid;
-    void *m_hostbuf;
 public:
     PYOPENCL_INLINE
-    memory_object(cl_mem mem, bool retain, void *hostbuf=0)
+    memory_object(cl_mem mem, bool retain)
         : clobj(mem), m_valid(true)
     {
         if (retain) {
             pyopencl_call_guarded(clRetainMemObject, this);
         }
-        m_hostbuf = hostbuf;
     }
     PYOPENCL_INLINE
     memory_object(const memory_object &mem)
@@ -40,12 +38,6 @@ public:
         pyopencl_call_guarded(clReleaseMemObject, this);
     }
 #if 0
-    PYOPENCL_USE_RESULT PYOPENCL_INLINE void*
-    hostbuf() const
-    {
-        // TODO: use this?
-        return m_hostbuf;
-    }
     PYOPENCL_USE_RESULT size_t
     size() const
     {
-- 
GitLab