Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,38 @@ struct _CCCL_DECLSPEC_EMPTY_BASES synchronous_resource_ref
template <class... _OtherProperties>
synchronous_resource_ref(::cuda::mr::resource_ref<_OtherProperties...>) = delete;

_CCCL_TEMPLATE(class... _OtherProperties)
_CCCL_REQUIRES((::cuda::std::__type_set_contains_v<::cuda::std::__type_set<_OtherProperties...>, _Properties...>) )
synchronous_resource_ref& operator=(const synchronous_resource_ref<_OtherProperties...>& __other) noexcept
{
__basic_any_access::__cast_to(
const_cast<synchronous_resource_ref<_OtherProperties...>&>(__other).__get_base(), __get_base());
return *this;
}

synchronous_resource_ref& operator=(const synchronous_resource_ref& __other) noexcept
{
__basic_any_access::__cast_to(const_cast<synchronous_resource_ref&>(__other).__get_base(), __get_base());
return *this;
}

using default_queries = ::cuda::mr::properties_list<_Properties...>;

private:
static_assert(::cuda::mr::__contains_execution_space_property<_Properties...>,
"The properties of cuda::experimental::synchronous_resource_ref must contain at least one execution "
"space "
"property!");

template <class...>
friend struct synchronous_resource_ref;

using __base::interface;

__base& __get_base() noexcept
{
return *this;
}
};

//! @brief Type erased wrapper around a `synchronous_resource` that satisfies \tparam _Properties
Expand All @@ -389,6 +413,20 @@ struct _CCCL_DECLSPEC_EMPTY_BASES resource_ref
// Inherit other constructors from __basic_any
_LIBCUDACXX_DELEGATE_CONSTRUCTORS(resource_ref, ::cuda::__basic_any, experimental::__iasync_resource<_Properties...>&);

_CCCL_TEMPLATE(class... _OtherProperties)
_CCCL_REQUIRES((::cuda::std::__type_set_contains_v<::cuda::std::__type_set<_OtherProperties...>, _Properties...>) )
resource_ref& operator=(const resource_ref<_OtherProperties...>& __other) noexcept
{
__basic_any_access::__cast_to(const_cast<resource_ref<_OtherProperties...>&>(__other).__get_base(), __get_base());
return *this;
}

resource_ref& operator=(const resource_ref& __other) noexcept
{
__basic_any_access::__cast_to(const_cast<resource_ref&>(__other).__get_base(), __get_base());
return *this;
}

using default_queries = ::cuda::mr::properties_list<_Properties...>;

private:
Expand All @@ -398,6 +436,8 @@ private:

template <class...>
friend struct synchronous_resource_ref;
template <class...>
friend struct resource_ref;

using __base::interface;

Expand Down
20 changes: 20 additions & 0 deletions cudax/test/memory_resource/any_async_resource.cu
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,24 @@ TEMPLATE_TEST_CASE_METHOD(test_fixture, "any_resource", "[container][resource]",
this->counts = Counts();
}

TEMPLATE_TEST_CASE_METHOD(
test_fixture, "ref assignment operators", "[container][resource]", big_resource, small_resource)
{
big_resource mr{42, this};
cudax::resource_ref<::cuda::mr::host_accessible, get_data> ref{mr};
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 42);

big_resource mr2{43, this};
cudax::resource_ref<::cuda::mr::host_accessible, get_data> ref2{mr2};
ref = ref2;
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 43);

cudax::resource_ref<::cuda::mr::host_accessible, get_data, extra_property> ref3{mr};
ref = ref3;
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 42);
}

#endif // __CUDA_ARCH__
20 changes: 20 additions & 0 deletions cudax/test/memory_resource/any_resource.cu
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,23 @@ TEMPLATE_TEST_CASE_METHOD(
// Reset the counters:
this->counts = Counts();
}

TEMPLATE_TEST_CASE_METHOD(
test_fixture, "synchronous ref assignment operators", "[container][resource]", big_resource, small_resource)
{
big_resource mr{42, this};
cudax::synchronous_resource_ref<::cuda::mr::host_accessible, get_data> ref{mr};
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 42);

big_resource mr2{43, this};
cudax::synchronous_resource_ref<::cuda::mr::host_accessible, get_data> ref2{mr2};
ref = ref2;
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 43);

cudax::synchronous_resource_ref<::cuda::mr::host_accessible, get_data, extra_property> ref3{mr};
ref = ref3;
CHECK(ref.allocate_sync(bytes(100), align(8)) == this);
CHECK(get_property(ref, get_data{}) == 42);
}
4 changes: 4 additions & 0 deletions cudax/test/memory_resource/test_resource.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ struct get_data
using value_type = int;
};

struct extra_property
{};

template <class T>
struct test_resource
{
Expand Down Expand Up @@ -213,6 +216,7 @@ struct test_resource
}

friend constexpr void get_property(const test_resource&, ::cuda::mr::host_accessible) noexcept {}
friend constexpr void get_property(const test_resource&, extra_property) noexcept {}
friend constexpr int get_property(const test_resource& self, get_data) noexcept
{
return self.data;
Expand Down