• 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 TestWaitList
12 #include <boost/test/unit_test.hpp>
13 
14 #include <algorithm>
15 #include <vector>
16 
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/system.hpp>
19 #include <boost/compute/async/future.hpp>
20 #include <boost/compute/algorithm/copy.hpp>
21 #include <boost/compute/container/vector.hpp>
22 #include <boost/compute/utility/wait_list.hpp>
23 
24 #include "check_macros.hpp"
25 #include "context_setup.hpp"
26 
27 namespace compute = boost::compute;
28 
BOOST_AUTO_TEST_CASE(create_wait_list)29 BOOST_AUTO_TEST_CASE(create_wait_list)
30 {
31     compute::wait_list events;
32     BOOST_CHECK_EQUAL(events.size(), size_t(0));
33     BOOST_CHECK_EQUAL(events.empty(), true);
34     BOOST_CHECK(events.get_event_ptr() == 0);
35 }
36 
37 #ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
BOOST_AUTO_TEST_CASE(create_wait_list_from_initializer_list)38 BOOST_AUTO_TEST_CASE(create_wait_list_from_initializer_list)
39 {
40     compute::event event0;
41     compute::event event1;
42     compute::event event2;
43     compute::wait_list events = { event0, event1, event2 };
44     BOOST_CHECK_EQUAL(events.size(), size_t(3));
45     CHECK_RANGE_EQUAL(compute::event, 3, events, (event0, event1, event2));
46 }
47 #endif // BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
48 
BOOST_AUTO_TEST_CASE(insert_future)49 BOOST_AUTO_TEST_CASE(insert_future)
50 {
51     // create vector on the host
52     std::vector<int> host_vector(4);
53     std::fill(host_vector.begin(), host_vector.end(), 7);
54 
55     // create vector on the device
56     compute::vector<int> device_vector(4, context);
57 
58     // create wait list
59     compute::wait_list events;
60 
61     // copy values to device
62     compute::future<void> future = compute::copy_async(
63         host_vector.begin(), host_vector.end(), device_vector.begin(), queue
64     );
65 
66     // add future event to the wait list
67     events.insert(future);
68     BOOST_CHECK_EQUAL(events.size(), size_t(1));
69     BOOST_CHECK(events.get_event_ptr() != 0);
70 
71     // wait for copy to complete
72     events.wait();
73 
74     // check values
75     CHECK_RANGE_EQUAL(int, 4, device_vector, (7, 7, 7, 7));
76 
77     // clear the event list
78     events.clear();
79     BOOST_CHECK_EQUAL(events.size(), size_t(0));
80 }
81 
82 BOOST_AUTO_TEST_SUITE_END()
83