2
0
mirror of https://github.com/boostorg/compute.git synced 2026-02-19 02:12:19 +00:00

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().
This commit is contained in:
Jakub Szuppe
2015-09-12 15:14:28 +02:00
parent 5c99e3f7f3
commit 88beaa0502

View File

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