Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit c9fe022

Browse files
committed
Fix issues in testing/allocator.cu.
- The `g_state` flag wasn't reset between executions. - The `destroy` method was being invoke in the current host system, not the system that owned the allocated memory (always cpp). This broke on MSVC's OpenMP implementation, where it seemed to be asserting the `g_state` flag before it was updated by `destroy`. This only happened on MSVC when host system = OMP, and appears to be a bug/miscompile in MSVC (repro'd on 2019). Fixed by explicitly tagging the allocator system to cpp. - Added check that `destroy` is not invoked on empty vectors.
1 parent 427a0c2 commit c9fe022

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

testing/allocator.cu

+10-5
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomCopyConstruct);
6363
template <typename T>
6464
struct my_allocator_with_custom_destroy
6565
{
66-
typedef T value_type;
67-
typedef T & reference;
68-
typedef const T & const_reference;
66+
// This is only used with thrust::cpp::vector:
67+
using system_type = thrust::cpp::tag;
68+
69+
using value_type = T;
70+
using reference = T &;
71+
using const_reference = const T &;
6972

7073
static bool g_state;
7174

@@ -120,12 +123,14 @@ bool my_allocator_with_custom_destroy<T>::g_state = false;
120123
template <typename T>
121124
void TestAllocatorCustomDestroy(size_t n)
122125
{
126+
my_allocator_with_custom_destroy<T>::g_state = false;
127+
123128
{
124129
thrust::cpp::vector<T, my_allocator_with_custom_destroy<T> > vec(n);
125130
} // destroy everything
126131

127-
if (0 < n)
128-
ASSERT_EQUAL(true, my_allocator_with_custom_destroy<T>::g_state);
132+
// state should only be true when there are values to destroy:
133+
ASSERT_EQUAL(n > 0, my_allocator_with_custom_destroy<T>::g_state);
129134
}
130135
DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomDestroy);
131136

0 commit comments

Comments
 (0)