Adding tests for async functions
MODIFY
test/CMakeLists.txt
test/CMakeLists.txt
@@ -38,6 +38,7 @@ add_rocthrust_test("thrust.hip.adjacent_difference" test_adjacent_difference.cpp
add_rocthrust_test("thrust.hip.advance" test_advance.cpp)
add_rocthrust_test("thrust.hip.allocator" test_allocator.cpp)
add_rocthrust_test("thrust.hip.allocator_aware_policies" test_allocator_aware_policies.cpp)
+add_rocthrust_test("thrust.hip.async_reduce" test_async_reduce.cpp)
add_rocthrust_test("thrust.hip.binary_search" test_binary_search.cpp)
add_rocthrust_test("thrust.hip.binary_search_descending" test_binary_search_descending.cpp)
add_rocthrust_test("thrust.hip.binary_search_vector" test_binary_search_vector.cpp)

ADD
test/test_async_reduce.cpp
+#include <thrust/detail/config.h>
+
+#if THRUST_CPP_DIALECT >= 2011
+
+#include <thrust/async/reduce.h>
+#include <thrust/host_vector.h>
+#include <thrust/device_vector.h>
+
+#include "test_header.hpp"
+
+template <typename T>
+struct custom_plus
+{
+ __host__ __device__
+ T operator()(T lhs, T rhs) const
+ {
+ return lhs + rhs;
+ }
+};
+
+#if 0
+template <typename T>
+struct test_async_reduce
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end()
+ );
+
+ auto f0 = thrust::async::reduce(
+ d0_data.begin(), d0_data.end()
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce
+, NumericTypes
+> test_async_reduce_instance;
+#else
+TESTS_DEFINE(AsyncReduceTests, FullTestsParams);
+TYPED_TEST(AsyncReduceTests, TestAsyncReduce)
+{
+ using T = typename TestFixture::input_type;
+ const std::vector<size_t> sizes = get_sizes();
+ for(auto size : sizes)
+ {
+ /*
+ thrust::host_vector<T> h_data = get_random_data<T>(
+ size, std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
+ */
+ thrust::host_vector<T> h_data(size);
+ thrust::device_vector<T> d_data = h_data;
+
+ ASSERT_EQ(h_data, d_data);
+
+ auto r0 = thrust::reduce(
+ h_data.begin(), h_data.end()
+ );
+
+ auto f0 = thrust::async::reduce(
+ d_data.begin(), d_data.end()
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQ(r0, r1);
+ }
+}
+#endif
+
+#if 0
+template <typename T>
+struct test_async_reduce_with_policy
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end()
+ );
+
+ auto f0 = thrust::async::reduce(
+ thrust::device, d0_data.begin(), d0_data.end()
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce_with_policy
+, NumericTypes
+> test_async_reduce_with_policy_instance;
+
+template <typename T>
+struct test_async_reduce_with_init
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ T const init = unittest::random_integer<T>();
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end(), init
+ );
+
+ auto f0 = thrust::async::reduce(
+ d0_data.begin(), d0_data.end(), init
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce_with_init
+, NumericTypes
+> test_async_reduce_with_init_instance;
+
+template <typename T>
+struct test_async_reduce_with_policy_init
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ T const init = unittest::random_integer<T>();
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end(), init
+ );
+
+ auto f0 = thrust::async::reduce(
+ thrust::device, d0_data.begin(), d0_data.end(), init
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce_with_policy_init
+, NumericTypes
+> test_async_reduce_with_policy_init_instance;
+
+template <typename T>
+struct test_async_reduce_with_init_op
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ T const init = unittest::random_integer<T>();
+ custom_plus<T> op{};
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end(), init, op
+ );
+
+ auto f0 = thrust::async::reduce(
+ d0_data.begin(), d0_data.end(), init, op
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce_with_init_op
+, NumericTypes
+> test_async_reduce_with_init_op_instance;
+
+template <typename T>
+struct test_async_reduce_with_policy_init_op
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ T const init = unittest::random_integer<T>();
+ custom_plus<T> op{};
+
+ auto r0 = thrust::reduce(
+ h0_data.begin(), h0_data.end(), init, op
+ );
+
+ auto f0 = thrust::async::reduce(
+ thrust::device, d0_data.begin(), d0_data.end(), init, op
+ );
+
+ auto r1 = std::move(f0).get();
+
+ ASSERT_EQUAL(r0, r1);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_reduce_with_policy_init_op
+, NumericTypes
+> test_async_reduce_with_policy_init_op_instance;
+
+// TODO: Async copy then reduce.
+
+// TODO: Device-side reduction usage.
+
+// TODO: Make random_integers more generic.
+
+#endif // THRUST_CPP_DIALECT >= 2011
+
+#endif

ADD
test/test_async_sort.cpp
+#include <thrust/detail/config.h>
+
+#if THRUST_CPP_DIALECT >= 2011
+
+#include <unittest/unittest.h>
+
+#include <thrust/async/sort.h>
+#include <thrust/host_vector.h>
+#include <thrust/device_vector.h>
+
+template <typename T>
+struct custom_greater
+{
+ __host__ __device__
+ bool operator()(T rhs, T lhs) const
+ {
+ return lhs > rhs;
+ }
+};
+
+template <typename T>
+struct test_async_sort
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ thrust::sort(
+ h0_data.begin(), h0_data.end()
+ );
+
+ auto f0 = thrust::async::sort(
+ d0_data.begin(), d0_data.end()
+ );
+
+ f0.wait();
+
+ ASSERT_EQUAL(h0_data, d0_data);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_sort
+, NumericTypes
+> test_async_sort_instance;
+
+template <typename T>
+struct test_async_sort_with_policy
+{
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ thrust::sort(
+ h0_data.begin(), h0_data.end()
+ );
+
+ auto f0 = thrust::async::sort(
+ thrust::device, d0_data.begin(), d0_data.end()
+ );
+
+ f0.wait();
+
+ ASSERT_EQUAL(h0_data, d0_data);
+ }
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_sort_with_policy
+, NumericTypes
+> test_async_sort_with_policy_instance;
+
+template <template <typename> class Op>
+struct test_async_sort_with_op
+{
+ template <typename T>
+ struct tester
+ {
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ Op<T> op{};
+
+ thrust::sort(
+ h0_data.begin(), h0_data.end(), op
+ );
+
+ auto f0 = thrust::async::sort(
+ d0_data.begin(), d0_data.end(), op
+ );
+
+ f0.wait();
+
+ ASSERT_EQUAL(h0_data, d0_data);
+ }
+ };
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_sort_with_op<custom_greater>::tester
+, NumericTypes
+> test_async_sort_with_op_instance(
+ "test_async_sort_with_op<custom_greater>"
+);
+VariableUnitTest<
+ test_async_sort_with_op<thrust::less>::tester
+, NumericTypes
+> test_async_sort_with_less_instance(
+ "test_async_sort_with_op<thrust::less>"
+);
+VariableUnitTest<
+ test_async_sort_with_op<thrust::greater>::tester
+, NumericTypes
+> test_async_sort_with_greater_instance(
+ "test_async_sort_with_op<thrust::greater>"
+);
+
+template <template <typename> class Op>
+struct test_async_sort_with_policy_op
+{
+ template <typename T>
+ struct tester
+ {
+ __host__
+ void operator()(std::size_t n)
+ {
+ thrust::host_vector<T> h0_data(unittest::random_integers<T>(n));
+ thrust::device_vector<T> d0_data(h0_data);
+
+ ASSERT_EQUAL(h0_data, d0_data);
+
+ Op<T> op{};
+
+ thrust::sort(
+ h0_data.begin(), h0_data.end(), op
+ );
+
+ auto f0 = thrust::async::sort(
+ thrust::device, d0_data.begin(), d0_data.end(), op
+ );
+
+ f0.wait();
+
+ ASSERT_EQUAL(h0_data, d0_data);
+ }
+ };
+};
+// TODO: Switch to `DECLARE_VARIABLE_UNITTEST` when we add `custom_numeric` to
+// the list of types it covers.
+VariableUnitTest<
+ test_async_sort_with_policy_op<custom_greater>::tester
+, NumericTypes
+> test_async_sort_with_policy_op_instance(
+ "test_async_sort_with_policy_op<custom_greater>"
+);
+VariableUnitTest<
+ test_async_sort_with_policy_op<thrust::less>::tester
+, NumericTypes
+> test_async_sort_with_policy_less_instance(
+ "test_async_sort_with_policy_op<thrust::less>"
+);
+VariableUnitTest<
+ test_async_sort_with_policy_op<thrust::greater>::tester
+, NumericTypes
+> test_async_sort_with_policy_greater_instance(
+ "test_async_sort_with_policy_op<thrust::greater>"
+);
+
+// TODO: Async copy then sort.
+
+// TODO: Test future return type.
+
+#endif // THRUST_CPP_DIALECT >= 2011
+

Adding tests for async functions