• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #define BOOST_TEST_MODULE TestAsyncWait
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/async/future.hpp>
15 #include <boost/compute/async/wait.hpp>
16 #include <boost/compute/algorithm/copy.hpp>
17 #include <boost/compute/container/vector.hpp>
18 
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
21 
22 namespace compute = boost::compute;
23 
BOOST_AUTO_TEST_CASE(empty)24 BOOST_AUTO_TEST_CASE(empty)
25 {
26 }
27 
28 #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
BOOST_AUTO_TEST_CASE(wait_for_copy)29 BOOST_AUTO_TEST_CASE(wait_for_copy)
30 {
31     // wait list
32     compute::wait_list events;
33 
34     // create host data array
35     int data[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
36 
37     // create vector on the device
38     compute::vector<int> vector(8, context);
39 
40     // fill vector with 9's
41     compute::future<void> fill_future =
42         compute::fill_async(vector.begin(), vector.end(), 9, queue);
43 
44     // wait for fill() to complete
45     compute::wait_for_all(fill_future);
46 
47     // check data on the device
48     CHECK_RANGE_EQUAL(int, 8, vector, (9, 9, 9, 9, 9, 9, 9, 9));
49 
50     // copy each pair of values independently and asynchronously
51     compute::event copy1 = queue.enqueue_write_buffer_async(
52         vector.get_buffer(), 0 * sizeof(int), 2 * sizeof(int), data + 0
53     );
54     compute::event copy2 = queue.enqueue_write_buffer_async(
55         vector.get_buffer(), 2 * sizeof(int), 2 * sizeof(int), data + 2
56     );
57     compute::event copy3 = queue.enqueue_write_buffer_async(
58         vector.get_buffer(), 4 * sizeof(int), 2 * sizeof(int), data + 4
59     );
60     compute::event copy4 = queue.enqueue_write_buffer_async(
61         vector.get_buffer(), 6 * sizeof(int), 2 * sizeof(int), data + 6
62     );
63 
64     // wait for all copies to complete
65     compute::wait_for_all(copy1, copy2, copy3, copy4);
66 
67     // check data on the device
68     CHECK_RANGE_EQUAL(int, 8, vector, (1, 2, 3, 4, 5, 6, 7, 8));
69 }
70 #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
71 
72 BOOST_AUTO_TEST_SUITE_END()
73