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
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/__memory_pool/device_memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ struct device_memory_pool : device_memory_pool_ref
}

//! @brief Returns a \c device_memory_pool_ref for this \c device_memory_pool.
//! The result is the same as if this object was cast to a \c device_memory_pool_ref.
[[nodiscard]] _CCCL_HOST_API device_memory_pool_ref as_ref() noexcept
//! We return by reference to ensure that we can subsequently convert to a resource_ref
[[nodiscard]] _CCCL_HOST_API device_memory_pool_ref& as_ref() noexcept
{
return device_memory_pool_ref(__pool_);
return static_cast<device_memory_pool_ref&>(*this);
}

device_memory_pool(const device_memory_pool&) = delete;
Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/__memory_pool/managed_memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ struct managed_memory_pool : managed_memory_pool_ref
}

//! @brief Returns a \c managed_memory_pool_ref for this \c managed_memory_pool.
//! The result is the same as if this object was cast to a \c managed_memory_pool_ref.
[[nodiscard]] _CCCL_HOST_API managed_memory_pool_ref as_ref() noexcept
//! We return by reference to ensure that we can subsequently convert to a resource_ref
[[nodiscard]] _CCCL_HOST_API managed_memory_pool_ref& as_ref() noexcept
{
return managed_memory_pool_ref(__pool_);
return static_cast<managed_memory_pool_ref&>(*this);
}

managed_memory_pool(const managed_memory_pool&) = delete;
Expand Down
6 changes: 3 additions & 3 deletions libcudacxx/include/cuda/__memory_pool/pinned_memory_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ struct pinned_memory_pool : pinned_memory_pool_ref
}

//! @brief Returns a \c pinned_memory_pool_ref for this \c pinned_memory_pool.
//! The result is the same as if this object was cast to a \c pinned_memory_pool_ref.
_CCCL_HOST_API pinned_memory_pool_ref as_ref() noexcept
//! We return by reference to ensure that we can subsequently convert to a resource_ref
_CCCL_HOST_API pinned_memory_pool_ref& as_ref() noexcept
{
return pinned_memory_pool_ref(__pool_);
return static_cast<pinned_memory_pool_ref&>(*this);
}

pinned_memory_pool(const pinned_memory_pool&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static bool ensure_export_handle(::cudaMemPool_t pool, const ::cudaMemAllocation
return allocation_handle == ::cudaMemHandleTypeNone ? status == ::cudaErrorInvalidValue : status == ::cudaSuccess;
}

C2H_CCCLRT_TEST("device_memory_resource construction", "[memory_resource]")
C2H_CCCLRT_TEST("device_memory_pool construction", "[memory_resource]")
{
int current_device = 0;
cuda::__ensure_current_context guard{cuda::device_ref{current_device}};
Expand Down Expand Up @@ -217,7 +217,7 @@ static void ensure_device_ptr(void* ptr)
CHECK(attributes.type == cudaMemoryTypeDevice);
}

C2H_CCCLRT_TEST("device_memory_resource allocation", "[memory_resource]")
C2H_CCCLRT_TEST("device_memory_pool allocation", "[memory_resource]")
{
cudaStream_t raw_stream;
{
Expand Down Expand Up @@ -332,7 +332,7 @@ C2H_CCCLRT_TEST("device_memory_resource allocation", "[memory_resource]")
}
}

C2H_CCCLRT_TEST("device_memory_resource comparison", "[memory_resource]")
C2H_CCCLRT_TEST("device_memory_pool comparison", "[memory_resource]")
{
int current_device = 0;
cuda::__ensure_current_context guard{cuda::device_ref{current_device}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,84 @@ C2H_CCCLRT_TEST("pinned_memory_pool with allocation handle", "[memory_resource]"

// managed memory pool does not support allocation handles yet.
#endif // !_CCCL_OS(WINDOWS)

C2H_CCCLRT_TEST("device_memory_pool conversion to resource_ref", "[memory_resource]")
{
int current_device = 0;
cuda::__ensure_current_context guard{cuda::device_ref{current_device}};

cuda::device_memory_pool pool{cuda::device_ref{0}};
cuda::mr::resource_ref<cuda::mr::device_accessible> ref1 = pool.as_ref();

cuda::device_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::device_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}

#if _CCCL_CTK_AT_LEAST(13, 0) && !_CCCL_OS(WINDOWS)
C2H_CCCLRT_TEST("managed_memory_pool conversion to resource_ref", "[memory_resource]")
{
int current_device = 0;
cuda::__ensure_current_context guard{cuda::device_ref{current_device}};

cuda::managed_memory_pool pool{};

{ // host device accessible
cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible> ref1 = pool.as_ref();

cuda::managed_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}

{ // host accessible
cuda::mr::resource_ref<cuda::mr::host_accessible> ref1 = pool.as_ref();

cuda::managed_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::host_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}

{ // device accessible
cuda::mr::resource_ref<cuda::mr::device_accessible> ref1 = pool.as_ref();

cuda::managed_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::device_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}
}
#endif // _CCCL_CTK_AT_LEAST(13, 0) && !_CCCL_OS(WINDOWS)

#if _CCCL_CTK_AT_LEAST(12, 6)
C2H_CCCLRT_TEST("pinned_memory_pool conversion to resource_ref", "[memory_resource]")
{
int current_device = 0;
cuda::__ensure_current_context guard{cuda::device_ref{current_device}};

cuda::pinned_memory_pool pool{0};

{ // host device accessible
cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible> ref1 = pool.as_ref();

cuda::pinned_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}

{ // host accessible
cuda::mr::resource_ref<cuda::mr::host_accessible> ref1 = pool.as_ref();

cuda::pinned_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::host_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}

{ // device accessible
cuda::mr::resource_ref<cuda::mr::device_accessible> ref1 = pool.as_ref();

cuda::pinned_memory_pool_ref pool_ref = pool.as_ref();
cuda::mr::resource_ref<cuda::mr::device_accessible> ref2 = pool_ref;
CHECK((ref1 == ref2));
}
}
#endif // _CCCL_CTK_AT_LEAST(12, 6)
Loading