File: zip_iterator_sort.cu

package info (click to toggle)
cccl 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,248 kB
  • sloc: cpp: 264,457; python: 6,421; sh: 2,762; perl: 460; makefile: 114; xml: 13
file content (32 lines) | stat: -rw-r--r-- 951 bytes parent folder | download
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
#include <thrust/iterator/zip_iterator.h>
#include <thrust/sort.h>

#include <unittest/unittest.h>

template <typename T>
struct TestZipIteratorStableSort
{
  void operator()(const size_t n)
  {
    using namespace thrust;

    host_vector<T> h1 = unittest::random_integers<T>(n);
    host_vector<T> h2 = unittest::random_integers<T>(n);

    device_vector<T> d1 = h1;
    device_vector<T> d2 = h2;

    // sort on host
    stable_sort(make_zip_iterator(make_tuple(h1.begin(), h2.begin())),
                make_zip_iterator(make_tuple(h1.end(), h2.end())));

    // sort on device
    stable_sort(make_zip_iterator(make_tuple(d1.begin(), d2.begin())),
                make_zip_iterator(make_tuple(d1.end(), d2.end())));

    ASSERT_EQUAL_QUIET(h1, d1);
    ASSERT_EQUAL_QUIET(h2, d2);
  }
};
VariableUnitTest<TestZipIteratorStableSort, unittest::type_list<unittest::int8_t, unittest::int16_t, unittest::int32_t>>
  TestZipIteratorStableSortInstance;