[compute] 03/46: Add missing enqueue_map_image method in command queue

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 55a7f874a686f677a3898143fc767ad39f02711d
Author: Jakub Szuppe <j.szuppe at gmail.com>
Date:   Sun Aug 16 15:29:07 2015 +0200

    Add missing enqueue_map_image method in command queue
---
 include/boost/compute/command_queue.hpp | 179 ++++++++++++++++++++++++++++++++
 test/test_image2d.cpp                   |  60 +++++++++++
 2 files changed, 239 insertions(+)

diff --git a/include/boost/compute/command_queue.hpp b/include/boost/compute/command_queue.hpp
index 646488a..1458b56 100644
--- a/include/boost/compute/command_queue.hpp
+++ b/include/boost/compute/command_queue.hpp
@@ -944,6 +944,185 @@ public:
         );
     }
 
+    /// Enqueues a command to map \p image into the host address space.
+    ///
+    /// Event associated with map operation is returned through
+    /// \p map_image_event parameter.
+    ///
+    /// \see_opencl_ref{clEnqueueMapImage}
+    void* enqueue_map_image(const image_object &image,
+                            cl_map_flags flags,
+                            const size_t *origin,
+                            const size_t *region,
+                            size_t &output_row_pitch,
+                            size_t &output_slice_pitch,
+                            event &map_image_event,
+                            const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(m_queue != 0);
+        BOOST_ASSERT(image.get_context() == this->get_context());
+
+        cl_int ret = 0;
+        void *pointer = clEnqueueMapImage(
+            m_queue,
+            image.get(),
+            CL_TRUE,
+            flags,
+            origin,
+            region,
+            &output_row_pitch,
+            &output_slice_pitch,
+            events.size(),
+            events.get_event_ptr(),
+            &map_image_event.get(),
+            &ret
+        );
+
+        if(ret != CL_SUCCESS){
+            BOOST_THROW_EXCEPTION(opencl_error(ret));
+        }
+
+        return pointer;
+    }
+
+    /// \overload
+    void* enqueue_map_image(const image_object &image,
+                            cl_map_flags flags,
+                            const size_t *origin,
+                            const size_t *region,
+                            size_t &output_row_pitch,
+                            size_t &output_slice_pitch,
+                            const wait_list &events = wait_list())
+    {
+        event event_;
+        return enqueue_map_image(
+            image, flags, origin, region,
+            output_row_pitch, output_slice_pitch, event_, events
+        );
+    }
+
+    /// \overload
+    template<size_t N>
+    void* enqueue_map_image(image_object& image,
+                            cl_map_flags flags,
+                            const extents<N> origin,
+                            const extents<N> region,
+                            size_t &output_row_pitch,
+                            size_t &output_slice_pitch,
+                            event &map_image_event,
+                            const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(image.get_context() == this->get_context());
+
+        size_t origin3[3] = { 0, 0, 0 };
+        size_t region3[3] = { 1, 1, 1 };
+
+        std::copy(origin.data(), origin.data() + N, origin3);
+        std::copy(region.data(), region.data() + N, region3);
+
+        return enqueue_map_image(
+            image, flags, origin3, region3,
+            output_row_pitch, output_slice_pitch, map_image_event, events
+        );
+    }
+
+    /// \overload
+    template<size_t N>
+    void* enqueue_map_image(image_object& image,
+                            cl_map_flags flags,
+                            const extents<N> origin,
+                            const extents<N> region,
+                            size_t &output_row_pitch,
+                            size_t &output_slice_pitch,
+                            const wait_list &events = wait_list())
+    {
+        event event_;
+        return enqueue_map_image(
+            image, flags, origin, region,
+            output_row_pitch, output_slice_pitch, event_, events
+        );
+    }
+
+    /// Enqueues a command to map \p image 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_image_event parameter.
+    ///
+    /// \see_opencl_ref{clEnqueueMapImage}
+    void* enqueue_map_image_async(const image_object &image,
+                                  cl_map_flags flags,
+                                  const size_t *origin,
+                                  const size_t *region,
+                                  size_t &output_row_pitch,
+                                  size_t &output_slice_pitch,
+                                  event &map_image_event,
+                                  const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(m_queue != 0);
+        BOOST_ASSERT(image.get_context() == this->get_context());
+
+        cl_int ret = 0;
+        void *pointer = clEnqueueMapImage(
+            m_queue,
+            image.get(),
+            CL_FALSE,
+            flags,
+            origin,
+            region,
+            &output_row_pitch,
+            &output_slice_pitch,
+            events.size(),
+            events.get_event_ptr(),
+            &map_image_event.get(),
+            &ret
+        );
+
+        if(ret != CL_SUCCESS){
+            BOOST_THROW_EXCEPTION(opencl_error(ret));
+        }
+
+        return pointer;
+    }
+
+    /// \overload
+    template<size_t N>
+    void* enqueue_map_image_async(image_object& image,
+                                  cl_map_flags flags,
+                                  const extents<N> origin,
+                                  const extents<N> region,
+                                  size_t &output_row_pitch,
+                                  size_t &output_slice_pitch,
+                                  event &map_image_event,
+                                  const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(image.get_context() == this->get_context());
+
+        size_t origin3[3] = { 0, 0, 0 };
+        size_t region3[3] = { 1, 1, 1 };
+
+        std::copy(origin.data(), origin.data() + N, origin3);
+        std::copy(region.data(), region.data() + N, region3);
+
+        return enqueue_map_image_async(
+            image, flags, origin3, region3,
+            output_row_pitch, output_slice_pitch, map_image_event, events
+        );
+    }
+
+    /// Enqueues a command to unmap \p image from the host memory space.
+    ///
+    /// \see_opencl_ref{clEnqueueUnmapMemObject}
+    event enqueue_unmap_image(const image_object &image,
+                              void *mapped_ptr,
+                              const wait_list &events = wait_list())
+    {
+        BOOST_ASSERT(image.get_context() == this->get_context());
+
+        return enqueue_unmap_mem_object(image.get(), mapped_ptr, events);
+    }
+
     /// Enqueues a command to copy data from \p src_image to \p dst_image.
     ///
     /// \see_opencl_ref{clEnqueueCopyImage}
