test_wait_list.cpp 2.4 KB

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