Conversation
nathanielsimard
left a comment
There was a problem hiding this comment.
The PR is good overall, but I have to think if it would be better to have a user managed memory pool instead. So all memory handles/bindings would be the same, but the underlying storage would be user managed. We already have different memory pools for different usage, so that could also work. Do you have an opinion about this?
I think either approach works, but the pool approach has the benefit that bindings and handles are simple and don't need branching whenever they're used. Let me give it a shot and see how it looks. |
|
Yup, I think the pool version ends up being cleaner! One thing to note: I made it take ownership of the buffer since that's what the pool kind of leans toward with its |
| pub struct UserManagedPool { | ||
| slices: HashMap<SliceId, Slice>, | ||
| } |
There was a problem hiding this comment.
I think I would also allow manually deallocating a buffer on the user managed pool. That could be a lot faster than calling cleanup on all memory pools. It would be another way to dealloc a buffer, with fined grain control instead of relying on a "GC" like cleanup. Cleanup is not called often, since most of our pools don't need to deallocate, pretty much only when switching models to reset the memory pools allocations.
There was a problem hiding this comment.
True, I added an unregister API to allow this to let the caller either use or drop the underlying buffer.
f3721db to
c7c14b0
Compare
# Conflicts: # crates/cubecl-wgpu/src/runtime.rs
f88e78a to
ea4d000
Compare
This PR allows registering external buffers with CubeCL, which is very useful as it enables zero-copy transfer. It internally uses a
BindingMemoryenum to distinguish external vs managed buffers as suggested in #291. I tried to keep this PR as minimal and non-invasive as possible - DLPack integration and such is left for future work.Fixes #291
Validate your PR with burn.
It is important that you make sure that you don't introduce any bugs in burn.
Instructions