Commit 35dcab5
authored
[C#] Implement missing APIs (#26101)
This pull request adds new APIs and updates existing ones to improve
memory and device information handling in the ONNX Runtime C# bindings.
The most significant changes introduce methods for fetching memory info
and device info for session inputs/outputs, and add support for shared
allocators and synchronization streams. There are also several updates
and renamings for LoraAdapter delegates and related APIs.
### Memory and Device Info APIs
* Added `GetMemoryInfosForInputs`, `GetMemoryInfosForOutputs`, and
`GetEpDeviceForInputs` methods to `InferenceSession.shared.cs` to fetch
memory info and device info for session inputs/outputs. These methods
utilize new native delegates for retrieving memory and device
information.
* Introduced native delegates in `NativeMethods.shared.cs` for
`OrtSessionGetMemoryInfoForInputs`, `OrtSessionGetMemoryInfoForOutputs`,
and `OrtSessionGetEpDeviceForInputs`, and wired them up in the static
constructor.
[[1]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73R530-R532)
[[2]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73R1312-R1335)
### Shared Allocator and Synchronization Stream Support
* Added delegates and static fields for creating, getting, and releasing
shared allocators, as well as for creating and managing synchronization
streams (`OrtCreateSharedAllocator`, `OrtGetSharedAllocator`,
`OrtReleaseSharedAllocator`, `OrtCreateSyncStreamForEpDevice`,
`OrtSyncStream_GetHandle`, `OrtReleaseSyncStream`).
* Added delegate for copying tensors (`OrtCopyTensors`).
### LoraAdapter API Updates
* Renamed LoraAdapter-related delegates to use the `Ort` prefix
(`OrtCreateLoraAdapter`, `OrtCreateLoraAdapterFromArray`,
`OrtReleaseLoraAdapter`) and updated their usage throughout the
codebase.
[[1]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73L699-R710)
[[2]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73L1561-R1672)
[[3]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73L1578-R1695)
### MemoryInfo Enhancements
* Added new delegates for creating memory info with more parameters
(`OrtCreateMemoryInfoV2`), and for querying device memory type and
vendor ID (`OrtMemoryInfoGetDeviceMemType`, `OrtMemoryInfoGetVendorId`).
[[1]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73R594-R596)
[[2]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73R1804-R1817)
[[3]](diffhunk://#diff-f9f2aaafc076365917de8ab96628da427d9dd0fd6a214fb9c266733f90d6fc73R1866-R1877)
### Minor API Documentation Update
* Clarified the lifetime of allocators in the documentation, noting they
can be explicitly unregistered.### Description
<!-- Describe your changes. -->
### 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. -->1 parent ad32f42 commit 35dcab5
File tree
14 files changed
+981
-221
lines changed- csharp
- src/Microsoft.ML.OnnxRuntime
- test
- Microsoft.ML.OnnxRuntime.Tests.Common
- Microsoft.ML.OnnxRuntime.Tests.NetCoreApp
- onnxruntime
- python
- test/python
14 files changed
+981
-221
lines changedLines changed: 76 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
217 | 293 | | |
218 | 294 | | |
219 | 295 | | |
| |||
Lines changed: 230 additions & 57 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | 376 | | |
380 | 377 | | |
381 | 378 | | |
382 | 379 | | |
383 | | - | |
384 | | - | |
| 380 | + | |
| 381 | + | |
385 | 382 | | |
386 | | - | |
| 383 | + | |
387 | 384 | | |
388 | 385 | | |
389 | | - | |
| 386 | + | |
390 | 387 | | |
391 | 388 | | |
392 | | - | |
| 389 | + | |
| 390 | + | |
393 | 391 | | |
394 | 392 | | |
395 | 393 | | |
| |||
Lines changed: 71 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
31 | 54 | | |
32 | 55 | | |
33 | 56 | | |
| |||
103 | 126 | | |
104 | 127 | | |
105 | 128 | | |
106 | | - | |
| 129 | + | |
| 130 | + | |
107 | 131 | | |
108 | 132 | | |
109 | 133 | | |
| |||
203 | 227 | | |
204 | 228 | | |
205 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
206 | 250 | | |
207 | 251 | | |
208 | 252 | | |
| |||
252 | 296 | | |
253 | 297 | | |
254 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
255 | 317 | | |
256 | 318 | | |
257 | 319 | | |
| |||
493 | 555 | | |
494 | 556 | | |
495 | 557 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | 558 | | |
503 | 559 | | |
504 | 560 | | |
| |||
560 | 616 | | |
561 | 617 | | |
562 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
563 | 627 | | |
564 | 628 | | |
565 | 629 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
333 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
334 | 337 | | |
335 | 338 | | |
336 | 339 | | |
337 | 340 | | |
338 | 341 | | |
339 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
340 | 441 | | |
341 | 442 | | |
342 | 443 | | |
| |||
477 | 578 | | |
478 | 579 | | |
479 | 580 | | |
480 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
481 | 612 | | |
482 | 613 | | |
483 | 614 | | |
| |||
0 commit comments