From c9fe022283a48e9de2d5858f5989ad2d607041b3 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Thu, 14 Apr 2022 15:02:24 -0400 Subject: [PATCH] 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. --- testing/allocator.cu | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/testing/allocator.cu b/testing/allocator.cu index 0317a2b312..175685ed04 100644 --- a/testing/allocator.cu +++ b/testing/allocator.cu @@ -63,9 +63,12 @@ DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomCopyConstruct); template struct my_allocator_with_custom_destroy { - typedef T value_type; - typedef T & reference; - typedef const T & const_reference; + // This is only used with thrust::cpp::vector: + using system_type = thrust::cpp::tag; + + using value_type = T; + using reference = T &; + using const_reference = const T &; static bool g_state; @@ -120,12 +123,14 @@ bool my_allocator_with_custom_destroy::g_state = false; template void TestAllocatorCustomDestroy(size_t n) { + my_allocator_with_custom_destroy::g_state = false; + { thrust::cpp::vector > vec(n); } // destroy everything - if (0 < n) - ASSERT_EQUAL(true, my_allocator_with_custom_destroy::g_state); + // state should only be true when there are values to destroy: + ASSERT_EQUAL(n > 0, my_allocator_with_custom_destroy::g_state); } DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomDestroy);