Spaces:
Runtime error
Runtime error
File size: 2,311 Bytes
be11144 |
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 |
#include <thrust/detail/config.h>
#if THRUST_CPP_DIALECT >= 2011 && !defined(THRUST_LEGACY_GCC)
#include <unittest/unittest.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/transform.h>
#include <thrust/zip_function.h>
#include <iostream>
using namespace unittest;
struct SumThree
{
template <typename T1, typename T2, typename T3>
__host__ __device__
auto operator()(T1 x, T2 y, T3 z) const
THRUST_DECLTYPE_RETURNS(x + y + z)
}; // end SumThree
struct SumThreeTuple
{
template <typename Tuple>
__host__ __device__
auto operator()(Tuple x) const
THRUST_DECLTYPE_RETURNS(thrust::get<0>(x) + thrust::get<1>(x) + thrust::get<2>(x))
}; // end SumThreeTuple
template <typename T>
struct TestZipFunctionTransform
{
void operator()(const size_t n)
{
using namespace thrust;
host_vector<T> h_data0 = unittest::random_samples<T>(n);
host_vector<T> h_data1 = unittest::random_samples<T>(n);
host_vector<T> h_data2 = unittest::random_samples<T>(n);
device_vector<T> d_data0 = h_data0;
device_vector<T> d_data1 = h_data1;
device_vector<T> d_data2 = h_data2;
host_vector<T> h_result_tuple(n);
host_vector<T> h_result_zip(n);
device_vector<T> d_result_zip(n);
// Tuple base case
transform(make_zip_iterator(make_tuple(h_data0.begin(), h_data1.begin(), h_data2.begin())),
make_zip_iterator(make_tuple(h_data0.end(), h_data1.end(), h_data2.end())),
h_result_tuple.begin(),
SumThreeTuple{});
// Zip Function
transform(make_zip_iterator(make_tuple(h_data0.begin(), h_data1.begin(), h_data2.begin())),
make_zip_iterator(make_tuple(h_data0.end(), h_data1.end(), h_data2.end())),
h_result_zip.begin(),
make_zip_function(SumThree{}));
transform(make_zip_iterator(make_tuple(d_data0.begin(), d_data1.begin(), d_data2.begin())),
make_zip_iterator(make_tuple(d_data0.end(), d_data1.end(), d_data2.end())),
d_result_zip.begin(),
make_zip_function(SumThree{}));
ASSERT_EQUAL(h_result_tuple, h_result_zip);
ASSERT_EQUAL(h_result_tuple, d_result_zip);
}
};
VariableUnitTest<TestZipFunctionTransform, ThirtyTwoBitTypes> TestZipFunctionTransformInstance;
#endif // THRUST_CPP_DIALECT
|