Closed GoogleCodeExporter closed 9 years ago
Here's a reproducer for the smallest N i could find:
#include <unittest/unittest.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/reduce.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
template<typename Tuple>
struct TuplePlus
{
__host__ __device__
Tuple operator()(Tuple x, Tuple y) const
{
using namespace thrust;
return make_tuple(get<0>(x) + get<0>(y),
get<1>(x) + get<1>(y));
}
}; // end TuplePlus
int main()
{
size_t n = 1505;
using namespace thrust;
typedef long T;
host_vector<T> h_data0 = unittest::random_integers<bool>(n);
host_vector<T> h_data1 = unittest::random_integers<T>(n);
host_vector<T> h_data2 = unittest::random_integers<T>(n);
host_vector<T> h_data3(n,0);
host_vector<T> h_data4(n,0);
host_vector<T> h_data5(n,0);
device_vector<T> d_data0 = h_data0;
device_vector<T> d_data1 = h_data1;
device_vector<T> d_data2 = h_data2;
device_vector<T> d_data3(n,0);
device_vector<T> d_data4(n,0);
device_vector<T> d_data5(n,0);
typedef tuple<T,T> Tuple;
// run on host
reduce_by_key
( make_zip_iterator(make_tuple(h_data0.begin(), h_data0.begin())),
make_zip_iterator(make_tuple(h_data0.end(), h_data0.end())),
make_zip_iterator(make_tuple(h_data1.begin(), h_data2.begin())),
make_zip_iterator(make_tuple(h_data3.begin(), h_data3.begin())),
make_zip_iterator(make_tuple(h_data4.begin(), h_data5.begin())),
equal_to<Tuple>(),
TuplePlus<Tuple>());
// run on device
reduce_by_key
( make_zip_iterator(make_tuple(d_data0.begin(), d_data0.begin())),
make_zip_iterator(make_tuple(d_data0.end(), d_data0.end())),
make_zip_iterator(make_tuple(d_data1.begin(), d_data2.begin())),
make_zip_iterator(make_tuple(d_data3.begin(), d_data3.begin())),
make_zip_iterator(make_tuple(d_data4.begin(), d_data5.begin())),
equal_to<Tuple>(),
TuplePlus<Tuple>());
ASSERT_EQUAL(h_data3, d_data3);
ASSERT_EQUAL(h_data4, d_data4);
ASSERT_EQUAL(h_data5, d_data5);
return 0;
}
Original comment by jaredhoberock
on 1 Mar 2012 at 9:59
This issue was closed by revision 257c6c3a96a6.
Original comment by wnbell
on 2 Mar 2012 at 10:31
Original issue reported on code.google.com by
jaredhoberock
on 1 Mar 2012 at 12:34