Commit 1bbce15
[DLPack] C Functions for DLPack Speed Exchange and Stream Handling (pytorch#165483)
## Addressed Issue
Issue pytorch#162845
## Summary of Changes
This PR introduces a unified `DLPackExchangeAPI` struct as described in proposal [175](dmlc/dlpack#175). This new convention replaces the previous mechanism of separate function pointers, and aligns with the latest DLPack standard as shown in PR [174](dmlc/dlpack#174).
Specifically, the new `DLPackExchangeAPI` struct is exposed as `torch.Tensor.__c_dlpack_exchange_api__`, which stores and exposes the following function pointers:
* `managed_tensor_allocator`
* `managed_tensor_from_py_object_no_sync`
* `managed_tensor_to_py_object_no_sync`
* `dltensor_from_py_object_no_sync`
* `current_work_stream`
Within the new `DLPackExchangeAPI` struct, the new `current_work_stream` function pointer allows more robust and integrated querying of the current device stream (e.g., CUDA stream) during DLPack tensor exchanges. All the conversion from/to DLPack has been updated to `_no_sync`, meaning you should use `current_work_stream` to explicitly handle stream synchronization. It also includes a non-owning DLTensor conversion `dltensor_from_py_object_no_sync` to avoid unnecessary reference counting.
Following this change, the `dlpack.h` has been updated to the latest DLPack.
Unit tests are added using `torch.utils.cpp_extension.load_inline` to avoid GIL release issues
when calling `THPVariable_Wrap`.
Pull Request resolved: pytorch#165483
Approved by: https://github.com/tqchen, https://github.com/albanD1 parent 3089c80 commit 1bbce15
File tree
7 files changed
+666
-12
lines changed- aten/src/ATen
- test
- torch
- _C
- csrc
7 files changed
+666
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| |||
437 | 440 | | |
438 | 441 | | |
439 | 442 | | |
440 | | - | |
| 443 | + | |
| 444 | + | |
441 | 445 | | |
442 | 446 | | |
443 | 447 | | |
| |||
465 | 469 | | |
466 | 470 | | |
467 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
468 | 487 | | |
469 | 488 | | |
470 | 489 | | |
| |||
489 | 508 | | |
490 | 509 | | |
491 | 510 | | |
492 | | - | |
| 511 | + | |
493 | 512 | | |
494 | 513 | | |
495 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
| |||
0 commit comments