Commit 54f9ccd
committed
refactor(runtime): extract TRTRuntimeConfig, address PR review
Address the structural PR feedback by extracting TensorRT-RTX-specific
IRuntimeConfig state into its own type and collapsing the per-feature
appliers that previously scattered `#ifdef TRT_MAJOR_RTX` through
TRTEngine.
What
- New core/runtime/TRTRuntimeConfig.{h,cpp} owns the IRuntimeConfig
shared_ptr plus (on TRT-RTX) the IRuntimeCache, runtime-cache path,
dynamic shapes kernel strategy, CUDA graph strategy, and the
rtx_native_cudagraphs_disabled one-shot flag. All per-feature
appliers live there as public members and are no-ops on non-RTX
builds, keeping the only `#ifdef TRT_MAJOR_RTX` scatter contained
in this new file.
- Strategy fields are now strongly-typed enums
(`DynamicShapesKernelStrategy`, `CudaGraphStrategyOption`) with
matching `to_string`/`to_int` helpers, validated at engine
construction via `to_dynamic_shapes_kernel_strategy` / `to_cuda_
graph_strategy_option` rather than raw int ranges.
- `TRTEngine::recreate_execution_context` is now backend-agnostic:
it calls `runtime_cfg.ensure_initialized`, applies the allocation
strategy, and creates the execution context via
`createExecutionContext(IRuntimeConfig*)`. Both standard TensorRT
and TRT-RTX go through this uniform path; only the three RTX-only
setters (`setRuntimeCache`, `setDynamicShapesKernel
SpecializationStrategy`, `setCudaGraphStrategy`) stay behind an
`#ifdef TRT_MAJOR_RTX` guard inside the struct.
- `~TRTEngine` now wraps cleanup in try/catch and delegates cache
persistence to `TRTRuntimeConfig::save_runtime_cache_nothrow`, so
stack unwinding can no longer propagate a cache-save failure out
of the destructor.
- `save_runtime_cache_nothrow` uses `std::filesystem` + atomic
`tmp+rename` only; file locking is out of scope for this PR and
will be introduced in a follow-up once we pick a portable
mechanism.
- `is_monolithic_capturable` asserts `exec_ctx` is non-null; the
three RTX-only appliers `TORCHTRT_ASSERT` that `config` is live
before dereferencing.
- `disable_rtx_native_cudagraphs` persists the runtime cache before
flipping the strategy so any kernels compiled under the internal
capture survive to the next reload.
- `TRTEngine::to_str` now emits human-readable strategy names (via
`to_string(enum)`) instead of integer codes.
- New serialization indices (`RUNTIME_CACHE_PATH_IDX`, `DYNAMIC_
SHAPES_KERNEL_STRATEGY_IDX`, `CUDA_GRAPH_STRATEGY_IDX`) are now
`#ifdef TRT_MAJOR_RTX`-gated in runtime.h, register_jit_hooks.cpp,
the FlattenedState tuple, the serialize/deserialize constructors,
and `__obj_flatten__`. Standard TRT builds keep `SERIALIZATION_LEN
== 11` so engines serialized there do not carry RTX-only slots.
- Python `_TorchTensorRTModule` reads the RTX-only index accessors
and writes the RTX-only engine-info slots only when
`ENABLED_FEATURES.tensorrt_rtx` is true. Standard TRT users see
no new behavior at runtime.
- Deduplicated `_compiler.py` arguments after rebase on upstream
main where PR pytorch#4184 had already added
`dynamic_shapes_kernel_specialization_strategy`. Kept one copy of
each arg; `cuda_graph_strategy` is threaded through all three
compile() entry points.
Build + tests
- RTX build on A100 / L40S: libtorchtrt.so and libtorchtrt_
runtime.so link clean, no `#ifdef` diagnostics. Pre-commit checks
pass (clang-format, black, isort, ruff, mypy, typos, buildifier).
- All 35 runtime-cache/strategy tests pass; regression across
test_000_runtime_cache.py (Python runtime), test_002_cudagraphs_
cpp.py, test_005_dynamic_allocation.py is green.
Addresses review comments on PR pytorch#4202:
- Guarding of new IDX entries and Python accessors on
TRT_MAJOR_RTX / ENABLED_FEATURES.tensorrt_rtx.
- Encapsulation of RTX-specific state in a dedicated type with
enumerated strategies and transparent standard-TRT/RTX behavior.
- Destructor exception safety.
- Unification of the execution-context creation path via
IRuntimeConfig.
- Removal of file locking for runtime-cache persistence.
- Debug asserts before dereferencing the live IRuntimeConfig.
- Human-readable to_str output.
- save_runtime_cache invoked from disable_rtx_native_cudagraphs.1 parent 2b630e8 commit 54f9ccd
12 files changed
Lines changed: 434 additions & 278 deletions
File tree
- core/runtime
- py/torch_tensorrt/dynamo
- runtime
- tests/py/dynamo/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| 113 | + | |
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
124 | | - | |
125 | 128 | | |
| 129 | + | |
126 | 130 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | 14 | | |
22 | 15 | | |
23 | 16 | | |
| |||
102 | 95 | | |
103 | 96 | | |
104 | 97 | | |
105 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
106 | 101 | | |
107 | 102 | | |
108 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
| |||
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
134 | 125 | | |
135 | 126 | | |
136 | 127 | | |
| |||
288 | 279 | | |
289 | 280 | | |
290 | 281 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
297 | 289 | | |
298 | 290 | | |
299 | 291 | | |
| |||
453 | 445 | | |
454 | 446 | | |
455 | 447 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | 448 | | |
| 449 | + | |
462 | 450 | | |
463 | 451 | | |
464 | 452 | | |
| |||
502 | 490 | | |
503 | 491 | | |
504 | 492 | | |
505 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
506 | 496 | | |
507 | 497 | | |
508 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
509 | 501 | | |
510 | 502 | | |
511 | 503 | | |
| |||
530 | 522 | | |
531 | 523 | | |
532 | 524 | | |
533 | | - | |
534 | | - | |
535 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
536 | 531 | | |
537 | 532 | | |
538 | 533 | | |
| |||
553 | 548 | | |
554 | 549 | | |
555 | 550 | | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
| 551 | + | |
565 | 552 | | |
566 | 553 | | |
567 | 554 | | |
568 | | - | |
569 | | - | |
570 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
571 | 561 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | 562 | | |
581 | 563 | | |
582 | 564 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 565 | + | |
| 566 | + | |
592 | 567 | | |
593 | 568 | | |
594 | 569 | | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
| 570 | + | |
604 | 571 | | |
605 | 572 | | |
606 | 573 | | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | 574 | | |
734 | 575 | | |
735 | 576 | | |
0 commit comments