Skip to content

Instantly share code, notes, and snippets.

@jszuppe
Created May 17, 2016 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jszuppe/5605c1057f6f0282437c777dd33ea24f to your computer and use it in GitHub Desktop.
Save jszuppe/5605c1057f6f0282437c777dd33ea24f to your computer and use it in GitHub Desktop.
template<class HostIterator, class DeviceIterator>
inline DeviceIterator copy(HostIterator first,
HostIterator last,
DeviceIterator result,
boost::compute::command_queue &queue)
{
...
// map result buffer to host
value_type *pointer = static_cast<value_type*>(
queue.enqueue_map_buffer(
result.get_buffer(),
CL_MAP_WRITE,
offset * sizeof(value_type),
count * sizeof(value_type)
)
);
// copy [first; last) to result buffer
std::copy(first, last, pointer);
// unmap result buffer
boost::compute::event unmapEvent = queue.enqueue_unmap_buffer(
result.get_buffer(),
static_cast<void*>(pointer)
);
unmapEvent.wait();
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment