Skip to content

Commit

Permalink
Added wait_list parameter to copy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmyagkov authored and jszuppe committed Feb 10, 2019
1 parent 924ed68 commit 3de4bba
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 70 deletions.
71 changes: 47 additions & 24 deletions include/boost/compute/algorithm/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
mpl::not_<
Expand All @@ -118,7 +119,7 @@ dispatch_copy_async(InputIterator first,
"copy_async() is only supported for contiguous host iterators"
);

return copy_to_device_async(first, last, result, queue);
return copy_to_device_async(first, last, result, queue, events);
}

// host -> device (async)
Expand All @@ -129,6 +130,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
mpl::not_<
Expand Down Expand Up @@ -167,7 +169,7 @@ dispatch_copy_async(InputIterator first,
context
);
return copy_on_device_async(
mapped_host.begin(), mapped_host.end(), result, queue
mapped_host.begin(), mapped_host.end(), result, queue, events
);
}

Expand All @@ -179,6 +181,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
mpl::not_<
Expand All @@ -190,7 +193,7 @@ dispatch_copy(InputIterator first,
>
>::type* = 0)
{
return copy_to_device(first, last, result, queue);
return copy_to_device(first, last, result, queue, events);
}

// host -> device
Expand All @@ -202,6 +205,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
mpl::not_<
Expand Down Expand Up @@ -258,13 +262,15 @@ dispatch_copy(InputIterator first,

// [0; map_copy_threshold) -> copy_to_device_map()
if(input_size_bytes < map_copy_threshold) {
return copy_to_device_map(first, last, result, queue);
return copy_to_device_map(first, last, result, queue, events);
}
// [map_copy_threshold; direct_copy_threshold) -> convert [first; last)
// on host and then perform copy_to_device()
else if(input_size_bytes < direct_copy_threshold) {
std::vector<output_type> vector(first, last);
return copy_to_device(vector.begin(), vector.end(), result, queue);
return copy_to_device(
vector.begin(), vector.end(), result, queue, events
);
}

// [direct_copy_threshold; inf) -> map [first; last) to device and
Expand All @@ -275,7 +281,7 @@ dispatch_copy(InputIterator first,
// return the result.
// At this point we are sure that count > 1 (first != last), so event
// returned by dispatch_copy_async() must be valid.
return dispatch_copy_async(first, last, result, queue).get();
return dispatch_copy_async(first, last, result, queue, events).get();
}

// host -> device
Expand All @@ -286,6 +292,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
mpl::not_<
Expand Down Expand Up @@ -345,12 +352,12 @@ dispatch_copy(InputIterator first,
// copy_to_device_map() is used for every input
if(input_size_bytes < map_copy_threshold
|| direct_copy_threshold <= map_copy_threshold) {
return copy_to_device_map(first, last, result, queue);
return copy_to_device_map(first, last, result, queue, events);
}
// [map_copy_threshold; inf) -> convert [first; last)
// on host and then perform copy_to_device()
std::vector<output_type> vector(first, last);
return copy_to_device(vector.begin(), vector.end(), result, queue);
return copy_to_device(vector.begin(), vector.end(), result, queue, events);
}

// device -> host (async)
Expand All @@ -360,6 +367,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -375,7 +383,7 @@ dispatch_copy_async(InputIterator first,
"copy_async() is only supported for contiguous host iterators"
);

return copy_to_host_async(first, last, result, queue);
return copy_to_host_async(first, last, result, queue, events);
}

// device -> host (async)
Expand All @@ -386,6 +394,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand Down Expand Up @@ -426,7 +435,8 @@ dispatch_copy_async(InputIterator first,
first,
last,
make_buffer_iterator<output_type>(mapped_host),
queue
queue,
events
);
// update host memory asynchronously by maping and unmaping memory
event map_event;
Expand All @@ -451,6 +461,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -465,7 +476,7 @@ dispatch_copy(InputIterator first,
>
>::type* = 0)
{
return copy_to_host(first, last, result, queue);
return copy_to_host(first, last, result, queue, events);
}

// device -> host
Expand All @@ -478,6 +489,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand Down Expand Up @@ -540,12 +552,12 @@ dispatch_copy(InputIterator first,
// copy_to_host_map() is used for every input
if(input_size_bytes < map_copy_threshold
|| direct_copy_threshold <= map_copy_threshold) {
return copy_to_host_map(first, last, result, queue);
return copy_to_host_map(first, last, result, queue, events);
}
// [map_copy_threshold; inf) -> copy [first;last) to temporary vector
// then copy (and convert) to result using std::copy()
std::vector<input_type> vector(count);
copy_to_host(first, last, vector.begin(), queue);
copy_to_host(first, last, vector.begin(), queue, events);
return std::copy(vector.begin(), vector.end(), result);
}

