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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
#include <thrust/detail/config.h>
#if _CCCL_STD_VER >= 2014
# include <thrust/future.h>
# include <unittest/unittest.h>
# include <unittest/util_async.h>
struct mock
{};
using future_value_types = unittest::type_list<
char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
unsigned long long,
float,
double,
custom_numeric,
float2,
mock>;
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct test_future_default_constructed
{
_CCCL_HOST void operator()()
{
THRUST_STATIC_ASSERT((std::is_same<thrust::future<decltype(thrust::device), T>,
thrust::unique_eager_future<decltype(thrust::device), T>>::value));
THRUST_STATIC_ASSERT((std::is_same<thrust::future<decltype(thrust::device), T>, thrust::device_future<T>>::value));
THRUST_STATIC_ASSERT((std::is_same<thrust::device_future<T>, thrust::device_unique_eager_future<T>>::value));
thrust::device_future<T> f0;
ASSERT_EQUAL(false, f0.valid_stream());
ASSERT_EQUAL(false, f0.valid_content());
ASSERT_THROWS_EQUAL(f0.wait(), thrust::event_error, thrust::event_error(thrust::event_errc::no_state));
ASSERT_THROWS_EQUAL(f0.stream(), thrust::event_error, thrust::event_error(thrust::event_errc::no_state));
ASSERT_THROWS_EQUAL(f0.get(), thrust::event_error, thrust::event_error(thrust::event_errc::no_content));
ASSERT_THROWS_EQUAL(
THRUST_UNUSED_VAR(f0.extract()), thrust::event_error, thrust::event_error(thrust::event_errc::no_content));
}
};
DECLARE_GENERIC_UNITTEST_WITH_TYPES(test_future_default_constructed, future_value_types);
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct test_future_new_stream
{
_CCCL_HOST void operator()()
{
auto f0 = thrust::device_future<T>(thrust::new_stream);
ASSERT_EQUAL(true, f0.valid_stream());
ASSERT_EQUAL(false, f0.valid_content());
ASSERT_NOT_EQUAL_QUIET(nullptr, f0.stream().native_handle());
TEST_EVENT_WAIT(f0);
ASSERT_EQUAL(true, f0.ready());
ASSERT_THROWS_EQUAL(f0.get(), thrust::event_error, thrust::event_error(thrust::event_errc::no_content));
ASSERT_THROWS_EQUAL(
THRUST_UNUSED_VAR(f0.extract()), thrust::event_error, thrust::event_error(thrust::event_errc::no_content));
}
};
DECLARE_GENERIC_UNITTEST_WITH_TYPES(test_future_new_stream, future_value_types);
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct test_future_convert_to_event
{
_CCCL_HOST void operator()()
{
auto f0 = thrust::device_future<T>(thrust::new_stream);
auto const f0_stream = f0.stream().native_handle();
ASSERT_EQUAL(true, f0.valid_stream());
ASSERT_EQUAL(false, f0.valid_content());
ASSERT_NOT_EQUAL_QUIET(nullptr, f0_stream);
auto f1 = thrust::device_event(std::move(f0));
ASSERT_EQUAL(false, f0.valid_stream());
ASSERT_EQUAL(true, f1.valid_stream());
ASSERT_EQUAL(f0_stream, f1.stream().native_handle());
}
};
DECLARE_GENERIC_UNITTEST_WITH_TYPES(test_future_convert_to_event, future_value_types);
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct test_future_when_all
{
_CCCL_HOST void operator()()
{
// Create futures with new streams.
auto f0 = thrust::device_future<T>(thrust::new_stream);
auto f1 = thrust::device_future<T>(thrust::new_stream);
auto f2 = thrust::device_future<T>(thrust::new_stream);
auto f3 = thrust::device_future<T>(thrust::new_stream);
auto f4 = thrust::device_future<T>(thrust::new_stream);
auto f5 = thrust::device_future<T>(thrust::new_stream);
auto f6 = thrust::device_future<T>(thrust::new_stream);
auto f7 = thrust::device_future<T>(thrust::new_stream);
auto const f0_stream = f0.stream().native_handle();
ASSERT_EQUAL(true, f0.valid_stream());
ASSERT_EQUAL(true, f1.valid_stream());
ASSERT_EQUAL(true, f2.valid_stream());
ASSERT_EQUAL(true, f3.valid_stream());
ASSERT_EQUAL(true, f4.valid_stream());
ASSERT_EQUAL(true, f5.valid_stream());
ASSERT_EQUAL(true, f6.valid_stream());
ASSERT_EQUAL(true, f7.valid_stream());
ASSERT_EQUAL(false, f0.valid_content());
ASSERT_EQUAL(false, f1.valid_content());
ASSERT_EQUAL(false, f2.valid_content());
ASSERT_EQUAL(false, f3.valid_content());
ASSERT_EQUAL(false, f4.valid_content());
ASSERT_EQUAL(false, f5.valid_content());
ASSERT_EQUAL(false, f6.valid_content());
ASSERT_EQUAL(false, f7.valid_content());
ASSERT_NOT_EQUAL_QUIET(nullptr, f0_stream);
ASSERT_NOT_EQUAL_QUIET(nullptr, f1.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f2.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f3.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f4.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f5.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f6.stream().native_handle());
ASSERT_NOT_EQUAL_QUIET(nullptr, f7.stream().native_handle());
auto e0 = thrust::when_all(f0, f1, f2, f3, f4, f5, f6, f7);
ASSERT_EQUAL(false, f0.valid_stream());
ASSERT_EQUAL(false, f1.valid_stream());
ASSERT_EQUAL(false, f2.valid_stream());
ASSERT_EQUAL(false, f3.valid_stream());
ASSERT_EQUAL(false, f4.valid_stream());
ASSERT_EQUAL(false, f5.valid_stream());
ASSERT_EQUAL(false, f6.valid_stream());
ASSERT_EQUAL(false, f7.valid_stream());
ASSERT_EQUAL(false, f0.valid_content());
ASSERT_EQUAL(false, f1.valid_content());
ASSERT_EQUAL(false, f2.valid_content());
ASSERT_EQUAL(false, f3.valid_content());
ASSERT_EQUAL(false, f4.valid_content());
ASSERT_EQUAL(false, f5.valid_content());
ASSERT_EQUAL(false, f6.valid_content());
ASSERT_EQUAL(false, f7.valid_content());
ASSERT_EQUAL(true, e0.valid_stream());
ASSERT_EQUAL(f0_stream, e0.stream().native_handle());
TEST_EVENT_WAIT(e0);
ASSERT_EQUAL(false, f0.ready());
ASSERT_EQUAL(false, f1.ready());
ASSERT_EQUAL(false, f2.ready());
ASSERT_EQUAL(false, f3.ready());
ASSERT_EQUAL(false, f4.ready());
ASSERT_EQUAL(false, f5.ready());
ASSERT_EQUAL(false, f6.ready());
ASSERT_EQUAL(false, f7.ready());
ASSERT_EQUAL(true, e0.ready());
}
};
DECLARE_GENERIC_UNITTEST_WITH_TYPES(test_future_when_all, future_value_types);
///////////////////////////////////////////////////////////////////////////////
#endif
|