Commit abc63e8
authored
Implement new Python APIs (#25999)
### Description
<!-- Describe your changes. -->
This pull request introduces several enhancements to ONNX Runtime's
Python and C++ APIs, focusing on improved device and memory information
handling, synchronization stream support, and tensor copy functionality.
It adds new Python bindings for device/memory types, exposes more
detailed session input/output metadata, and provides a Python-accessible
tensor copy API. The changes also refactor and extend the C++ API for
better stream and memory info management.
Key changes include:
### Device and Memory Information Enhancements
* Added Python bindings for `OrtMemoryInfoDeviceType`,
`OrtDeviceMemoryType`, and expanded `OrtDevice` to expose the memory
type via a new `mem_type` method. The `OrtMemoryInfo` Python class now
supports both legacy and new V2 constructors and exposes additional
properties such as device memory type and vendor ID.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1801-R1810)
[[2]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1839)
[[3]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eL1941-R2005)
* Extended the Python `InferenceSession` object to provide access to
input/output `OrtMemoryInfo` and `OrtEpDevice` objects through new
properties and methods.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR2702-R2729)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR202-R213)
[[3]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR591-R593)
[[4]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR607-R609)
### Synchronization Stream and Execution Provider Device Support
* Introduced Python bindings for `OrtSyncStream`, including creation via
`OrtEpDevice.create_sync_stream()` and retrieval of device-specific
`OrtMemoryInfo` via `OrtEpDevice.memory_info()`.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1890-R1938)
[[2]](diffhunk://#diff-44e70fbe60cba71c94f1a46ec2b1facaa8e9475232dad6df5ecbea301e76d475R34-R44)
* Refactored the C++ API to generalize `SyncStream` handling, allowing
for unowned streams and improved type safety.
[[1]](diffhunk://#diff-17f64e8b38fcdcd25e90abcabeec4b420956b15fe63868a5d0b270c376bde209L1066-R1084)
[[2]](diffhunk://#diff-cc93f5f9d8078d3d3af14c9bb4c0c59e25a99f3ec75d7772ea20111ed7eb6ddeL672-R677)
### Tensor Copy Functionality
* Added a new Python-level `copy_tensors` function and corresponding C++
binding, enabling efficient copying of tensor data between `OrtValue`
objects, optionally using a synchronization stream.
[[1]](diffhunk://#diff-c46fc0e05521f706449c04aed599ac0229012c007a78b584519e71a57601d63eR1588-R1599)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1155-R1163)
[[3]](diffhunk://#diff-44e70fbe60cba71c94f1a46ec2b1facaa8e9475232dad6df5ecbea301e76d475R84)
### Miscellaneous Improvements and Fixes
* Changed the return type of the `OrtValue.data_ptr` method in the
Python binding from `int64_t` to `uintptr_t` for better cross-platform
compatibility.
[[1]](diffhunk://#diff-666c9002698d1bbd4215237231e5be98d7b33e5054f018dce952407027bd0473L336-R336)
[[2]](diffhunk://#diff-666c9002698d1bbd4215237231e5be98d7b33e5054f018dce952407027bd0473L347-R347)
* Minor improvements to error messages and device type handling in the
Python API (e.g., for `OrtDevice`).
[[1]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1176)
[[2]](diffhunk://#diff-f0e8ba8cb8cb07b51b3be675bf62cec07e2eae1461341ce5801d33a57c8f57fdR1219-R1221)
* Included necessary C++ includes for plugin stream support.
These changes collectively improve the flexibility and introspection
capabilities of ONNX Runtime's device, memory, and execution provider
interfaces, and make advanced features available to Python users.
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Depends on: #260211 parent b72dd15 commit abc63e8
File tree
8 files changed
+276
-41
lines changed- include/onnxruntime/core/session
- onnxruntime
- python
- test/python
8 files changed
+276
-41
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1063 | 1063 | | |
1064 | 1064 | | |
1065 | 1065 | | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
1070 | 1074 | | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1071 | 1085 | | |
1072 | 1086 | | |
1073 | 1087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
669 | 669 | | |
670 | 670 | | |
671 | 671 | | |
672 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
673 | 675 | | |
674 | 676 | | |
| 677 | + | |
675 | 678 | | |
676 | 679 | | |
677 | 680 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
202 | 214 | | |
203 | 215 | | |
204 | 216 | | |
| |||
576 | 588 | | |
577 | 589 | | |
578 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
579 | 594 | | |
580 | 595 | | |
581 | 596 | | |
| |||
589 | 604 | | |
590 | 605 | | |
591 | 606 | | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
592 | 610 | | |
593 | 611 | | |
594 | 612 | | |
| |||
1134 | 1152 | | |
1135 | 1153 | | |
1136 | 1154 | | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
1137 | 1164 | | |
1138 | 1165 | | |
1139 | 1166 | | |
| |||
1146 | 1173 | | |
1147 | 1174 | | |
1148 | 1175 | | |
| 1176 | + | |
1149 | 1177 | | |
1150 | 1178 | | |
1151 | 1179 | | |
| |||
1188 | 1216 | | |
1189 | 1217 | | |
1190 | 1218 | | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1191 | 1222 | | |
1192 | 1223 | | |
1193 | 1224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
| 336 | + | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
| 347 | + | |
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
1587 | 1588 | | |
1588 | 1589 | | |
1589 | 1590 | | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1590 | 1603 | | |
1591 | 1604 | | |
1592 | 1605 | | |
| |||
1788 | 1801 | | |
1789 | 1802 | | |
1790 | 1803 | | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
1791 | 1814 | | |
1792 | 1815 | | |
1793 | 1816 | | |
| |||
1816 | 1839 | | |
1817 | 1840 | | |
1818 | 1841 | | |
| 1842 | + | |
1819 | 1843 | | |
1820 | 1844 | | |
1821 | 1845 | | |
| |||
1866 | 1890 | | |
1867 | 1891 | | |
1868 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
1869 | 1896 | | |
1870 | 1897 | | |
1871 | 1898 | | |
1872 | 1899 | | |
1873 | 1900 | | |
1874 | | - | |
| 1901 | + | |
1875 | 1902 | | |
1876 | 1903 | | |
1877 | 1904 | | |
1878 | | - | |
| 1905 | + | |
1879 | 1906 | | |
1880 | 1907 | | |
1881 | 1908 | | |
1882 | | - | |
| 1909 | + | |
1883 | 1910 | | |
1884 | 1911 | | |
1885 | 1912 | | |
1886 | 1913 | | |
1887 | 1914 | | |
1888 | | - | |
| 1915 | + | |
1889 | 1916 | | |
1890 | 1917 | | |
1891 | 1918 | | |
1892 | 1919 | | |
1893 | 1920 | | |
1894 | | - | |
| 1921 | + | |
1895 | 1922 | | |
1896 | 1923 | | |
1897 | 1924 | | |
1898 | | - | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
1899 | 1942 | | |
1900 | 1943 | | |
1901 | 1944 | | |
| |||
1941 | 1984 | | |
1942 | 1985 | | |
1943 | 1986 | | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
1963 | 2009 | | |
1964 | 2010 | | |
1965 | 2011 | | |
| |||
2699 | 2745 | | |
2700 | 2746 | | |
2701 | 2747 | | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
2702 | 2775 | | |
2703 | 2776 | | |
2704 | 2777 | | |
| |||
0 commit comments