-
Notifications
You must be signed in to change notification settings - Fork 211
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
[FEA] Make device_vector
safer to use in multi-device setting
#1527
Comments
Perhaps we should benchmark it. In the single-device case, the |
I think you are refering to this: #1370 (comment) . I think the case in RMM's thrust allocator isn't as bad -- putting the set device in allocate/deallocate wouldn't be the same as putting it way down in |
Previously, the user had to arrange that the device active when a thrust_allocator object was created was also active when allocate and deallocate was called. This is hard to manage if exceptions are thrown. Instead, save the active device on construction and ensure that it is active when calling deallocate and deallocate. This means that device_vector is safe to destruct with RAII semantics in a multi-device setting. Add tests of this facility, and correct the parameterization usage in the other thrust allocator tests such that we actually check the MRs we're parameterizing over. - Closes rapidsai#1527
Previously, the user had to arrange that the device active when a thrust_allocator object was created was also active when allocate and deallocate was called. This is hard to manage if exceptions are thrown. Instead, save the active device on construction and ensure that it is active when calling deallocate and deallocate. This means that device_vector is safe to destruct with RAII semantics in a multi-device setting. Add tests of this facility, and correct the parameterization usage in the other thrust allocator tests such that we actually check the MRs we're parameterizing over. - Closes #1527 Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - Rong Ou (https://github.com/rongou) - Mark Harris (https://github.com/harrism) URL: #1533
Is your feature request related to a problem? Please describe.
Since #1370,
device_buffer
is safe to use in a multi-device setting wrt active devices when the destructor runs. While it was always possible (and relatively straightforward) to arrange for the active device to be correct in scenarios where no exceptions occurred, when there are exceptions setting the correct device for destruction was much more complicated.We therefore added the
cuda_set_device_raii
helper object and stored the active device id in thedevice_buffer
to ensure that the correct device is always active when calling allocate/deallocate functions.In contrast, since
device_vector
is just an alias forthrust::device_vector
, it still suffers from the old issue: the user must manually arrange that the correct device is active for the dtor.Describe the solution you'd like
#1523 documents this restriction, but it would be good if we could lift it. One way would be to store the active device in the thrust allocator wrapper that we use to interface RMM's memory resources with the thrust allocator model.
We would then use
cuda_set_device_raii
in all the allocate/deallocate functions.This was discounted as an approach in #1370 since it produces more device switches than necessary in some circumstances (pushing the device switching as far out as possible was preferred), so there would be some overhead compared to use of
device_buffer
(though hopefully small). And we note that sincedevice_vector
isn't stream ordered there are other disadvantages to using it, so the small performance cost is probably not that terminal.Describe alternatives you've considered
Maintain status quo, and eventually deprecate and then remove
device_vector
, since it is not stream-ordered anyway and we are trying to move away from that model.The text was updated successfully, but these errors were encountered: