|
9 | 9 | #include <thrust/iterator/constant_iterator.h> |
10 | 10 | #include <thrust/iterator/discard_iterator.h> |
11 | 11 | #include <thrust/iterator/retag.h> |
| 12 | +#include <thrust/device_malloc.h> |
| 13 | +#include <thrust/device_free.h> |
12 | 14 |
|
13 | 15 | void TestCopyFromConstIterator(void) |
14 | 16 | { |
@@ -617,3 +619,62 @@ void TestCopyIfStencilDispatchImplicit() |
617 | 619 | } |
618 | 620 | DECLARE_UNITTEST(TestCopyIfStencilDispatchImplicit); |
619 | 621 |
|
| 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); |
0 commit comments