TensorRT 10.10 OSS Release (#4437)

Signed-off-by: Po-Wei Wang (Vincent) <poweiw@nvidia.com>
This commit is contained in:
Po-Wei (Vincent)
2025-05-09 15:21:00 -07:00
committed by GitHub
parent 9e0835ac8a
commit 665cfbe862
182 changed files with 1821 additions and 2854 deletions
+290 -10
View File
@@ -15,8 +15,274 @@
# limitations under the License.
#
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(PyTensorRT LANGUAGES CXX C)
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
project(TRTPyBinds LANGUAGES CXX)
option(TRT_BUILD_ENABLE_NEW_PYTHON_FLOW "Use new build logic based on the main CMake build." OFF)
if(MSVC)
set(DEFAULT_PY_EXT_PATH "${TOOLS_BASE}/win32")
else()
set(DEFAULT_PY_EXT_PATH "/externals")
endif()
set(TRT_BUILD_PYTHON_EXTERNALS_PATH ${DEFAULT_PY_EXT_PATH} CACHE PATH "Path to the parent folder of pybind11 and the many versioned python headers/libs.")
set(TRT_BUILD_PYTHON_PY_VERSIONS 3.8 3.9 3.10 3.11 3.12 3.13 CACHE STRING "The list of python versions to build bindings for.")
set(TRT_PYTHON_MODULE_NAMES
"tensorrt"
"tensorrt_lean"
"tensorrt_dispatch"
)
if (${TRT_BUILD_ENABLE_NEW_PYTHON_FLOW})
# The "main" tensorrt bindings depend on the parser, so if we aren't building it, we need to skip it.
if(NOT ${TRT_BUILD_ONNX_PARSER})
message(STATUS "Not building the tensorrt python bindings as the ONNX Parser was disabled.")
list(REMOVE_ITEM TRT_PYTHON_MODULE_NAMES "tensorrt")
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(
Python3
COMPONENTS Interpreter
REQUIRED
)
# Disable automatic python detection since we need to build bindings for many python versions in one go.
set(PYBIND11_NOPYTHON ON CACHE INTERNAL "")
add_subdirectory(${TRT_BUILD_PYTHON_EXTERNALS_PATH}/pybind11 ${CMAKE_CURRENT_BINARY_DIR}/externals/pybind11)
# Pybind11 would normally enable this by default, but does not do so under NOPYTHON mode, so we do it manually.
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
add_custom_target(tensorrt_python_bindings)
# Creates the binding library for the specified module and python version.
#
# \param moduleName The module name to create the bindings for. One of "tensorrt", "tensorrt_dispatch", or "tensorrt_lean".
# \param pyVersion The python version to create bindings for, i.e. "3.12".
function(createBindingLibrary moduleName pyVersion)
set(libName tensorrt_bindings_${moduleName}_${pyVersion})
add_library(${libName} MODULE)
# Set options unique to the "full" bindings.
# The subdirs will use the value of TRT_PYTHON_IS_FULL_BINDINGS to set sources appropriately.
if(${moduleName} STREQUAL "tensorrt")
target_compile_definitions(${libName} PRIVATE
tensorrt_EXPORTS=1
)
set(TRT_PYTHON_IS_FULL_BINDINGS ON)
else()
set(TRT_PYTHON_IS_FULL_BINDINGS OFF)
endif()
function(add_${libName}_source)
target_sources(${libName} PRIVATE ${ARGN})
endfunction()
# Create an indirect refernce to the add_${libName}_source function which can be called by the subdirectories.
# This allows each subdir to add files to the individual targets with unique binary dirs on each call.
set(ADD_SOURCES_FUNCTION add_${libName}_source)
set(SUBDIR_BINARY_DIR_PREFIX ${libName})
add_subdirectory(src ${SUBDIR_BINARY_DIR_PREFIX}/src)
target_link_libraries(${libName} PRIVATE
pybind11::headers
pybind11::opt_size
)
if(MSVC)
target_link_libraries(${libName} PRIVATE
pybind11::windows_extras
)
else()
# This allows us to use TRT libs shipped with standalone wheels.
target_link_options(${libName} PRIVATE "LINKER:-rpath=$ORIGIN:$ORIGIN/../${TENSORRT_MODULE}_libs)")
endif()
# Find the main python headers in the relevant python<ver> subfolder in the externals.
find_path(
PYTHON_INCLUDES Python.h
HINTS ${TRT_BUILD_PYTHON_EXTERNALS_PATH}/python${pyVersion}
PATH_SUFFIXES include
NO_CACHE
REQUIRED
NO_CMAKE_FIND_ROOT_PATH
)
# Most of the headers are in that path we just found, except "pyconfig.h", which is platform-specific
# and in a platform-specific directory with an inconsistent naming scheme.
# So... go hunt for that. It's "mostly" located at /externals/python<ver>/include/<triple>/python<ver>/
# Except on windows, where instead of <triple> it's just "win".
if(${TRT_BUILD_PLATFORM} STREQUAL ${TRT_PLATFORM_X86})
set(PYCONFIG_H_PATH "x86_64-linux-gnu/python${pyVersion}")
elseif(${TRT_BUILD_PLATFORM} STREQUAL ${TRT_PLATFORM_AARCH64})
set(PYCONFIG_H_PATH "aarch64-linux-gnu/python${pyVersion}")
elseif(${TRT_BUILD_PLATFORM} STREQUAL ${TRT_PLATFORM_WIN10})
set(PYCONFIG_H_PATH "win/python${pyVersion}")
else()
message(FATAL_ERROR "The current platform \"${TRT_BUILD_PLATFORM}\" cannot be used to build the TRT Python Bindings.")
endif()
find_path(
PYCONFIG_INCLUDE pyconfig.h
HINTS ${PYTHON_INCLUDES}/${PYCONFIG_H_PATH}
NO_CACHE
REQUIRED
NO_CMAKE_FIND_ROOT_PATH
)
# Add the python headers as SYSTEM headers to silence warnings.
target_include_directories(${libName} SYSTEM PRIVATE
${PYTHON_INCLUDES}
${PYCONFIG_INCLUDE}
)
target_include_directories(${libName} PRIVATE
"include"
"docstrings"
)
# Setup links against the TRT Libraries.
if(${moduleName} STREQUAL "tensorrt")
set(TRT_LIBS tensorrt nvonnxparser tensorrt_plugins)
elseif(${moduleName} STREQUAL "tensorrt_lean")
set(TRT_LIBS tensorrt_lean_runtime)
elseif(${moduleName} STREQUAL "tensorrt_dispatch")
set(TRT_LIBS tensorrt_dispatch_runtime)
else()
message(FATAL_ERROR "Unknown TensorRT module " ${moduleName})
endif()
find_package(CUDAToolkit REQUIRED)
target_link_libraries(${libName} PRIVATE
${TRT_LIBS}
$<COMPILE_ONLY:CUDA::cudart_static>
)
# Tell the files what module they are currently building.
target_compile_definitions(${libName} PRIVATE
TENSORRT_MODULE=${moduleName}
)
# Remove the `lib` prefix from the binding .so's and correct the output name.
set_target_properties(${libName}
PROPERTIES PREFIX ""
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${moduleName}_bindings-py${pyVersion}
OUTPUT_NAME ${moduleName}
)
add_dependencies(tensorrt_python_bindings ${libName})
# Setup some final MSVC-exclusive settings
if(MSVC)
# Prevent pybind11 from sharing resources with other, potentially ABI incompatible modules
# https://github.com/pybind/pybind11/issues/2898
add_definitions(-DPYBIND11_COMPILER_TYPE="_${PROJECT_NAME}_abi")
# The python lib is python<maj><minor>.lib, but pyVersion is <maj>.<minor>, so we need to remove the dot.
string(REPLACE "." "" pyVerStr ${pyVersion})
if(NOT TARGET python${pyVerStr})
# Windows needs an explicit link against the python library.
find_library(
PYTHON${pyVerStr}_LIBRARY_PATH python${pyVerStr}.lib
HINTS ${TRT_BUILD_PYTHON_EXTERNALS_PATH}/python${pyVersion}
PATH_SUFFIXES lib
REQUIRED
NO_CMAKE_FIND_ROOT_PATH
)
add_library(python${pyVerStr} STATIC IMPORTED)
set_target_properties(python${pyVerStr} PROPERTIES IMPORTED_LOCATION "${PYTHON${pyVerStr}_LIBRARY_PATH}")
endif()
target_link_libraries(${libName} PRIVATE python${pyVerStr})
endif()
endfunction()
# Processes one or more wheel templates file, replacing any markers with concrete information and
# copying the result into the per-python per-module build dir.
#
# \param moduleName The module name to create the bindings for. One of "tensorrt", "tensorrt_dispatch", or "tensorrt_lean".
# \param pyVersion The python version to create bindings for, i.e. "3.12".
# \param ARGN A list of file paths, relative to './packaging/bindings_wheel/tensorrt', of the file(s) to copy.
# \returns generatedWheelFiles A list containing paths to all generated files, which can be used to create a custom target.
function(processWheelTemplates moduleName pyVersion)
foreach(filePath IN LISTS ARGN)
set(outputDir ${CMAKE_CURRENT_BINARY_DIR}/${moduleName}_bindings-py${pyVersion}/$<CONFIG>)
set(outputFile ${outputDir}/${filePath})
add_custom_command(
OUTPUT ${outputFile}
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/process_wheel_template.py
--src-dir ${CMAKE_CURRENT_LIST_DIR}/packaging/bindings_wheel/tensorrt
--dst-dir ${outputDir}
--filepath ${filePath}
--trt-module ${moduleName}
--trt-py-version ${TensorRT_VERSION}
--cuda-version ${TRT_CUDA_VERSION}
--trt-version ${TensorRT_VERSION}
DEPENDS
scripts/process_wheel_template.py
${CMAKE_CURRENT_LIST_DIR}/packaging/bindings_wheel/tensorrt/${filePath}
VERBATIM)
list(APPEND generatedFiles ${outputFile})
endforeach()
set(generatedWheelFiles ${generatedFiles} PARENT_SCOPE)
endfunction()
add_custom_target(trt_python_wheel_files)
# Expands all template files for the bindings for the target module and python version.
# Each call to this function creates a new custom target, and makes trt_python_wheel_files depend on the new target.
#
# \param moduleName The module name to create the bindings for. One of "tensorrt", "tensorrt_dispatch", or "tensorrt_lean".
# \param pyVersion The python version to create bindings for, i.e. "3.12".
function(expandWheelTemplates moduleName pyVersion)
set(wheelTarget trt_wheel_files_${moduleName}_${pyVersion})
processWheelTemplates(${moduleName} ${pyVersion}
__init__.py
plugin/__init__.py
plugin/_autotune.py
plugin/_export.py
plugin/_lib.py
plugin/_plugin_class.py
plugin/_tensor.py
plugin/_top_level.py
plugin/_utils.py
plugin/_validate.py
)
add_custom_target(${wheelTarget} DEPENDS ${generatedWheelFiles})
add_dependencies(trt_python_wheel_files ${wheelTarget})
endfunction()
# Enumerate all the combinations and create the per-python per-module targets.
foreach(moduleName IN LISTS TRT_PYTHON_MODULE_NAMES)
foreach(pyVersion IN LISTS TRT_BUILD_PYTHON_PY_VERSIONS)
createBindingLibrary(${moduleName} ${pyVersion})
expandWheelTemplates(${moduleName} ${pyVersion})
# TODO: Add custom targets to run copy_standalone_libs.py and build the wheels.
# We should be able to generate a pyproject.toml from the current config and setup a custom command to build the wheel directly.
endforeach()
endforeach()
else() # TRT_BUILD_ENABLE_NEW_PYTHON_FLOW - old flow is below this line
# Sets variable to a value if variable is unset.
macro(set_ifndef var val)
@@ -59,11 +325,13 @@ set_ifndef(WIN_EXTERNALS ${EXT_PATH})
message(STATUS "WIN_EXTERNALS: ${WIN_EXTERNALS}")
# Convert to an absolute path.
set_ifndef(ONNX_INC_DIR ${TENSORRT_ROOT}/parsers/)
set_ifndef(ONNX_INC_DIR ${TENSORRT_ROOT}/parsers/onnx)
find_path(
PYBIND11_DIR pybind11/pybind11.h
HINTS ${EXT_PATH} ${WIN_EXTERNALS}
PATH_SUFFIXES pybind11/include)
PATH_SUFFIXES pybind11/include
REQUIRED
)
message(STATUS "ONNX_INC_DIR: ${ONNX_INC_DIR}")
message(STATUS "PYBIND11_DIR: ${PYBIND11_DIR}")
@@ -90,17 +358,23 @@ if(MSVC)
find_path(
PY_INCLUDE Python.h
HINTS ${WIN_EXTERNALS}/${PYTHON} ${EXT_PATH}/${PYTHON}
PATH_SUFFIXES include)
PATH_SUFFIXES include
REQUIRED
)
find_path(
PY_LIB_DIR ${PYTHON_LIB_NAME}.lib
HINTS ${WIN_EXTERNALS}/${PYTHON} ${EXT_PATH}/${PYTHON}
PATH_SUFFIXES lib)
PATH_SUFFIXES lib
REQUIRED
)
message(STATUS "PY_LIB_DIR: ${PY_LIB_DIR}")
else()
find_path(
PY_INCLUDE Python.h
HINTS ${EXT_PATH}/${PYTHON} /usr/include/${PYTHON}
PATH_SUFFIXES include)
PATH_SUFFIXES include
REQUIRED
)
endif()
message(STATUS "PY_INCLUDE: ${PY_INCLUDE}")
@@ -114,17 +388,21 @@ else()
endif()
endif()
# The per-platform pyconfig.h is located at /externals/python<ver>/<triple>/python<ver>/.
# Not sure why it's setup that way.
find_path(
PY_CONFIG_INCLUDE pyconfig.h
HINTS ${PY_INCLUDE}
PATH_SUFFIXES ${PY_TARGET_DIR}/${PYTHON} ${PY_TARGET_DIR}/${PYTHON}m)
PATH_SUFFIXES ${PY_TARGET_DIR}/${PYTHON} ${PY_TARGET_DIR}/${PYTHON}m
REQUIRED
)
message(STATUS "PY_CONFIG_INCLUDE: ${PY_CONFIG_INCLUDE}")
# -------- GLOBAL COMPILE OPTIONS --------
include_directories(${TENSORRT_ROOT}/include ${PROJECT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/docstrings ${ONNX_INC_DIR} ${PYBIND11_DIR})
link_directories(${TENSORRT_BUILD})
link_directories(${TENSORRT_BUILD} ${TENSORRT_LIBPATH})
if(MSVC)
# Prevent pybind11 from sharing resources with other, potentially ABI incompatible modules
@@ -137,7 +415,7 @@ if(MSVC)
link_libraries(${ADDITIONAL_PLATFORM_LIB_FLAGS})
link_directories(${PY_LIB_DIR})
list(APPEND CMAKE_CXX_FLAGS_DEBUG "/bigobj")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
if(${NV_GEN_PDB})
# PDB is only useful in release mode.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /bigobj")
@@ -199,3 +477,5 @@ endif()
# Note that we have to remove the `lib` prefix from the binding .so's
set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
endif()
-66
View File
@@ -1,66 +0,0 @@
# TensorRT Python Bindings
## Installation
### Set environment variables
Set `TRT_OSSPATH` and `TRT_LIBPATH` environment variables to point to your OSS clone
and TensorRT library location, respectively.
### Download pybind11
Create a directory for external sources and download pybind11 into it.
```bash
export EXT_PATH=~/external
mkdir -p $EXT_PATH && cd $EXT_PATH
git clone https://github.com/pybind/pybind11.git
```
### Download Python headers
#### Add Main Headers
1. Get the source code from the official [python sources](https://www.python.org/downloads/source/)
2. Copy the contents of the `Include/` directory into `$EXT_PATH/pythonX.Y/include/` directory.
Example: Python 3.10
```bash
wget https://www.python.org/ftp/python/3.10.11/Python-3.10.11.tgz
tar -xvf Python-3.10.11.tgz
mkdir -p $EXT_PATH/python3.10/include
cp -r Python-3.10.11/Include/* $EXT_PATH/python3.10/include
```
#### Add PyConfig.h
1. Download the deb package for the desired platform from [here](https://packages.debian.org/search?searchon=contents&keywords=pyconfig.h&mode=path&suite=unstable&arch=any).
Typical plaforms include `x86_64` (`amd64`), `aarch64` (`arm64`), and `ppc64le` (`ppc64el`).
For older versions of Python, you may need to select a different suite.
2. Unpack the debian with `ar x <libpython...>.deb`
3. Unpack the contained `data.tar.xz` with `tar -xvf`
4. Find `pyconfig.h` in the `./usr/include/<platform>/pythonX.Y/` directory and copy it into `$EXT_PATH/pythonX.Y/include/`.
Example: Python 3.10
```bash
wget http://http.us.debian.org/debian/pool/main/p/python3.10/libpython3.10-dev_3.10.12-1_amd64.deb
ar x libpython3.10-dev*.deb
mkdir debian && tar -xf data.tar.xz -C debian
cp debian/usr/include/x86_64-linux-gnu/python3.10/pyconfig.h python3.10/include/
```
### Build Python bindings
Use `build.sh` to generate the installable wheels for the intended Python version and target architecture.
Example: for Python 3.10 `x86_64` wheel,
```bash
cd $TRT_OSSPATH/python
TENSORRT_MODULE=tensorrt PYTHON_MAJOR_VERSION=3 PYTHON_MINOR_VERSION=10 TARGET_ARCHITECTURE=x86_64 ./build.sh
```
### Install the python wheel
```bash
python3 -m pip install ./build/bindings_wheel/dist/tensorrt-*.whl
```
+5 -4
View File
@@ -1155,6 +1155,9 @@ constexpr char const* PROFILE_SHARING_0806 = R"trtdoc(
constexpr char const* ALIASED_PLUGIN_IO_10_03 = R"trtdoc(
Allows plugin I/O to be aliased when using IPluginV3OneBuildV2.
)trtdoc";
constexpr char const* RUNTIME_ACTIVATION_RESIZE_10_10 = R"trtdoc(
Allow update_device_memory_size_for_shapes to resize runner internal activation memory by changing the allocation algorithm. Using this feature can reduce runtime memory requirement when the actual input tensor shapes are smaller than the maximum input tensor dimensions.
)trtdoc";
} // namespace PreviewFeatureDoc
namespace HardwareCompatibilityLevelDoc
@@ -1223,7 +1226,7 @@ constexpr char const* FULL = R"trtdoc(
namespace NetworkDefinitionCreationFlagDoc
{
constexpr char const* descr
= R"trtdoc(List of immutable network properties expressed at network creation time. For example, to enable explicit batch mode, pass a value of ``1 << int(NetworkDefinitionCreationFlag.STRONGLY_TYPED)`` to :func:`create_network` )trtdoc";
= R"trtdoc(List of immutable network properties expressed at network creation time. For example, to enable strongly typed mode, pass a value of ``1 << int(NetworkDefinitionCreationFlag.STRONGLY_TYPED)`` to :func:`create_network` )trtdoc";
constexpr char const* EXPLICIT_BATCH
= R"trtdoc([DEPRECATED] Ignored because networks are always "explicit batch" in TensorRT 10.0.)trtdoc";
constexpr char const* STRONGLY_TYPED
@@ -1889,15 +1892,13 @@ namespace RuntimeInspectorDoc
{
constexpr char const* descr = R"trtdoc(
An engine inspector which prints out the layer information of an engine or an execution context.
The engine or the context must be set before get_layer_information() or get_engine_information() can be called.
The amount of printed information depends on the profiling verbosity setting of the builder config when the engine is built.
By default, the profiling verbosity is set to ProfilingVerbosity.LAYER_NAMES_ONLY, and only layer names will be printed.
If the profiling verbosity is set to ProfilingVerbosity.DETAILED, layer names and layer parameters will be printed.
If the profiling verbosity is set to ProfilingVerbosity.NONE, no layer information will be printed.
:ivar engine: :class:`ICudaEngine` Set or get the engine currently being inspected.
:ivar context: :class:`IExecutionContext` Set or get context currently being inspected.
:ivar execution_context: :class:`IExecutionContext` Set or get context currently being inspected.
:ivar error_recorder: :class:`IErrorRecorder` Application-implemented error reporting interface for TensorRT objects.
)trtdoc";
+2
View File
@@ -24,6 +24,8 @@ namespace tensorrt
namespace CalibrationAlgoTypeDoc
{
constexpr const char* descr = R"trtdoc(
[DEPRECATED] Deprecated in TensorRT 10.1. Superseded by explicit quantization.
Version of calibration algorithm to use.
)trtdoc";
} // namespace CalibrationAlgoTypeDoc
+10 -4
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -383,7 +383,7 @@ constexpr const char* ipluginv3_descr = R"trtdoc(
:ivar num_outputs: :class:`int` The number of outputs from the plugin. This is used by the implementations of :class:`INetworkDefinition` and :class:`Builder`. In particular, it is called prior to any call to :func:`initialize`.
:ivar tensorrt_version: :class:`int` [READ ONLY] The API version with which this plugin was built.
:ivar plugin_type: :class:`str` The plugin type. Should match the plugin name returned by the corresponding plugin creator.
:ivar plugin_name: :class:`str` The plugin name. Should match the plugin name returned by the corresponding plugin creator.
:ivar plugin_version: :class:`str` The plugin version. Should match the plugin version returned by the corresponding plugin creator.
:ivar plugin_namespace: :class:`str` The namespace that this plugin object belongs to. Ideally, all plugin objects from the same plugin library should have the same namespace.
:ivar serialization_size: :class:`int` [READ ONLY] The size of the serialization buffer required.
@@ -403,7 +403,7 @@ constexpr const char* ipluginv3onecore_descr = R"trtdoc(
Every attribute must be explicitly initialized on Python-based plugins.
These attributes will be read-only when accessed through a C++-based plugin.
:ivar plugin_type: :class:`str` The plugin type. Should match the plugin name returned by the corresponding plugin creator.
:ivar plugin_name: :class:`str` The plugin name. Should match the plugin name returned by the corresponding plugin creator.
:ivar plugin_version: :class:`str` The plugin version. Should match the plugin version returned by the corresponding plugin creator.
:ivar plugin_namespace: :class:`str` The namespace that this plugin object belongs to. Ideally, all plugin objects from the same plugin library should have the same namespace.
)trtdoc";
@@ -418,6 +418,10 @@ constexpr const char* ipluginv3onebuild_descr = R"trtdoc(
These attributes will be read-only when accessed through a C++-based plugin.
:ivar num_outputs: :class:`int` The number of outputs from the plugin. This is used by the implementations of :class:`INetworkDefinition` and :class:`Builder`.
:ivar format_combination_limit: :class:`int` The maximum number of format combinations that the plugin supports.
:ivar metadata_string: :class:`str` The metadata string for the plugin.
:ivar timing_cache_id: :class:`str` The timing cache ID for the plugin.
)trtdoc";
constexpr const char* ipluginv3onebuildv2_descr = R"trtdoc(
@@ -929,7 +933,9 @@ namespace IPluginRegistryDoc
constexpr const char* descr = R"trtdoc(
Registers plugin creators.
:ivar plugin_creator_list: All the registered plugin creators.
:ivar plugin_creator_list: [DEPRECATED] Deprecated in TensorRT 10.0. List of IPluginV2-descendent plugin creators in current registry.
:ivar all_creators: List of all registered plugin creators of current registry.
:ivar all_creators_recursive: List of all registered plugin creators of current registry and its parents (if :attr:`parent_search_enabled` is True).
:ivar error_recorder: :class:`IErrorRecorder` Application-implemented error reporting interface for TensorRT objects.
:ivar parent_search_enabled: bool variable indicating whether parent search is enabled. Default is True.
)trtdoc";
@@ -21,7 +21,7 @@
#include "NvInfer.h"
//!
//! \file plugin.h
//! \file NvInferPythonPlugin.h
//!
//! This file contains definitions for supporting the `tensorrt.plugin` Python module
//!
@@ -361,7 +361,7 @@ def _register_plugin_creator(name: str, namespace: str, attrs_types):
plg_creator = _TemplatePluginCreator(name, namespace, attrs_types)
plg_registry.register_creator(plg_creator, namespace)
plg_creator = plg_registry.get_creator(name, "1", namespace)
QDP_CREATORS[f"{name}::{namespace}"] = plg_creator
QDP_CREATORS[f"{namespace}::{name}"] = plg_creator
return plg_creator
+69
View File
@@ -0,0 +1,69 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Copies a template file from a source directory (e.g. packaging/) to a destination (usually a build dir),
replacing variables (e.g. `##TENSORRT_VERSION##`) with concrete values.
Sub-directory structure is preserved.
This file is used by the CMake build when building the python wheels.
"""
import argparse
import glob
import os
def main():
parser = argparse.ArgumentParser(
description="Copy files from a source to a destination, replacing variables with concrete values"
)
parser.add_argument("--src-dir", help="The absolute path to the source directory.", required=True)
parser.add_argument("--dst-dir", help="The absolute path to the destination directory.", required=True)
parser.add_argument("--filepath", help="The template file to copy, relative to the source directory.", required=True)
parser.add_argument("--trt-module", help="The TensorRT module name. One of 'tensorrt', 'tensorrt_lean', or 'tensorrt_dispatch'.", required=True)
parser.add_argument("--trt-py-version", help="The version string for the python bindings being built. Usually `major.minor.patch.build`.", required=True)
parser.add_argument("--cuda-version", help="The Cuda version (major.minor).", required=True)
parser.add_argument("--trt-version", help="The TensorRT version (major.minor.patch).", required=True)
args, _ = parser.parse_known_args()
if not os.path.isdir(args.src_dir):
raise ValueError(f"Provided src-dir {args.src_dir} is not a directory.")
if not os.path.isdir(args.dst_dir):
raise ValueError(f"Provided dst-dir {args.dst_dir} is not a directory.")
target_path = os.path.join(args.src_dir, args.filepath)
if not os.path.exists(target_path):
raise ValueError(f"Target file {target_path} does not exist.")
with open(target_path, 'r', encoding="utf-8") as file:
contents = file.read()
contents = contents.replace("##TENSORRT_MODULE##", args.trt_module)
contents = contents.replace("##TENSORRT_PYTHON_VERSION##", args.trt_py_version)
contents = contents.replace("##CUDA_MAJOR##", args.cuda_version.split(".")[0])
contents = contents.replace("##TENSORRT_MAJOR##", args.trt_version.split(".")[0])
dest_path = os.path.join(args.dst_dir, args.filepath)
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
with open(dest_path, 'w', encoding="utf-8") as of:
of.write(contents)
if __name__ == "__main__":
main()
+25
View File
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Note: This subdirectory is added multiple times, once for each binding library target.
# Indirectly call the current ADD_SOURCES_FUNCTION to populate target sources on the bindings lib that currently being setup.
cmake_language(CALL ${ADD_SOURCES_FUNCTION}
pyTensorRT.cpp
utils.cpp
)
add_subdirectory(infer ${SUBDIR_BINARY_DIR_PREFIX}/src/infer)
add_subdirectory(parsers ${SUBDIR_BINARY_DIR_PREFIX}/src/parsers)
+32
View File
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Note: This subdirectory is added multiple times, once for each binding library target.
# Indirectly call the current ADD_SOURCES_FUNCTION to populate target sources on the bindings lib that currently being setup.
cmake_language(CALL ${ADD_SOURCES_FUNCTION}
pyCore.cpp
pyPlugin.cpp
pyFoundationalTypes.cpp
)
# These sources are omitted from the lean/dispatch runtime bindings.
if(${TRT_PYTHON_IS_FULL_BINDINGS})
cmake_language(CALL ${ADD_SOURCES_FUNCTION}
pyAlgorithmSelector.cpp
pyGraph.cpp
pyInt8.cpp
)
endif()
+5 -2
View File
@@ -1625,13 +1625,16 @@ void bindCore(py::module& m)
py::enum_<PreviewFeature>(m, "PreviewFeature", PreviewFeatureDoc::descr, py::module_local())
.value("PROFILE_SHARING_0806", PreviewFeature::kPROFILE_SHARING_0806, PreviewFeatureDoc::PROFILE_SHARING_0806)
.value("ALIASED_PLUGIN_IO_10_03", PreviewFeature::kALIASED_PLUGIN_IO_10_03,
PreviewFeatureDoc::ALIASED_PLUGIN_IO_10_03);
PreviewFeatureDoc::ALIASED_PLUGIN_IO_10_03)
.value("RUNTIME_ACTIVATION_RESIZE_10_10", PreviewFeature::kRUNTIME_ACTIVATION_RESIZE_10_10,
PreviewFeatureDoc::RUNTIME_ACTIVATION_RESIZE_10_10);
py::enum_<HardwareCompatibilityLevel>(
m, "HardwareCompatibilityLevel", HardwareCompatibilityLevelDoc::descr, py::module_local())
.value("NONE", HardwareCompatibilityLevel::kNONE, HardwareCompatibilityLevelDoc::NONE)
.value("AMPERE_PLUS", HardwareCompatibilityLevel::kAMPERE_PLUS, HardwareCompatibilityLevelDoc::AMPERE_PLUS)
.value("SAME_COMPUTE_CAPABILITY", HardwareCompatibilityLevel::kSAME_COMPUTE_CAPABILITY, HardwareCompatibilityLevelDoc::SAME_COMPUTE_CAPABILITY);
.value("SAME_COMPUTE_CAPABILITY", HardwareCompatibilityLevel::kSAME_COMPUTE_CAPABILITY,
HardwareCompatibilityLevelDoc::SAME_COMPUTE_CAPABILITY);
py::enum_<RuntimePlatform>(m, "RuntimePlatform", RuntimePlatformDoc::descr, py::module_local())
.value("SAME_AS_BUILD", RuntimePlatform::kSAME_AS_BUILD, RuntimePlatformDoc::SAME_AS_BUILD)
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,7 @@
// This file contains all bindings related to TensorRT INetworkDefinition.
#include "ForwardDeclarations.h"
#include "impl/plugin.h"
#include "impl/NvInferPythonPlugin.h"
#include "utils.h"
#include <pybind11/stl.h>
#include <tuple>
+23 -6
View File
@@ -17,7 +17,7 @@
// This file contains all bindings related to plugins.
#include "ForwardDeclarations.h"
#include "impl/plugin.h"
#include "impl/NvInferPythonPlugin.h"
#include "infer/pyPluginDoc.h"
#include "utils.h"
#include <cuda_runtime_api.h>
@@ -2968,9 +2968,11 @@ static const auto get_plugin_creator_list = [](IPluginRegistry& self) {
return new std::vector<IPluginCreator*>(ptr, ptr + numCreators);
};
static const auto get_all_creators = [](IPluginRegistry& self) -> std::vector<py::object>* {
std::vector<py::object>* getCreatorsUtil(
std::function<IPluginCreatorInterface* const*(int32_t* const)> getCreatorsFunc, std::string const& funcName)
{
int32_t numCreators{0};
IPluginCreatorInterface* const* ptr = self.getAllCreators(&numCreators);
IPluginCreatorInterface* const* ptr = getCreatorsFunc(&numCreators);
// Python will free when done.
auto vec = std::make_unique<std::vector<py::object>>(numCreators);
try
@@ -2995,13 +2997,23 @@ static const auto get_all_creators = [](IPluginRegistry& self) -> std::vector<py
}
catch (std::exception const& e)
{
std::cerr << "[ERROR] Exception caught in get_all_creators(): " << e.what() << std::endl;
std::cerr << "[ERROR] Exception caught in " << funcName << "(): " << e.what() << std::endl;
}
catch (...)
{
std::cerr << "[ERROR] Exception caught in get_all_creators()" << std::endl;
std::cerr << "[ERROR] Exception caught in " << funcName << "()" << std::endl;
}
return nullptr;
}
static const auto get_all_creators = [](IPluginRegistry& self) -> std::vector<py::object>* {
return getCreatorsUtil(
std::bind(&IPluginRegistry::getAllCreators, &self, std::placeholders::_1), "get_all_creators");
};
static const auto get_all_creators_recursive = [](IPluginRegistry& self) -> std::vector<py::object>* {
return getCreatorsUtil(std::bind(&IPluginRegistry::getAllCreatorsRecursive, &self, std::placeholders::_1),
"get_all_creators_recursive");
};
static const auto get_capability_interface = [](IPluginV3& self, PluginCapabilityType type) -> py::object {
@@ -3063,7 +3075,11 @@ static const auto get_capability_interface = [](IPluginV3& self, PluginCapabilit
}
catch (py::cast_error const& e)
{
return py::cast(static_cast<IPluginV3QuickRuntime*>(capability_interface));
try
{
return py::cast(static_cast<IPluginV3QuickRuntime*>(capability_interface));
}
PLUGIN_API_CATCH_CAST("get_capability_interface", " a valid runtime capability interface")
}
}
}
@@ -3816,6 +3832,7 @@ void bindPlugin(py::module& m)
m, "IPluginRegistry", IPluginRegistryDoc::descr, py::module_local())
.def_property_readonly("plugin_creator_list", lambdas::get_plugin_creator_list)
.def_property_readonly("all_creators", lambdas::get_all_creators)
.def_property_readonly("all_creators_recursive", lambdas::get_all_creators_recursive)
.def("register_creator",
py::overload_cast<IPluginCreator&, AsciiChar const* const>(&IPluginRegistry::registerCreator), "creator"_a,
"plugin_namespace"_a = "", py::keep_alive<1, 2>{}, IPluginRegistryDoc::register_creator_iplugincreator)
+24
View File
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Note: This subdirectory is added multiple times, once for each binding library target.
# Indirectly call the current ADD_SOURCES_FUNCTION to populate target sources on the bindings lib that currently being setup.
# The parser is only included by the full "tensorrt" binding module.
if(${TRT_PYTHON_IS_FULL_BINDINGS})
cmake_language(CALL ${ADD_SOURCES_FUNCTION}
pyOnnx.cpp
)
endif()
+3 -3
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,8 +17,8 @@
// Implementation of PyBind11 Binding Code for OnnxParser
#include "ForwardDeclarations.h"
#include "onnx/NvOnnxParser.h"
#include "onnx/errorHelpers.hpp"
#include "NvOnnxParser.h"
#include "errorHelpers.hpp"
#include "parsers/pyOnnxDoc.h"
#include "utils.h"
#include <pybind11/stl.h>