Adding reservation aware resource adapter - #1142
Conversation
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
/ok to test |
| auto const padded_bytes = | ||
| safe_cast<std::int64_t>(rmm::align_up(bytes, alignment)); | ||
| balance_.fetch_add(padded_bytes, std::memory_order_acq_rel); | ||
| adaptor_->total_reserved_.fetch_add(padded_bytes, std::memory_order_acq_rel); |
There was a problem hiding this comment.
I would use a method to do this, rather than making total_reserved_ a public member.
There was a problem hiding this comment.
Its private, but MemoryReservationImpl<> has been friended in ReservationAwareResourceAdaptorImpl.
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
@bdice thank you for the review. |
Signed-off-by: niranda perera <niranda.perera@gmail.com>
| if (overbooking > 0 && !allow_overbooking) { | ||
| return {0, overbooking}; | ||
| } | ||
| if (total_reserved_.compare_exchange_weak( |
There was a problem hiding this comment.
current_allocated is "expensive" since it has to acquire a mutex. So let's make this compare_exchange_strong and lose the while loop, no?
There was a problem hiding this comment.
Maybe not. I think the while loop serves 2 purposes.
- spurious failures
total_reserved_reserved could also be modified between L108-119.
So, the latter might still be in effect. I think we can rework the logic to avoid this. Let me try
There was a problem hiding this comment.
I changed this to a more pessimistic approach on total_reserved_. We claim upfront, and if overbooking is not allowed, we rollback.
…-aware-resource-adapter
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
/ok to test |
This PR adds
ReservationAwareResourceAdaptor, whose reservations are themselves RMM memory resources: hand one to cudf and every allocation made through it is charged against the reservation, turning "reserve before allocate" into something the type system and the allocator enforce rather than a convention.MemoryReservationis ashared_resource, so it can be passed anywhere armm::device_async_resource_refis accepted. Allocating draws down its balance and throwsrmm::out_of_memorywhen the grant is exhausted.RmmResourceAdaptor's allocation tracking with a runtime-adjustable limit and a reserved-bytes counter (follows the limit logic inBufferResource)Usage
ReservationAwareResourceAdaptor adaptor{rmm::mr::cuda_memory_resource{}, 1MB}; auto res = adaptor.reserve(2KB, AllowOverbooking::NO); { rmm::device_buffer buf1{1KB, stream, res}; rmm::device_buffer buf2{1KB, stream, res}; EXPECT_THROW((rmm::device_buffer buf3{1KB, stream, res}, rmm::out_of_memory); // res is exhausted } rmm::device_buffer buf4{2KB, stream, res}; // works again because buffers are releasedNotes