File: test_wait_list.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (82 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE TestWaitList
#include <boost/test/unit_test.hpp>

#include <algorithm>
#include <vector>

#include <boost/compute/command_queue.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/async/future.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/utility/wait_list.hpp>

#include "check_macros.hpp"
#include "context_setup.hpp"

namespace compute = boost::compute;

BOOST_AUTO_TEST_CASE(create_wait_list)
{
    compute::wait_list events;
    BOOST_CHECK_EQUAL(events.size(), size_t(0));
    BOOST_CHECK_EQUAL(events.empty(), true);
    BOOST_CHECK(events.get_event_ptr() == 0);
}

#ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
BOOST_AUTO_TEST_CASE(create_wait_list_from_initializer_list)
{
    compute::event event0;
    compute::event event1;
    compute::event event2;
    compute::wait_list events = { event0, event1, event2 };
    BOOST_CHECK_EQUAL(events.size(), size_t(3));
    CHECK_RANGE_EQUAL(compute::event, 3, events, (event0, event1, event2));
}
#endif // BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST

BOOST_AUTO_TEST_CASE(insert_future)
{
    // create vector on the host
    std::vector<int> host_vector(4);
    std::fill(host_vector.begin(), host_vector.end(), 7);

    // create vector on the device
    compute::vector<int> device_vector(4, context);

    // create wait list
    compute::wait_list events;

    // copy values to device
    compute::future<void> future = compute::copy_async(
        host_vector.begin(), host_vector.end(), device_vector.begin(), queue
    );

    // add future event to the wait list
    events.insert(future);
    BOOST_CHECK_EQUAL(events.size(), size_t(1));
    BOOST_CHECK(events.get_event_ptr() != 0);

    // wait for copy to complete
    events.wait();

    // check values
    CHECK_RANGE_EQUAL(int, 4, device_vector, (7, 7, 7, 7));

    // clear the event list
    events.clear();
    BOOST_CHECK_EQUAL(events.size(), size_t(0));
}

BOOST_AUTO_TEST_SUITE_END()