Skip to content

asarray supports sequence of arrays from multiple devices #1151

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

Conversation

oleksandr-pavlyk
Copy link
Contributor

Added support for asarray to create arrays from sequences of usm_ndarray objects allocated on different devices, and other Python sequences or numpy arrays.

In [1]: import dpctl, dpctl.tensor as dpt

In [2]: m = dpt.zeros((2, 4), dtype="i2", device="cpu")

In [3]: w = dpt.full(4, -1, device="opencl:gpu")

In [4]: res = dpt.asarray([m, [w, [0,] * 4 ]], dtype="f4", device="cpu")

In [5]: res
Out[5]:
usm_ndarray([[[ 0.,  0.,  0.,  0.],
              [ 0.,  0.,  0.,  0.]],

             [[-1., -1., -1., -1.],
              [ 0.,  0.,  0.,  0.]]], dtype=float32)

In [6]: res.device
Out[6]: Device(opencl:cpu:0)
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • If this PR is a work in progress, are you opening the PR as a draft?

```
In [1]: import dpctl, dpctl.tensor as dpt

In [2]: m = dpt.zeros((2, 4), dtype="i2", device="cpu")

In [3]: w = dpt.full(4, -1, device="opencl:gpu")

In [4]: res = dpt.asarray([m, [w, [0,] * 4 ]], dtype="f4", device="cpu")

In [5]: res
Out[5]:
usm_ndarray([[[ 0.,  0.,  0.,  0.],
              [ 0.,  0.,  0.,  0.]],
             [[-1., -1., -1., -1.],
	      [ 0.,  0.,  0.,  0.]]], dtype=float32)

In [6]: res.device
Out[6]: Device(opencl:cpu:0)
```

This usage requires user to specify sycl_queue or device keyword to
indicate where the result is created, or ExecitionPlacementError is
raised.
@coveralls
Copy link
Collaborator

coveralls commented Mar 31, 2023

Coverage Status

Coverage: 82.947% (+0.09%) from 82.854% when pulling ce5425b on as-type-supports-sequence-of-arrays-from-multiple-devices into d945d95 on master.

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_65 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

@github-actions
Copy link

Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_66 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

```
import dpnp, numpy, dpctl, dpctl.tensor as dpt
w = dpt.full(4, -1, device="opencl:gpu")
res = dpt.asarray([w, range(4)], dtype="f4")   # now correctly infers where to allocate output array
```

```
import dpctl, dpctl.tensor as dpt
m = dpt.zeros((2, 4), dtype="i2", device="cpu")
w = dpt.full(4, -1, device="opencl:gpu")

res = dpt.asarray([m, [w, range(4)], dtype="f4", device="cpu")
```
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_72 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

@oleksandr-pavlyk oleksandr-pavlyk merged commit 2a3558c into master Apr 5, 2023
@github-actions
Copy link

github-actions bot commented Apr 5, 2023

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

@github-actions
Copy link

github-actions bot commented Apr 5, 2023

Array API standard conformance tests for dpctl=0.14.3dev0=py310h76be34b_74 ran successfully.
Passed: 46
Failed: 788
Skipped: 280

@oleksandr-pavlyk oleksandr-pavlyk deleted the as-type-supports-sequence-of-arrays-from-multiple-devices branch April 5, 2023 17:19
@oleksandr-pavlyk oleksandr-pavlyk changed the title As type supports sequence of arrays from multiple devices asarray supports sequence of arrays from multiple devices Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants