[compute] 02/46: Add asynchronous versions of a few methods in command_queue class

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Dec 21 18:28:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository compute.

commit 88beaa0502f02424fe07c522ebee758b9c301a14
Author: Jakub Szuppe <j.szuppe at gmail.com>
Date:   Sat Sep 12 15:14:28 2015 +0200

    Add asynchronous versions of a few methods in command_queue class
    
    Add asynchronous versions for enqueue_map_buffer(), enqueue_read_buffer_rect()
    and enqueue_write_buffer_rect().
---
 include/boost/compute/command_queue.hpp | 134 ++++++++++++++++++++++++++++++++
 1 file changed, 134 insertions(+)

diff --git a/include/boost/compute/command_queue.hpp b/include/boost/compute/command_queue.hpp
index 9636d1a..646488a 100644
--- a/include/boost/compute/command_queue.hpp
+++ b/include/boost/compute/command_queue.hpp
@@ -358,6 +358,53 @@ public:
             BOOST_THROW_EXCEPTION(opencl_error(ret));
         }
     }
+
+    /// Enqueues a command to read a rectangular region from \p buffer to
+    /// host memory. The copy will be performed asynchronously.
+    ///
+    /// \see_opencl_ref{clEnqueueReadBufferRect}
+    ///
+    /// \opencl_version_warning{1,1}
+    event enqueue_read_buffer_rect_async(const buffer &buffer,
+                                         const size_t buffer_origin[3],
+                                         const size_t host_origin[3],
+                                         const size_t region[3],
+                                         size_t buffer_row_pitch,
+                                         size_t buffer_slice_pitch,
+                                         size_t host_row_pitch,
+                                         size_t host_slice_pitch,
+                                         void *host_ptr,
+                                         const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(m_queue != 0);
+        BOOST_ASSERT(buffer.get_context() == this->get_context());
+        BOOST_ASSERT(host_ptr != 0);
+
+        event event_;
+
+        cl_int ret = clEnqueueReadBufferRect(
+            m_queue,
+            buffer.get(),
+            CL_FALSE,
+            buffer_origin,
+            host_origin,
+            region,
+            buffer_row_pitch,
+            buffer_slice_pitch,
+            host_row_pitch,
+            host_slice_pitch,
+            host_ptr,
+            events.size(),
+            events.get_event_ptr(),
+            &event_.get()
+        );
+
+        if(ret != CL_SUCCESS){
+            BOOST_THROW_EXCEPTION(opencl_error(ret));
+        }
+
+        return event_;
+    }
     #endif // CL_VERSION_1_1
 
     /// Enqueues a command to write data from host memory to \p buffer.
@@ -474,6 +521,53 @@ public:
             BOOST_THROW_EXCEPTION(opencl_error(ret));
         }
     }
+
+    /// Enqueues a command to write a rectangular region from host memory
+    /// to \p buffer. The copy is performed asynchronously.
+    ///
+    /// \see_opencl_ref{clEnqueueWriteBufferRect}
+    ///
+    /// \opencl_version_warning{1,1}
+    event enqueue_write_buffer_rect_async(const buffer &buffer,
+                                          const size_t buffer_origin[3],
+                                          const size_t host_origin[3],
+                                          const size_t region[3],
+                                          size_t buffer_row_pitch,
+                                          size_t buffer_slice_pitch,
+                                          size_t host_row_pitch,
+                                          size_t host_slice_pitch,
+                                          void *host_ptr,
+                                          const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(m_queue != 0);
+        BOOST_ASSERT(buffer.get_context() == this->get_context());
+        BOOST_ASSERT(host_ptr != 0);
+
+        event event_;
+
+        cl_int ret = clEnqueueWriteBufferRect(
+            m_queue,
+            buffer.get(),
+            CL_FALSE,
+            buffer_origin,
+            host_origin,
+            region,
+            buffer_row_pitch,
+            buffer_slice_pitch,
+            host_row_pitch,
+            host_slice_pitch,
+            host_ptr,
+            events.size(),
+            events.get_event_ptr(),
+            &event_.get()
+        );
+
+        if(ret != CL_SUCCESS){
+            BOOST_THROW_EXCEPTION(opencl_error(ret));
+        }
+
+        return event_;
+    }
     #endif // CL_VERSION_1_1
 
     /// Enqueues a command to copy data from \p src_buffer to
@@ -653,6 +747,46 @@ public:
         return enqueue_map_buffer(buffer, flags, offset, size, event_, events);
     }
 
+    /// Enqueues a command to map \p buffer into the host address space.
+    /// Map operation is performed asynchronously. The pointer to the mapped
+    /// region cannot be used until the map operation has completed.
+    ///
+    /// Event associated with map operation is returned through
+    /// \p map_buffer_event parameter.
+    ///
+    /// \see_opencl_ref{clEnqueueMapBuffer}
+    void* enqueue_map_buffer_async(const buffer &buffer,
+                                   cl_map_flags flags,
+                                   size_t offset,
+                                   size_t size,
+                                   event &map_buffer_event,
+                                   const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(m_queue != 0);
+        BOOST_ASSERT(offset + size <= buffer.size());
+        BOOST_ASSERT(buffer.get_context() == this->get_context());
+
+        cl_int ret = 0;
+        void *pointer = clEnqueueMapBuffer(
+            m_queue,
+            buffer.get(),
+            CL_FALSE,
+            flags,
+            offset,
+            size,
+            events.size(),
+            events.get_event_ptr(),
+            &map_buffer_event.get(),
+            &ret
+        );
+
+        if(ret != CL_SUCCESS){
+            BOOST_THROW_EXCEPTION(opencl_error(ret));
+        }
+
+        return pointer;
+    }
+
     /// Enqueues a command to unmap \p buffer from the host memory space.
     ///
     /// \see_opencl_ref{clEnqueueUnmapMemObject}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git



More information about the debian-science-commits mailing list