diff --git a/test/test_image2d.cpp b/test/test_image2d.cpp
index 5560a09..8471f90 100644
--- a/test/test_image2d.cpp
+++ b/test/test_image2d.cpp
@@ -161,4 +161,64 @@ BOOST_AUTO_TEST_CASE(image2d_type_name)
     );
 }
 
+BOOST_AUTO_TEST_CASE(map_image)
+{
+    compute::image_format format(CL_RGBA, CL_UNSIGNED_INT8);
+
+    if(!compute::image2d::is_supported_format(format, context)){
+        std::cerr << "skipping clone_image test, image format not supported" << std::endl;
+        return;
+    }
+
+    // create image on the device
+    compute::image2d image(context, 2, 2, format);
+
+    // ensure we have a valid image object
+    BOOST_REQUIRE(image.get() != cl_mem());
+
+    size_t row_pitch = 0;
+    size_t slice_pitch = 0;
+
+    // write map image
+    compute::uint_* ptr = static_cast<compute::uint_*>(
+        queue.enqueue_map_image(image, CL_MAP_WRITE, image.origin(),
+                                image.size(), row_pitch, slice_pitch)
+    );
+
+    BOOST_CHECK_EQUAL(row_pitch, size_t(2*4));
+
+    // image data
+    compute::uint_ data[] = { 0x0000ffff, 0xff00ffff,
+                              0x00ff00ff, 0xffffffff };
+
+    // copy data to image
+    for(size_t i = 0; i < 4; i++){
+        *(ptr+i) = data[i];
+    }
+
+    // unmap
+    queue.enqueue_unmap_image(image, static_cast<void*>(ptr));
+
+    // read map image
+    compute::event map_event;
+    ptr = static_cast<compute::uint_*>(
+        queue.enqueue_map_image_async(image, CL_MAP_READ, image.origin(),
+                                      image.size(), row_pitch, slice_pitch,
+                                      map_event)
+    );
+
+    map_event.wait();
+
+    BOOST_CHECK(map_event.get_status() == CL_COMPLETE);
+    BOOST_CHECK_EQUAL(row_pitch, size_t(2*4));
+
+    // checking
+    for(size_t i = 0; i < 4; i++){
+        BOOST_CHECK_EQUAL(*(ptr+i), data[i]);
+    }
+
+    // unmap
+    queue.enqueue_unmap_image(image, static_cast<void*>(ptr));
+}
+
 BOOST_AUTO_TEST_SUITE_END()

-- 
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