-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add usm memory constructor from existing allocation #1782
Add usm memory constructor from existing allocation #1782
Conversation
Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞 |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_238 ran successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have small style comments which can be ignored.
examples/pybind11/external_usm_allocation/external_usm_allocation/_usm_alloc_example.cpp
Show resolved
Hide resolved
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_239 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_240 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_254 ran successfully. |
usm_memory( void *usm_ptr, size_t nbytes, sycl::queue &q, std::shared_ptr<void> shptr) usm_ptr: Pointer to USM allocation nbytes: is the size of allocation in bytes q : sycl::queue associated with this allocation in Python. shptr: Smart pointer with custom deleter that deallocates the USM allocation. Implementation notes: Use unique_ptr to manage lifetime of new copy of sycl::queue, Delegate newly created Python object memory management to a unique_ptr to ensure it gets properly handled in case an exception is thrown.
The example now also demonstration zero-copy creation of MemoryUSMDevice Python object from allocation created and populated in C++. Use lambda as a deleter per @AlexanderKalistratov suggestion
0b4032a
to
1ef63da
Compare
@AlexanderKalistratov @ndgrigorian I have applied suggested changes, rebased and squashed commits. This is ready for next round of reviewing. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_261 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_257 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_258 ran successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I ran the example on CUDA as well.
This PR add
dpctl::memory::usm_memory
constructor to create Python memory object from natively made allocation.The signature is
where
usm_ptr
is the pointer to USM-allocation,nbytes
the size of allocation in bytes,q
the queue associated with the Python memory object, andowner
is the shared pointer whose destructor frees USM allocation via its custom deleter argument.Example of using such constructor is added to
examples/pybind11/external_usm_allocation
extension.