-
Notifications
You must be signed in to change notification settings - Fork 394
feat: TorchTRT Annotation Layer for Cuda generated kernels #4199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bowang007
wants to merge
3
commits into
main
Choose a base branch
from
tta_cuda_plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| .. _torch_tensorrt_annotation_py: | ||
|
|
||
| torch_tensorrt.annotation | ||
| ========================== | ||
|
|
||
| .. currentmodule:: torch_tensorrt.annotation | ||
|
|
||
| .. automodule:: torch_tensorrt.annotation | ||
|
|
||
| .. note:: | ||
|
|
||
| This module is **experimental**. It requires ``cuda-python`` at runtime | ||
| and TensorRT ``>=10.7.0`` (and not ``10.14.x``) for Quick Deployable | ||
| Plugin (QDP) support. Install ``cuda-python`` with ``pip install | ||
| cuda-python``. | ||
|
|
||
| Overview | ||
| -------- | ||
|
|
||
| The ``annotation`` module registers NVRTC-compiled CUDA C++ kernels as | ||
| TensorRT Quick Deployable Plugins with full Ahead-of-Time (AOT) | ||
| compilation support. It offers two entry points that trade | ||
| declarativeness for flexibility — start with :func:`auto_cuda_kernel_plugin` and | ||
| drop down to :func:`manual_cuda_kernel_plugin` only when your kernel falls outside | ||
| the declarative DSL: | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
| :widths: 28 36 36 | ||
|
|
||
| * - Entry point | ||
| - What you provide | ||
| - What you get for free | ||
| * - :func:`auto_cuda_kernel_plugin` | ||
| - A :class:`KernelSpec` dataclass (source, inputs, outputs, extras, | ||
| geometry) | ||
| - Meta / eager / AOT functions and the PyTorch schema — all derived | ||
| * - :func:`manual_cuda_kernel_plugin` | ||
| - ``aot_fn`` + ``eager_fn`` + a meta function decorated with the | ||
| one-shot decorator | ||
| - PyTorch op + TRT plugin + converter, registered together | ||
|
|
||
| For unary-pointwise kernels, :func:`pointwise_aot` and | ||
| :func:`pointwise_eager` produce the two callables so users can plug them | ||
| directly into :func:`manual_cuda_kernel_plugin`. | ||
|
|
||
| Declarative entry point | ||
| ----------------------- | ||
|
|
||
| .. autofunction:: auto_cuda_kernel_plugin | ||
|
|
||
| KernelSpec DSL | ||
| ^^^^^^^^^^^^^^ | ||
|
|
||
| .. autoclass:: KernelSpec | ||
| :members: | ||
|
|
||
| .. autoclass:: InputDecl | ||
| :members: | ||
|
|
||
| .. autoclass:: ScalarInput | ||
| :members: | ||
|
|
||
| .. autoclass:: OutputDecl | ||
| :members: | ||
|
|
||
| Shape relations | ||
| """"""""""""""" | ||
|
|
||
| .. autoclass:: SameAs | ||
| :members: | ||
|
|
||
| .. autoclass:: ReduceDims | ||
| :members: | ||
|
|
||
| Extra scalar args | ||
| """"""""""""""""" | ||
|
|
||
| Extras are passed to the kernel between the input and output pointer | ||
| lists in :class:`KernelSpec` order. | ||
|
|
||
| .. autoclass:: Numel | ||
| :members: | ||
|
|
||
| .. autoclass:: DimSize | ||
| :members: | ||
|
|
||
| Launch geometry | ||
| """"""""""""""" | ||
|
|
||
| .. autoclass:: Elementwise | ||
| :members: | ||
|
|
||
| .. autoclass:: Reduction | ||
| :members: | ||
|
|
||
| .. autoclass:: Custom | ||
| :members: | ||
|
|
||
| One-shot hand-written entry point | ||
| --------------------------------- | ||
|
|
||
| .. autofunction:: manual_cuda_kernel_plugin | ||
|
|
||
| Lower-level building blocks | ||
| --------------------------- | ||
|
|
||
| .. autofunction:: cuda_python | ||
|
|
||
| .. autofunction:: custom_plugin | ||
|
|
||
| Spec class | ||
| ^^^^^^^^^^ | ||
|
|
||
| .. autoclass:: CudaPythonSpec | ||
| :members: | ||
|
|
||
| Pointwise helpers | ||
| ----------------- | ||
|
|
||
| .. autofunction:: pointwise_aot | ||
|
|
||
| .. autofunction:: pointwise_eager | ||
|
|
||
| Kernel signature convention | ||
| --------------------------- | ||
|
|
||
| All entry points assume the ``__global__`` kernel takes its arguments in | ||
| the fixed order:: | ||
|
|
||
| (input_ptrs..., extras..., output_ptrs...) | ||
|
|
||
| Pointers are ``void*`` cast to the appropriate element type. Extras | ||
| follow the order declared in :attr:`KernelSpec.extras` for the | ||
| declarative path, or the order your ``aot_fn`` builds for the manual | ||
| path. | ||
|
|
||
| Error behavior | ||
| -------------- | ||
|
|
||
| :func:`auto_cuda_kernel_plugin` validates the :class:`KernelSpec` at decorator | ||
| time and raises :class:`ValueError` for the common authoring mistakes: | ||
|
|
||
| - Empty or duplicate-named ``inputs`` / ``outputs``. | ||
| - ``ReduceDims(input_idx=N)`` or ``SameAs(input_idx=N)`` where ``N`` is | ||
| out of range. | ||
| - ``Numel`` / ``DimSize`` referencing a name that is not an input. | ||
| - ``dtype_from`` pointing at an unknown input. | ||
| - ``Elementwise(layout='flat')`` with a multi-dimensional block tuple. | ||
| - Invalid block sizes, ``block_size`` in :class:`Reduction`, or a | ||
| non-callable :attr:`Custom.fn`. | ||
|
|
||
| Shape-dependent errors — for example | ||
| ``Elementwise(layout='nd', block=(16, 16))`` invoked against a 1-D | ||
| output — are raised at launch time in a clear ``ValueError`` because | ||
| the offending ranks are only known when concrete tensors arrive. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ Core | |
| dynamo | ||
| logging | ||
| runtime | ||
| annotation | ||
| ../cli/torchtrtc | ||
| ../indices/supported_ops | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be called torch_tensorrt.kernels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @narendasan should we just deprecate the naming related to
annotation? I'm a little bit confused here since thisannotationis really opaque to the users and there is noannotationmodule right now