Commit 787f80e
committed
tensor.asarray support for objects with __usm_ndarray__ attribute added
`asarray` supports objects that implement `__sycl_usm_array_interface__`.
It can create a view into USM allocation owned by input object, hence maintains
a reference to it.
Asynchronous deallocation of such objects in dpctl.tensor functions require
manipulating Python object reference counters, and hold GIL. This is a source
of dead-locks, and affects performance.
This PR adds support for ingesting Python objects that implement __usm_ndarray__
attribute (property) that returns dpt.usm_ndarray object with such a view directly.
It is trivial for `dpnp.ndarray` to implement such a property, e.g,.
```
@Property
def __usm_ndarray__(self):
return self._array_obj
```
With this definition, `dpt.asarray(dpnp_array)` will recognize that the underlying
USM allocation is managed by the smart pointer, and asynchronous deallocation will
not involve Python objects, avoiding dead-locks and improving performance.1 parent 9f8f90b commit 787f80e
1 file changed
+30
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
306 | 310 | | |
307 | 311 | | |
308 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
309 | 318 | | |
310 | 319 | | |
311 | 320 | | |
| |||
330 | 339 | | |
331 | 340 | | |
332 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
333 | 347 | | |
334 | 348 | | |
335 | 349 | | |
| |||
361 | 375 | | |
362 | 376 | | |
363 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
364 | 383 | | |
365 | 384 | | |
366 | 385 | | |
| |||
564 | 583 | | |
565 | 584 | | |
566 | 585 | | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
567 | 597 | | |
568 | 598 | | |
569 | 599 | | |
| |||
0 commit comments