Skip to content

Commit

Permalink
Fix comparison - step 1.
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Zientkiewicz <[email protected]>
  • Loading branch information
mzient committed Jul 20, 2021
1 parent 5948149 commit b14bbca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class resource : public cuda::memory_resource<cuda::memory_kind::pinned> {

#ifndef _LIBCUDACXX_NO_RTTI
bool do_is_equal(const cuda::memory_resource<cuda::memory_kind::pinned> &other) const noexcept override {
fprintf(stderr, "Comparison start: %p %p\n", this, &other);
if (auto *other_ptr = dynamic_cast<const resource *>(&other)) {
fprintf(stderr, "values: %d %d\n", value, other_ptr->value);
return value == other_ptr->value;
} else {
return false;
Expand All @@ -44,6 +46,7 @@ class resource : public cuda::memory_resource<cuda::memory_kind::pinned> {
struct tag1;
struct tag2;


int main(int argc, char **argv) {
#if !defined(__CUDA_ARCH__) && !defined(_LIBCUDACXX_NO_RTTI)
resource<tag1> r1, r2, r3;
Expand All @@ -52,10 +55,23 @@ int main(int argc, char **argv) {
r2.value = 42;
r3.value = 99;
r4.value = 42;

using t1 = decltype(view_resource(&r1));
using t2 = decltype(view_resource(&r2));
using t4 = decltype(view_resource(&r4));
assert(view_resource(&r1) == view_resource(&r2));
assert(view_resource(&r1) != view_resource(&r3));
assert(view_resource(&r1) == view_resource(&r4));
assert(view_resource(&r4) == view_resource(&r4));
cuda::resource_view<cuda::memory_access::host, cuda::memory_access::device> v1 = &r1;
cuda::resource_view<cuda::memory_access::device> v2 = &r2;
cuda::resource_view<cuda::memory_access::host> v3 = &r3;
cuda::resource_view<cuda::memory_access::device, cuda::memory_access::host> v4 = &r4;
assert(v1 == v2);
assert(v1 != v3);
assert(v1 != v4);
// assert(v2 != v3); - cannot compare
assert(v2 != v4);
assert(v3 != v4);
assert(v4 == v4);
#endif
return 0;
}
10 changes: 5 additions & 5 deletions include/cuda/memory_resource
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected:
}

template <typename _ResourcePointer, typename... _Properties>
friend class basic_resource_view;
friend class cuda::basic_resource_view;
};

class stream_ordered_memory_resource_base : public virtual memory_resource_base {
Expand Down Expand Up @@ -297,7 +297,7 @@ protected:
virtual void do_deallocate_async(void *__mem, size_t __bytes, size_t __alignment, stream_view __stream) = 0;

template <typename _ResourcePointer, typename... _Properties>
friend class basic_resource_view;
friend class cuda::basic_resource_view;
};

} // namespace detail
Expand Down Expand Up @@ -397,11 +397,11 @@ private:
}

bool is_equal_base(const detail::memory_resource_base &__other) const noexcept final override {
#if _LIBCUDACXX_NO_RTTI
#ifdef _LIBCUDACXX_NO_RTTI
return this == &__other;
#else
if (auto *__other_res = dynamic_cast<const memory_resource *>(&__other))
return do_is_equal(__other_res);
return do_is_equal(*__other_res);
else
return false;
#endif
Expand Down Expand Up @@ -764,7 +764,7 @@ public:
using __view2_t = basic_resource_view<_Ptr2, _Props2...>;
static_assert(cuda::is_view_convertible<__view1_t, __view2_t>::value || cuda::is_view_convertible<__view2_t, __view1_t>::value,
"The resource views are not compatible");
return static_cast<const detail::memory_resource_base*>(__pointer)->is_equal(__v2.pointer);
return static_cast<const detail::memory_resource_base*>(__pointer)->is_equal(*__v2.__pointer);
}

template <typename _Ptr2, typename... _Props2>
Expand Down

0 comments on commit b14bbca

Please sign in to comment.