Skip to content

Commit

Permalink
Add documentation to added functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
miscco committed Sep 20, 2023
1 parent e1f8ffb commit 40b4a18
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/rmm/cuda_stream_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class cuda_stream_view {

/**
* @brief Implicit conversion from cuda::stream_ref.
*
* @param stream The underlying stream for this view
*/
constexpr cuda_stream_view(cuda::stream_ref stream) noexcept : stream_{stream.get()} {}

Expand All @@ -76,6 +78,8 @@ class cuda_stream_view {

/**
* @brief Implicit conversion to stream_ref.
*
* @return cuda::stream_ref The underlying stream referenced by this cuda_stream_view
*/
constexpr operator cuda::stream_ref() const noexcept { return value(); }

Expand Down
5 changes: 5 additions & 0 deletions include/rmm/device_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ class device_buffer {
*/
[[nodiscard]] async_resource_ref memory_resource() const noexcept { return _mr; }

/**
* @brief Enables the `cuda::mr::device_accessible` property
*
* This property declares that a `device_buffer` provides device accessible memory
*/
friend void get_property(device_buffer const&, cuda::mr::device_accessible) noexcept {}

private:
Expand Down
5 changes: 5 additions & 0 deletions include/rmm/device_uvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ class device_uvector {
return _storage.memory_resource();
}

/**
* @brief Enables the `cuda::mr::device_accessible` property
*
* This property declares that a `device_uvector` provides device accessible memory
*/
friend void get_property(device_uvector const&, cuda::mr::device_accessible) noexcept {}

/**
Expand Down
25 changes: 22 additions & 3 deletions include/rmm/mr/device/device_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class device_memory_resource {
*
* @throws Nothing.
*
* @param p Pointer to be deallocated
* @param ptr Pointer to be deallocated
* @param bytes The size in bytes of the allocation. This must be equal to the
* value of `bytes` that was passed to the `allocate` call that returned `p`.
* @param alignment The alignment that was passed to the `allocate` call that returned `p`
Expand Down Expand Up @@ -251,7 +251,7 @@ class device_memory_resource {
*
* @throws Nothing.
*
* @param p Pointer to be deallocated
* @param ptr Pointer to be deallocated
* @param bytes The size in bytes of the allocation. This must be equal to the
* value of `bytes` that was passed to the `allocate` call that returned `p`.
* @param alignment The alignment that was passed to the `allocate` call that returned `p`
Expand All @@ -278,7 +278,7 @@ class device_memory_resource {
*
* @throws Nothing.
*
* @param p Pointer to be deallocated
* @param ptr Pointer to be deallocated
* @param bytes The size in bytes of the allocation. This must be equal to the
* value of `bytes` that was passed to the `allocate` call that returned `p`.
* @param stream Stream on which to perform allocation
Expand All @@ -288,11 +288,25 @@ class device_memory_resource {
do_deallocate(ptr, bytes, stream);
}

/**
* @brief Comparison operator with another device_memory_resource
*
* @param other The other resource to compare to
* @return true If the two resources are equivalent
* @return false If the two resources are not equivalent
*/
[[nodiscard]] bool operator==(device_memory_resource const& other) const noexcept
{
return do_is_equal(other);
}

/**
* @brief Comparison operator with another device_memory_resource
*
* @param other The other resource to compare to
* @return false If the two resources are equivalent
* @return true If the two resources are not equivalent
*/
[[nodiscard]] bool operator!=(device_memory_resource const& other) const noexcept
{
return !do_is_equal(other);
Expand Down Expand Up @@ -326,6 +340,11 @@ class device_memory_resource {
return do_get_mem_info(stream);
}

/**
* @brief Enables the `cuda::mr::device_accessible` property
*
* This property declares that a `device_memory_resource` provides device accessible memory
*/
friend void get_property(device_memory_resource const&, cuda::mr::device_accessible) noexcept {}

private:
Expand Down
7 changes: 7 additions & 0 deletions include/rmm/mr/device/pool_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ namespace detail {
template <class PoolResource, class Upstream, class = void>
struct maybe_remove_property {};

/**
* @brief Specialization of maybe_remove_property to not propagate non existing properties
*/
template <class PoolResource, class Upstream>
struct maybe_remove_property<
PoolResource,
Upstream,
cuda::std::enable_if_t<!cuda::has_property<Upstream, cuda::mr::device_accessible>>> {
/**
* @brief Explicit removal of the friend function so we do not pretent to provide device
* accessible memory
*/
friend void get_property(const PoolResource&, cuda::mr::device_accessible) = delete;
};
} // namespace detail
Expand Down
19 changes: 19 additions & 0 deletions include/rmm/mr/host/host_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,35 @@ class host_memory_resource {
return do_is_equal(other);
}

/**
* @brief Comparison operator with another device_memory_resource
*
* @param other The other resource to compare to
* @return true If the two resources are equivalent
* @return false If the two resources are not equivalent
*/
[[nodiscard]] bool operator==(host_memory_resource const& other) const noexcept
{
return do_is_equal(other);
}

/**
* @brief Comparison operator with another device_memory_resource
*
* @param other The other resource to compare to
* @return false If the two resources are equivalent
* @return true If the two resources are not equivalent
*/
[[nodiscard]] bool operator!=(host_memory_resource const& other) const noexcept
{
return !do_is_equal(other);
}

/**
* @brief Enables the `cuda::mr::host_accessible` property
*
* This property declares that a `host_memory_resource` provides host accessible memory
*/
friend void get_property(host_memory_resource const&, cuda::mr::host_accessible) noexcept {}

private:
Expand Down
53 changes: 53 additions & 0 deletions include/rmm/mr/host/pinned_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,73 @@ class pinned_memory_resource final : public host_memory_resource {
pinned_memory_resource& operator=(pinned_memory_resource&&) =
default; ///< @default_move_assignment{pinned_memory_resource}

/**
* @brief Query whether the pinned_memory_resource supports use of non-null CUDA streams for
* allocation/deallocation.
*
* @returns bool false.
*/
[[nodiscard]] bool supports_streams() const noexcept { return false; }

/**
* @brief Query whether the resource supports the get_mem_info API.
*
* @return bool false.
*/
[[nodiscard]] bool supports_get_mem_info() const noexcept { return false; }

/**
* @brief Queries the amount of free and total memory for the resource.
*
* @param stream the stream whose memory manager we want to retrieve
*
* @returns a pair containing the free memory in bytes in .first and total amount of memory in
* .second
*/
[[nodiscard]] std::pair<std::size_t, std::size_t> get_mem_info(cuda_stream_view stream) const
{
return std::make_pair(0, 0);
}

/**
* @brief Pretent to support the allocate_async interface, falling back to stream 0
*
* @throws `rmm::bad_alloc` When the requested `bytes` cannot be allocated on
* the specified `stream`.
*
* @param bytes The size of the allocation
* @param alignment The expected alignment of the allocation
* @return void* Pointer to the newly allocated memory
*/
[[nodiscard]] void* allocate_async(std::size_t bytes, std::size_t alignment, cuda_stream_view)
{
return do_allocate(bytes, alignment);
}

/**
* @brief Pretent to support the allocate_async interface, falling back to stream 0
*
* @throws `rmm::bad_alloc` When the requested `bytes` cannot be allocated on
* the specified `stream`.
*
* @param bytes The size of the allocation
* @return void* Pointer to the newly allocated memory
*/
[[nodiscard]] void* allocate_async(std::size_t bytes, cuda_stream_view)
{
return do_allocate(bytes);
}

/**
* @brief Pretent to support the deallocate_async interface, falling back to stream 0
*
* @throws Nothing.
*
* @param ptr Pointer to be deallocated
* @param bytes The size in bytes of the allocation. This must be equal to the
* value of `bytes` that was passed to the `allocate` call that returned `p`.
* @param alignment The alignment that was passed to the `allocate` call that returned `p`
*/
void deallocate_async(void* ptr, std::size_t bytes, std::size_t alignment, cuda_stream_view)
{
do_deallocate(ptr, rmm::detail::align_up(bytes, alignment));
Expand Down

0 comments on commit 40b4a18

Please sign in to comment.