Skip to content

Commit 306bec0

Browse files
committed
The great Thrust index type fix, part 3: (partially) verify copy.
1 parent f28a6b6 commit 306bec0

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

testing/copy.cu

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <thrust/iterator/constant_iterator.h>
1010
#include <thrust/iterator/discard_iterator.h>
1111
#include <thrust/iterator/retag.h>
12+
#include <thrust/device_malloc.h>
13+
#include <thrust/device_free.h>
1214

1315
void TestCopyFromConstIterator(void)
1416
{
@@ -617,3 +619,62 @@ void TestCopyIfStencilDispatchImplicit()
617619
}
618620
DECLARE_UNITTEST(TestCopyIfStencilDispatchImplicit);
619621

622+
struct only_set_when_expected_it
623+
{
624+
unsigned long long expected;
625+
bool * flag;
626+
627+
__host__ __device__ only_set_when_expected_it operator++() const { return *this; }
628+
__host__ __device__ only_set_when_expected_it operator*() const { return *this; }
629+
template<typename Difference>
630+
__host__ __device__ only_set_when_expected_it operator+(Difference) const { return *this; }
631+
template<typename Index>
632+
__host__ __device__ only_set_when_expected_it operator[](Index) const { return *this; }
633+
634+
__device__
635+
void operator=(long long value) const
636+
{
637+
if (value == expected)
638+
{
639+
*flag = true;
640+
}
641+
}
642+
};
643+
644+
namespace thrust
645+
{
646+
template<>
647+
struct iterator_traits<only_set_when_expected_it>
648+
{
649+
typedef long long value_type;
650+
typedef only_set_when_expected_it reference;
651+
};
652+
}
653+
654+
void TestCopyWithBigIndexesHelper(int magnitude)
655+
{
656+
thrust::counting_iterator<unsigned long long> begin(0);
657+
thrust::counting_iterator<unsigned long long> end = begin + (1ull << magnitude);
658+
ASSERT_EQUAL(thrust::distance(begin, end), 1ll << magnitude);
659+
660+
thrust::device_ptr<bool> has_executed = thrust::device_malloc<bool>(1);
661+
*has_executed = false;
662+
663+
only_set_when_expected_it out = { (1ull << magnitude) - 1, thrust::raw_pointer_cast(has_executed) };
664+
665+
thrust::copy(thrust::device, begin, end, out);
666+
667+
bool has_executed_h = *has_executed;
668+
thrust::device_free(has_executed);
669+
670+
ASSERT_EQUAL(has_executed_h, true);
671+
}
672+
673+
void TestCopyWithBigIndexes()
674+
{
675+
TestCopyWithBigIndexesHelper(30);
676+
TestCopyWithBigIndexesHelper(31);
677+
TestCopyWithBigIndexesHelper(32);
678+
TestCopyWithBigIndexesHelper(33);
679+
}
680+
DECLARE_UNITTEST(TestCopyWithBigIndexes);

testing/for_each.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ DECLARE_UNITTEST(TestForEachNWithLargeTypes);
355355

356356
THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END
357357

358-
struct OnlySetWhenExpected
358+
struct only_set_when_expected
359359
{
360360
unsigned long long expected;
361361
bool * flag;
@@ -379,7 +379,7 @@ void TestForEachWithBigIndexesHelper(int magnitude)
379379
thrust::device_ptr<bool> has_executed = thrust::device_malloc<bool>(1);
380380
*has_executed = false;
381381

382-
OnlySetWhenExpected fn = { (1ull << magnitude) - 1, thrust::raw_pointer_cast(has_executed) };
382+
only_set_when_expected fn = { (1ull << magnitude) - 1, thrust::raw_pointer_cast(has_executed) };
383383

384384
thrust::for_each(thrust::device, begin, end, fn);
385385

0 commit comments

Comments
 (0)