#include #include #include #include using namespace unittest; struct SumTupleFunctor { template _CCCL_HOST_DEVICE Tuple operator()(const Tuple& lhs, const Tuple& rhs) { using cuda::std::get; return cuda::std::tuple(get<0>(lhs) + get<0>(rhs), get<1>(lhs) + get<1>(rhs)); } }; struct MakeTupleFunctor { template _CCCL_HOST_DEVICE cuda::std::tuple operator()(T1& lhs, T2& rhs) { return cuda::std::tuple(lhs, rhs); } }; template struct TestTupleReduce { void operator()(const size_t n) { thrust::host_vector h_t1 = random_integers(n); thrust::host_vector h_t2 = random_integers(n); // zip up the data thrust::host_vector> h_tuples(n); thrust::transform(h_t1.begin(), h_t1.end(), h_t2.begin(), h_tuples.begin(), MakeTupleFunctor()); // copy to device thrust::device_vector> d_tuples = h_tuples; cuda::std::tuple zero(0, 0); // sum on host cuda::std::tuple h_result = thrust::reduce(h_tuples.begin(), h_tuples.end(), zero, SumTupleFunctor()); // sum on device cuda::std::tuple d_result = thrust::reduce(d_tuples.begin(), d_tuples.end(), zero, SumTupleFunctor()); ASSERT_EQUAL_QUIET(h_result, d_result); } }; VariableUnitTest TestTupleReduceInstance;