diff --git a/include/rmm/cuda_stream_view.hpp b/include/rmm/cuda_stream_view.hpp index 1cdebbf52..55fa0d8b3 100644 --- a/include/rmm/cuda_stream_view.hpp +++ b/include/rmm/cuda_stream_view.hpp @@ -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()} {} @@ -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(); } diff --git a/include/rmm/device_buffer.hpp b/include/rmm/device_buffer.hpp index d826cebdf..7405a30e9 100644 --- a/include/rmm/device_buffer.hpp +++ b/include/rmm/device_buffer.hpp @@ -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: diff --git a/include/rmm/device_uvector.hpp b/include/rmm/device_uvector.hpp index 51499d97e..0164f2984 100644 --- a/include/rmm/device_uvector.hpp +++ b/include/rmm/device_uvector.hpp @@ -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 {} /** diff --git a/include/rmm/mr/device/device_memory_resource.hpp b/include/rmm/mr/device/device_memory_resource.hpp index 6a084e407..faacee1a3 100644 --- a/include/rmm/mr/device/device_memory_resource.hpp +++ b/include/rmm/mr/device/device_memory_resource.hpp @@ -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` @@ -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` @@ -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 @@ -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); @@ -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: diff --git a/include/rmm/mr/device/pool_memory_resource.hpp b/include/rmm/mr/device/pool_memory_resource.hpp index 99e8a5bec..cf8557447 100644 --- a/include/rmm/mr/device/pool_memory_resource.hpp +++ b/include/rmm/mr/device/pool_memory_resource.hpp @@ -60,11 +60,18 @@ namespace detail { template struct maybe_remove_property {}; +/** + * @brief Specialization of maybe_remove_property to not propagate non existing properties + */ template struct maybe_remove_property< PoolResource, Upstream, cuda::std::enable_if_t>> { + /** + * @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 diff --git a/include/rmm/mr/host/host_memory_resource.hpp b/include/rmm/mr/host/host_memory_resource.hpp index ee06645ab..1163e26e3 100644 --- a/include/rmm/mr/host/host_memory_resource.hpp +++ b/include/rmm/mr/host/host_memory_resource.hpp @@ -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: diff --git a/include/rmm/mr/host/pinned_memory_resource.hpp b/include/rmm/mr/host/pinned_memory_resource.hpp index cbf51f37e..91a08cbab 100644 --- a/include/rmm/mr/host/pinned_memory_resource.hpp +++ b/include/rmm/mr/host/pinned_memory_resource.hpp @@ -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 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));