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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
#include <thrust/detail/config.h>
#include <thrust/limits.h>
#include <thrust/async/copy.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include "test_header.hpp"
TESTS_DEFINE(AsyncCopyTests, NumericalTestsParams);
#define DEFINE_ASYNC_COPY_CALLABLE(name, ...) \
struct THRUST_PP_CAT2(name, _fn) \
{ \
template <typename ForwardIt, typename Sentinel, typename OutputIt> \
__host__ \
auto operator()( \
ForwardIt&& first, Sentinel&& last, OutputIt&& output \
) const \
THRUST_RETURNS( \
::thrust::async::copy( \
__VA_ARGS__ \
THRUST_PP_COMMA_IF(THRUST_PP_ARITY(__VA_ARGS__)) \
THRUST_FWD(first), THRUST_FWD(last), THRUST_FWD(output) \
) \
) \
}; \
/**/
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_host, thrust::host
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_device, thrust::device
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_host_to_device, thrust::host, thrust::device
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_device_to_host, thrust::device, thrust::host
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_host_to_host, thrust::host, thrust::host
);
DEFINE_ASYNC_COPY_CALLABLE(
invoke_async_copy_device_to_device, thrust::device, thrust::device
);
#undef DEFINE_ASYNC_COPY_CALLABLE
template <typename T, typename AsyncCopyCallable>
void AsyncCopyHostToDevice()
{
for(auto size : get_sizes())
{
SCOPED_TRACE(testing::Message() << "with size = " << size);
for(auto seed : get_seeds())
{
SCOPED_TRACE(testing::Message() << "with seed= " << seed);
thrust::host_vector<T> h0 = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed);
thrust::device_vector<T> d0(size);
auto f0 = AsyncCopyCallable{}(
h0.begin(), h0.end(), d0.begin()
);
f0.wait();
ASSERT_EQ(h0, d0);
}
}
}
TYPED_TEST(AsyncCopyTests, TestAsyncTriviallyRelocatableElementsHostToDevice)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
AsyncCopyHostToDevice<T, invoke_async_copy_fn>();
};
TYPED_TEST(AsyncCopyTests, TestAsyncTriviallyRelocatableElementsHostToDevicePolicies)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
AsyncCopyHostToDevice<T, invoke_async_copy_host_to_device_fn>();
};
template <typename T, typename AsyncCopyCallable>
void AsyncCopyDeviceToHost()
{
for(auto size : get_sizes())
{
SCOPED_TRACE(testing::Message() << "with size = " << size);
for(auto seed : get_seeds())
{
SCOPED_TRACE(testing::Message() << "with seed= " << seed);
thrust::host_vector<T> h0 = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed);
thrust::device_vector<T> h1(size);
thrust::device_vector<T> d0(size);
thrust::copy(h0.begin(), h0.end(), d0.begin());
ASSERT_EQ(h0, d0);
auto f0 = AsyncCopyCallable{}(
d0.begin(), d0.end(), h1.begin()
);
f0.wait();
ASSERT_EQ(h0, d0);
ASSERT_EQ(d0, h1);
}
}
}
TYPED_TEST(AsyncCopyTests, TestAsyncCopyTriviallyRelocatableDeviceToHost)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
AsyncCopyDeviceToHost<T, invoke_async_copy_fn>();
};
TYPED_TEST(AsyncCopyTests, TestAsyncCopyTriviallyRelocatableDeviceToHostPolicies)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
AsyncCopyDeviceToHost<T, invoke_async_copy_device_to_host_fn>();
};
/*TYPED_TEST(AsyncCopyTests, TestAsyncCopyDevicetoDevice)
{
using T = typename TestFixture::input_type;
for(auto size : get_sizes())
{
SCOPED_TRACE(testing::Message() << "with size = " << size);
for(auto seed : get_seeds())
{
SCOPED_TRACE(testing::Message() << "with seed= " << seed);
thrust::host_vector<T> h0_data = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed);
thrust::device_vector<T> d0_data(size);
thrust::device_vector<T> d1_data(size);
thrust::copy(h0_data.begin(), h0_data.end(), d0_data.begin());
ASSERT_EQ(h0_data, d0_data);
auto f0 = AsyncCopyCallable{}(
d0.begin(), d0.end(), d1.begin()
);
f0.wait();
ASSERT_EQ(h0_data, d0_data);
ASSERT_EQ(d0_data, d1_data);
}
}
}
TYPED_TEST(AsyncCopyTests, TestAsyncCopyDevicetoDeviceWithPolicy)
{
using T = typename TestFixture::input_type;
for(auto size : get_sizes())
{
SCOPED_TRACE(testing::Message() << "with size = " << size);
for(auto seed : get_seeds())
{
SCOPED_TRACE(testing::Message() << "with seed= " << seed);
thrust::host_vector<T> h0_data = get_random_data<T>(
size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max(), seed);
thrust::device_vector<T> d0_data(size);
thrust::device_vector<T> d1_data(size);
thrust::copy(h0_data.begin(), h0_data.end(), d0_data.begin());
ASSERT_EQ(h0_data, d0_data);
auto f0 = AsyncCopyCallable{}(
first, last, d1.begin()
);
f0.wait();
ASSERT_EQ(h0_data, d0_data);
ASSERT_EQ(d0_data, d1_data);
}
}
};*/
// TODO: device_to_device implicit.
// TODO: device_to_device NonContiguousIterator input (counting_iterator).
// TODO: device_to_device NonContiguousIterator output (discard_iterator).
// TODO: host_to_device non trivially relocatable.
// TODO: device_to_host non trivially relocatable.
// TODO: host_to_device NonContiguousIterator input (counting_iterator).
// TODO: host_to_device NonContiguousIterator output (discard_iterator).
// TODO: device_to_host NonContiguousIterator input (counting_iterator).
// TODO: device_to_host NonContiguousIterator output (discard_iterator).
// TODO: Mixed types, needs loosening of `is_trivially_relocatable_to` logic.
// TODO: H->D copy, then dependent D->H copy (round trip).
// Can't do this today because we can't do cross-system with explicit policies.
|