19 #include <rmm/detail/error.hpp>
20 #include <rmm/detail/export.hpp>
21 #include <rmm/detail/format.hpp>
29 namespace RMM_NAMESPACE {
59 template <
typename Upstream>
72 std::size_t allocation_limit,
74 : upstream_{upstream},
75 allocation_limit_{allocation_limit},
91 std::size_t allocation_limit,
94 allocation_limit_{allocation_limit},
140 auto const proposed_size =
align_up(bytes, alignment_);
141 auto const old = allocated_bytes_.fetch_add(proposed_size);
142 if (old + proposed_size <= allocation_limit_) {
144 return get_upstream_resource().allocate_async(bytes, stream);
146 allocated_bytes_ -= proposed_size;
151 allocated_bytes_ -= proposed_size;
152 auto const msg = std::string(
"超出内存限制(未能分配 ") +
153 rmm::detail::format_bytes(bytes) +
")";
153 rmm::detail::format_bytes(bytes) +
")";
164 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override 166 std::size_t allocated_size =
align_up(bytes, alignment_);
153 rmm::detail::format_bytes(bytes) +
")";
167 get_upstream_resource().deallocate_async(ptr, bytes, stream);
168 allocated_bytes_ -= allocated_size;
178 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override 180 if (
this == &other) {
return true; }
181 auto const* cast =
dynamic_cast<limiting_resource_adaptor<Upstream> const*
>(&other);
182 if (cast ==
nullptr) {
return false; }
183 return get_upstream_resource() == cast->get_upstream_resource();
190 std::size_t allocation_limit_;