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

Commit

Permalink
Fix issues in testing/allocator.cu.
Browse files Browse the repository at this point in the history
- 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
1 parent 427a0c2 commit c9fe022
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit c9fe022

Please sign in to comment.