Expand All @@ -559,6 +571,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand Down Expand Up @@ -618,13 +631,13 @@ dispatch_copy(InputIterator first,

// [0; map_copy_threshold) -> copy_to_host_map()
if(input_size_bytes < map_copy_threshold) {
return copy_to_host_map(first, last, result, queue);
return copy_to_host_map(first, last, result, queue, events);
}
// [map_copy_threshold; direct_copy_threshold) -> copy [first;last) to
// temporary vector then copy (and convert) to result using std::copy()
else if(input_size_bytes < direct_copy_threshold) {
std::vector<input_type> vector(count);
copy_to_host(first, last, vector.begin(), queue);
copy_to_host(first, last, vector.begin(), queue, events);
return std::copy(vector.begin(), vector.end(), result);
}

Expand All @@ -636,7 +649,7 @@ dispatch_copy(InputIterator first,
// return the result.
// At this point we are sure that count > 1 (first != last), so event
// returned by dispatch_copy_async() must be valid.
return dispatch_copy_async(first, last, result, queue).get();
return dispatch_copy_async(first, last, result, queue, events).get();
}

// device -> device
Expand All @@ -646,6 +659,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -658,7 +672,7 @@ dispatch_copy(InputIterator first,
>
>::type* = 0)
{
return copy_on_device(first, last, result, queue);
return copy_on_device(first, last, result, queue, events);
}

// device -> device (specialization for buffer iterators)
Expand All @@ -668,6 +682,7 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -691,7 +706,8 @@ dispatch_copy(InputIterator first,
result.get_buffer(),
first.get_index() * sizeof(value_type),
result.get_index() * sizeof(value_type),
static_cast<size_t>(n) * sizeof(value_type));
static_cast<size_t>(n) * sizeof(value_type),
events);
return result + n;
}

Expand All @@ -702,6 +718,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -714,7 +731,7 @@ dispatch_copy_async(InputIterator first,
>
>::type* = 0)
{
return copy_on_device_async(first, last, result, queue);
return copy_on_device_async(first, last, result, queue, events);
}

// device -> device (async, specialization for buffer iterators)
Expand All @@ -724,6 +741,7 @@ dispatch_copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if<
mpl::and_<
is_device_iterator<InputIterator>,
Expand All @@ -749,7 +767,8 @@ dispatch_copy_async(InputIterator first,
result.get_buffer(),
first.get_index() * sizeof(value_type),
result.get_index() * sizeof(value_type),
static_cast<size_t>(n) * sizeof(value_type)
static_cast<size_t>(n) * sizeof(value_type),
events
);

return make_future(result + n, event_);
Expand All @@ -762,12 +781,14 @@ dispatch_copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue,
const wait_list &events,
typename boost::enable_if_c<
!is_device_iterator<InputIterator>::value &&
!is_device_iterator<OutputIterator>::value
>::type* = 0)
{
(void) queue;
(void) events;

return std::copy(first, last, result);
}
Expand Down Expand Up @@ -833,9 +854,10 @@ template<class InputIterator, class OutputIterator>
inline OutputIterator copy(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue = system::default_queue())
command_queue &queue = system::default_queue(),
const wait_list &events = wait_list())
{
return detail::dispatch_copy(first, last, result, queue);
return detail::dispatch_copy(first, last, result, queue, events);
}

/// Copies the values in the range [\p first, \p last) to the range
Expand All @@ -847,9 +869,10 @@ inline future<OutputIterator>
copy_async(InputIterator first,
InputIterator last,
OutputIterator result,
command_queue &queue = system::default_queue())
command_queue &queue = system::default_queue(),
const wait_list &events = wait_list())
{
return detail::dispatch_copy_async(first, last, result, queue);
return detail::dispatch_copy_async(first, last, result, queue, events);
}

} // end compute namespace
Expand Down
6 changes: 4 additions & 2 deletions include/boost/compute/algorithm/copy_n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ template<class InputIterator, class Size, class OutputIterator>
inline OutputIterator copy_n(InputIterator first,
Size count,
OutputIterator result,
command_queue &queue = system::default_queue())
command_queue &queue = system::default_queue(),
const wait_list &events = wait_list())
{
typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;

return ::boost::compute::copy(first,
first + static_cast<difference_type>(count),
result,
queue);
queue,
events);
}

} // end compute namespace
Expand Down
Loading

0 comments on commit 3de4bba

Please sign in to comment.