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
|
#include <thrust/detail/config.h>
#include <thrust/async/scan.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include "test_header.hpp"
TESTS_DEFINE(AsyncScanTests, NumericalTestsParams)
enum wait_policy
{
wait_for_futures,
do_not_wait_for_futures
};
#define FIRST_ARG(N, ...) N
#define SECOND_ARG(N, ...) FIRST_ARG(__VA_ARGS__)
#define DEFINE_INCLUSIVE_SCAN_INVOKER(name, ...) \
template <typename T> \
struct name \
{ \
template <typename ForwardIt, typename Sentinel, typename OutputIt> \
__host__ static void sync(ForwardIt&& first, Sentinel&& last, OutputIt&& out) \
{ \
::thrust::inclusive_scan(THRUST_FWD(first), \
THRUST_FWD(last), \
THRUST_FWD(out) THRUST_PP_COMMA_IF(THRUST_PP_ARITY( \
FIRST_ARG(__VA_ARGS__))) FIRST_ARG(__VA_ARGS__)); \
} \
\
template <typename ForwardIt, typename Sentinel, typename OutputIt> \
__host__ static auto async(ForwardIt&& first, Sentinel&& last, OutputIt&& out) \
THRUST_DECLTYPE_RETURNS(::thrust::async::inclusive_scan( \
SECOND_ARG(__VA_ARGS__) \
THRUST_PP_COMMA_IF(THRUST_PP_ARITY(SECOND_ARG(__VA_ARGS__))) \
THRUST_FWD(first), \
THRUST_FWD(last), \
THRUST_FWD(out) THRUST_PP_COMMA_IF(THRUST_PP_ARITY(FIRST_ARG(__VA_ARGS__))) \
FIRST_ARG(__VA_ARGS__))) \
} /**/
#define DEFINE_EXCLUSIVE_SCAN_INVOKER(name, init, ...) \
template <typename T> \
struct name \
{ \
template <typename ForwardIt, typename Sentinel, typename OutputIt> \
__host__ static void sync(ForwardIt&& first, Sentinel&& last, OutputIt&& out) \
{ \
::thrust::exclusive_scan(THRUST_FWD(first), \
THRUST_FWD(last), \
THRUST_FWD(out), \
init THRUST_PP_COMMA_IF(THRUST_PP_ARITY( \
FIRST_ARG(__VA_ARGS__))) FIRST_ARG(__VA_ARGS__)); \
} \
\
template <typename ForwardIt, typename Sentinel, typename OutputIt> \
__host__ static auto async(ForwardIt&& first, Sentinel&& last, OutputIt&& out) \
THRUST_DECLTYPE_RETURNS(::thrust::async::exclusive_scan( \
SECOND_ARG(__VA_ARGS__) \
THRUST_PP_COMMA_IF(THRUST_PP_ARITY(SECOND_ARG(__VA_ARGS__))) \
THRUST_FWD(first), \
THRUST_FWD(last), \
THRUST_FWD(out), \
init THRUST_PP_COMMA_IF(THRUST_PP_ARITY(FIRST_ARG(__VA_ARGS__))) \
FIRST_ARG(__VA_ARGS__))) \
} /**/
DEFINE_INCLUSIVE_SCAN_INVOKER(inclusive_scan_invoker);
DEFINE_INCLUSIVE_SCAN_INVOKER(inclusive_scan_invoker_device, thrust::plus<T> {}, thrust::device);
DEFINE_EXCLUSIVE_SCAN_INVOKER(exclusive_scan_invoker, T(0));
DEFINE_EXCLUSIVE_SCAN_INVOKER(exclusive_scan_invoker_device,
T(0),
thrust::plus<T> {},
thrust::device);
DEFINE_INCLUSIVE_SCAN_INVOKER(inclusive_scan_invoker_maximum, thrust::maximum<T> {});
DEFINE_INCLUSIVE_SCAN_INVOKER(inclusive_scan_invoker_maximum_device,
thrust::maximum<T> {},
thrust::device);
DEFINE_EXCLUSIVE_SCAN_INVOKER(exclusive_scan_invoker_maximum, T(1), thrust::maximum<T> {});
DEFINE_EXCLUSIVE_SCAN_INVOKER(exclusive_scan_invoker_maximum_device,
T(1),
thrust::maximum<T> {},
thrust::device);
#undef DEFINE_SCAN_INVOKER
#undef DEFINE_SCAN_OP_INVOKER
#undef FIRST_ARG
#undef SECOND_ARD
///////////////////////////////////////////////////////////////////////////////
template <typename T, template <typename> class ScanInvoker, wait_policy WaitPolicy>
void TestAsyncScan()
{
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(h0_data);
thrust::host_vector<T> h0_output(h0_data);
thrust::device_vector<T> d0_output(d0_data);
ScanInvoker<T>::sync(h0_data.begin(), h0_data.end(), h0_output.begin());
auto f0 = ScanInvoker<T>::async(d0_data.begin(), d0_data.end(), d0_output.begin());
THRUST_IF_CONSTEXPR(wait_for_futures == WaitPolicy)
{
f0.wait();
ASSERT_EQ(h0_output, d0_output);
}
}
}
}
TYPED_TEST(AsyncScanTests, AsyncInclusiveScan)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker, do_not_wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanPolicy)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker_device, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanMaximum)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker_maximum, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanMaximumNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker_maximum, do_not_wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanPolicyMaximum)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker_maximum_device, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncInclusiveScanPolicyMaximumNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, inclusive_scan_invoker_maximum_device, do_not_wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScan)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker, do_not_wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanPolicy)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker_device, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanMaximum)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker_maximum, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanMaximumNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker_maximum, do_not_wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanPolicyMaximum)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker_maximum_device, wait_for_futures>();
};
TYPED_TEST(AsyncScanTests, AsyncExclusiveScanPolicyMaximumNoWait)
{
SCOPED_TRACE(testing::Message() << "with device_id= " << test::set_device_from_ctest());
using T = typename TestFixture::input_type;
TestAsyncScan<T, exclusive_scan_invoker_maximum_device, do_not_wait_for_futures>();
};
///////////////////////////////////////////////////////////////////////////////
|