Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
Prev Previous commit
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.
  • Loading branch information
alliepiper committed May 16, 2022
commit 4cdf6deedda1ad2bd4fa1b37367c90cd16e2c7e5
15 changes: 10 additions & 5 deletions testing/allocator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomCopyConstruct);
template <typename T>
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;

Expand Down Expand Up @@ -120,12 +123,14 @@ bool my_allocator_with_custom_destroy<T>::g_state = false;
template <typename T>
void TestAllocatorCustomDestroy(size_t n)
{
my_allocator_with_custom_destroy<T>::g_state = false;

{
thrust::cpp::vector<T, my_allocator_with_custom_destroy<T> > vec(n);
} // destroy everything

if (0 < n)
ASSERT_EQUAL(true, my_allocator_with_custom_destroy<T>::g_state);
// state should only be true when there are values to destroy:
ASSERT_EQUAL(n > 0, my_allocator_with_custom_destroy<T>::g_state);
}
DECLARE_VARIABLE_UNITTEST(TestAllocatorCustomDestroy);

Expand Down