-
Notifications
You must be signed in to change notification settings - Fork 30
Enhance from_dlpack to support imported kDLCPU data to kDLOneAPI #1789
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
Enhance from_dlpack to support imported kDLCPU data to kDLOneAPI #1789
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_246 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_248 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_250 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_251 ran successfully. |
@oleksandr-pavlyk For example:
This may not really be a problem, because the |
Thanks for the example @ndgrigorian. I have pushed the fix, by replacing |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_291 ran successfully. |
d8fa3b2
to
25f8afb
Compare
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_295 ran successfully. |
@ndgrigorian Once this is ready to go, I intend to squash all changes into few commits. Please rereview |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_296 ran successfully. |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_298 ran successfully. |
For arr that supports DLPack, version (1, 0), or legacy, support ``` from_dlpack(arr, device=target_dev) ``` where target_dev is `(kDLCPU, 0)` for transfer to host, or a value recognized by device keywords in dpctl.tensor for other functions, or `(kDLOneAPI, dev_id)`. To support transfer via host, `arr` must support `__dlpack__(max_version=(1,0), dl_device=(1, 0))`. For array objects with legacy `__dlpack__` support only, supported inputs are those residing on kDLCPU device, or those from kDLOneAPI device only. --- This is a combination of 17 commits squashed into one: Combine two validation checks into one, improving coverage Only fall-back to __dlpack__() if requested device does not change Simplify branching, only fall-back to no-arg call to __dlpack__ is dl_device is None or same as reported for the input Changed from_dlpack to copy via host is needed This enables dpt.from_dlpack(numpy_array, device="opencl:cpu") Add a test to exercise copy via host Handle possibilities for TypeError and BufferError These may be hard to test Change exception raised by __dlpack__ if dl_device is unsupported It used to raise NotImplementedError, not raises BufferError Add case of dlpack test to expand coverage Removed comment, add NotImplementedError to the except clause To ensure same validation across branches, compute host_blob by roundtripping it through dlpack Test from_dlpack on numpy input with strides not multiple of elementsize Refined from_dlpack docstrings, reorged impl of from_dlpack Used try/except/else/finally to avoid raising an exception when another one is in flight (confusing UX). device keyword is only allowed to be (kDLCPU, 0) or (kDLOneAPI, num). Device keyword value is used to create output array, rather than device_id deduced from it. Adjusted test per change in implementation Expand applicability of fall-back behavior When `from_dlpack(arr, device=dev)` is called, for `arr` object that supports legacy DLPack interface (max_version, dl_device, copy are not supported), we now support arr being device on host, that is (kDLCPU, 0), and (kDLOneAPI, different_device_id). Support for this last case is being added in this commit, as per review comment. Add symmetric support for containers with legacy DLPack support For legacy containers, support device=(kDLCPU, 0) as well as oneAPI device. Add tests for importing generic legacy and generic modern containers Fix typos in comments Add test for legacy container holding numpy's array.
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_300 ran successfully. |
759a27e
to
2661f51
Compare
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_284 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.
This LGTM, thank you @oleksandr-pavlyk !
9a17afc
into
feature/dlpack-kdlcpu-support
This PR contributes to gh-1781 to support importing objects resident on other devices to oneAPI devices by copying via host.