Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complete set of resource ref aliases #1479

Merged
merged 3 commits into from
Feb 26, 2024
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
32 changes: 32 additions & 0 deletions include/rmm/resource_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,43 @@ namespace rmm {
* @file
*/

/**
* @brief Alias for a `cuda::mr::resource_ref` with the property
* `cuda::mr::device_accessible`.
*/
using device_resource_ref = cuda::mr::resource_ref<cuda::mr::device_accessible>;

/**
* @brief Alias for a `cuda::mr::async_resource_ref` with the property
* `cuda::mr::device_accessible`.
*/
nvdbaranec marked this conversation as resolved.
Show resolved Hide resolved
using device_async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::device_accessible>;

/**
* @brief Alias for a `cuda::mr::resource_ref` with the property
* `cuda::mr::host_accessible`.
*/
using host_resource_ref = cuda::mr::resource_ref<cuda::mr::host_accessible>;

/**
* @brief Alias for a `cuda::mr::async_resource_ref` with the property
* `cuda::mr::host_accessible`.
*/
using host_async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::host_accessible>;
Copy link
Member

@harrism harrism Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be common for users of async_resource_ref for pinned host memory to also want device_accessible. (I expect you will want it in your cuDF usage eventually too...) My question is, do we want to just add cuda::mr::device_accessible to this alias, or add another one:

using host_device_async_resource_ref = 
  cuda::mr::async_resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible>;

Thoughts @nvdbaranec @Missco @jrhemstad ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add device_accessible to the host_async_resource_ref as that would all potential memory resource to satisfy device_accessible

On the other hand an async resource has no real value without device_accessible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. However I think an async resource ref that is host-only has value because it specifies that it will only be used on the host, but it may still be backed by pinned memory. And then it benefits from stream-ordered allocation (e.g. can be used in a stream-ordered pool) and also can be used as the host memory for SOL cudaMemcpyAsync.

So really for completeness I think we probably need the full set:

using host_resource_ref = cuda::mr::resource_ref<cuda::mr::host_accessible>;
using device_resource_ref = cuda::mr::resource_ref<cuda::mr::device_accessible>;
using host_device_resource_ref = cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible>;
using host_async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::host_accessible>;
using device_async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::device_accessible>;
using host_device_async_resource_ref = cuda::mr::async_resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case for this right now in cudf is strictly in the hostdevice_vector class, whose sole purpose is to force explicit host<->device copying onto the user. That is: entirely avoiding the device touching pinned memory directly. So in that sense, stream ordering at the allocator level isn't necessary.

https://github.com/rapidsai/cudf/blob/branch-24.04/cpp/src/io/utilities/hostdevice_vector.hpp

As for whether cudf at large will ever need this, I'm not sure. At the moment it definitely prefers to be explicit about all host<-> device handoffs.


/**
* @brief Alias for a `cuda::mr::resource_ref` with the properties
* `cuda::mr::host_accessible` and `cuda::mr::device_accessible`.
*/
using host_device_resource_ref =
cuda::mr::resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible>;

/**
* @brief Alias for a `cuda::mr::async_resource_ref` with the properties
* `cuda::mr::host_accessible` and `cuda::mr::device_accessible`.
*/
using host_device_async_resource_ref =
cuda::mr::async_resource_ref<cuda::mr::host_accessible, cuda::mr::device_accessible>;

/** @} */ // end of group
} // namespace rmm
5 changes: 3 additions & 2 deletions tests/mr/host/mr_ref_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <rmm/mr/host/host_memory_resource.hpp>
#include <rmm/mr/host/new_delete_resource.hpp>
#include <rmm/mr/host/pinned_memory_resource.hpp>
#include <rmm/resource_ref.hpp>

#include <cuda/memory_resource>
#include <cuda_runtime_api.h>
Expand Down Expand Up @@ -72,7 +73,7 @@ struct allocation {
template <typename MemoryResourceType>
struct MRRefTest : public ::testing::Test {
MemoryResourceType mr;
cuda::mr::resource_ref<cuda::mr::host_accessible> ref;
rmm::host_resource_ref ref;

MRRefTest() : mr{}, ref{mr} {}
};
Expand Down Expand Up @@ -248,7 +249,7 @@ TYPED_TEST(MRRefTest, UnsupportedAlignmentTest)
TEST(PinnedResource, isPinned)
{
rmm::mr::pinned_memory_resource mr;
cuda::mr::resource_ref<cuda::mr::host_accessible> ref{mr};
rmm::host_resource_ref ref{mr};
void* ptr{nullptr};
EXPECT_NO_THROW(ptr = ref.allocate(100));
EXPECT_TRUE(is_pinned_memory(ptr));
Expand Down
Loading