-
Notifications
You must be signed in to change notification settings - Fork 33
Add trt decoder #307
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
wsttiger
wants to merge
27
commits into
NVIDIA:main
Choose a base branch
from
wsttiger:add_trt_decoder
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.
+2,855
−1
Open
Add trt decoder #307
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
9e97e26
Add TensorRT decoder plugin for quantum error correction
wsttiger 79a7e19
Formatting
wsttiger d88452f
Removed hardcoded paths to TensorRT installation
wsttiger e7ec736
Merge branch 'main' into add_trt_decoder
wsttiger 7cbbeb1
Incorrect URL
wsttiger 5287b09
Fixed up the references to cuda in CMake
wsttiger 88b3cc1
Switched to finding cuda toolkit instead of hardcoding cuda headers
wsttiger 1bfbb3d
Disabled trt_decoder for ARM
wsttiger 4c040dc
Redo platform check for x86
wsttiger e01de62
Added include directory for the Arm64 arch
wsttiger ce0f24c
Removed cudaqx namespace
wsttiger e641f49
Added copyright notice
wsttiger f3d7a95
Added CUDAQ logging + minor details
wsttiger 6533797
Handled CUDA (potential) errors + formatting
wsttiger 83e957b
Removed block_size from trt_decoder logic (there's no parity check ma…
wsttiger cdb1754
Default initialization + formatting
wsttiger b6cfa6f
Added LFS (no assets yet), added training for E2E test with test AI d…
wsttiger aea8d56
Added test AI model (onnx)
wsttiger 036b331
Formatting
wsttiger 1deb4f5
Added test_trt_decoder.py - for the python path
wsttiger 5db5c88
Added trt-decoder optional dependency to cudaq_qec pyproject.toml
wsttiger 2fb89c7
Added platform detection to test_trt_decoder.py
wsttiger 8fa4ef8
Modified platform checks
wsttiger 4f133f9
Formatting
wsttiger fb16b36
Merge branch 'main' into add_trt_decoder
wsttiger c9e563f
DCO Remediation Commit for Scott Thornton <[email protected]>
wsttiger 392f5de
Added installation of TensorRT to build_wheels.yaml
wsttiger 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
Some comments aren't visible on the classic Files Changed page.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.onnx filter=lfs diff=lfs merge=lfs -text |
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
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
Git LFS file not shown
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,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 - 2025 NVIDIA Corporation & Affiliates. * | ||
* All rights reserved. * | ||
* * | ||
* This source code and the accompanying materials are made available under * | ||
* the terms of the Apache License 2.0 which accompanies this distribution. * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "cudaq/qec/decoder.h" | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "NvInfer.h" | ||
#include "NvOnnxParser.h" | ||
|
||
namespace cudaq::qec::trt_decoder_internal { | ||
|
||
/// @brief Validates TRT decoder parameters | ||
/// @param params The parameter map to validate | ||
/// @throws std::runtime_error if parameters are invalid | ||
void validate_trt_decoder_parameters(const cudaqx::heterogeneous_map ¶ms); | ||
|
||
/// @brief Loads a binary file into memory | ||
/// @param filename Path to the file to load | ||
/// @return Vector containing the file contents | ||
/// @throws std::runtime_error if file cannot be opened | ||
std::vector<char> load_file(const std::string &filename); | ||
|
||
/// @brief Builds a TensorRT engine from an ONNX model | ||
/// @param onnx_model_path Path to the ONNX model file | ||
/// @param params Configuration parameters | ||
/// @param logger TensorRT logger instance | ||
/// @return Unique pointer to the built TensorRT engine | ||
/// @throws std::runtime_error if engine building fails | ||
std::unique_ptr<nvinfer1::ICudaEngine> | ||
build_engine_from_onnx(const std::string &onnx_model_path, | ||
const cudaqx::heterogeneous_map ¶ms, | ||
nvinfer1::ILogger &logger); | ||
|
||
/// @brief Saves a TensorRT engine to a file | ||
/// @param engine The engine to save | ||
/// @param file_path Path where to save the engine | ||
/// @throws std::runtime_error if saving fails | ||
void save_engine_to_file(nvinfer1::ICudaEngine *engine, | ||
const std::string &file_path); | ||
|
||
/// @brief Parses and configures precision settings for TensorRT | ||
/// @param precision The precision string (fp16, bf16, int8, fp8, noTF32, best) | ||
/// @param config TensorRT builder config instance | ||
void parse_precision(const std::string &precision, | ||
nvinfer1::IBuilderConfig *config); | ||
|
||
} // namespace cudaq::qec::trt_decoder_internal |
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
144 changes: 144 additions & 0 deletions
144
libs/qec/lib/decoders/plugins/trt_decoder/CMakeLists.txt
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,144 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2024 - 2025 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
cmake_minimum_required(VERSION 3.28 FATAL_ERROR) | ||
|
||
set(MODULE_NAME "cudaq-qec-trt-decoder") | ||
|
||
project(${MODULE_NAME}) | ||
|
||
# Set default TensorRT root if not provided | ||
if(NOT DEFINED TENSORRT_ROOT) | ||
message(STATUS "TENSORRT_ROOT not provided, using default: ${TENSORRT_ROOT}") | ||
else() | ||
message(STATUS "Using TENSORRT_ROOT: ${TENSORRT_ROOT}") | ||
endif() | ||
|
||
# Specify the source file for the plugin | ||
set(PLUGIN_SRC | ||
trt_decoder.cpp | ||
# Add additional source files here as needed | ||
) | ||
|
||
find_package(CUDAToolkit REQUIRED) | ||
|
||
# Create the shared library | ||
add_library(${MODULE_NAME} SHARED ${PLUGIN_SRC}) | ||
|
||
# Check for TensorRT availability | ||
find_path(TENSORRT_INCLUDE_DIR NvInfer.h | ||
PATHS | ||
${TENSORRT_ROOT}/include | ||
/usr/include/x86_64-linux-gnu | ||
/usr/include/aarch64-linux-gnu/ | ||
/usr/local/cuda/include | ||
/usr/local/tensorrt/include | ||
/opt/tensorrt/include | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
find_library(TENSORRT_LIBRARY nvinfer | ||
PATHS | ||
${TENSORRT_ROOT}/lib | ||
/usr/lib/x86_64-linux-gnu | ||
/usr/local/cuda/lib64 | ||
/usr/local/tensorrt/lib | ||
/opt/tensorrt/lib | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
find_library(TENSORRT_ONNX_LIBRARY nvonnxparser | ||
PATHS | ||
${TENSORRT_ROOT}/lib | ||
/usr/lib/x86_64-linux-gnu | ||
/usr/local/cuda/lib64 | ||
/usr/local/tensorrt/lib | ||
/opt/tensorrt/lib | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
if(TENSORRT_INCLUDE_DIR AND TENSORRT_LIBRARY AND TENSORRT_ONNX_LIBRARY) | ||
message(STATUS "TensorRT found: ${TENSORRT_INCLUDE_DIR}") | ||
message(STATUS "TensorRT library: ${TENSORRT_LIBRARY}") | ||
message(STATUS "TensorRT ONNX parser: ${TENSORRT_ONNX_LIBRARY}") | ||
target_compile_definitions(${MODULE_NAME} PRIVATE TENSORRT_AVAILABLE) | ||
else() | ||
message(WARNING "TensorRT not found. Building decoder without TensorRT support.") | ||
message(WARNING "TENSORRT_INCLUDE_DIR: ${TENSORRT_INCLUDE_DIR}") | ||
message(WARNING "TENSORRT_LIBRARY: ${TENSORRT_LIBRARY}") | ||
message(WARNING "TENSORRT_ONNX_LIBRARY: ${TENSORRT_ONNX_LIBRARY}") | ||
endif() | ||
|
||
# Set the include directories for dependencies | ||
target_include_directories(${MODULE_NAME} | ||
PUBLIC | ||
${CMAKE_SOURCE_DIR}/libs/qec/include | ||
${CMAKE_SOURCE_DIR}/libs/core/include | ||
) | ||
|
||
# Add TensorRT include directory if found | ||
if(TENSORRT_INCLUDE_DIR) | ||
target_include_directories(${MODULE_NAME} PRIVATE | ||
${TENSORRT_INCLUDE_DIR} | ||
${CUDAToolkit_INCLUDE_DIRS} | ||
) | ||
endif() | ||
|
||
# Link with required libraries | ||
target_link_libraries(${MODULE_NAME} | ||
PUBLIC | ||
cudaqx-core | ||
cudaq::cudaq-operator | ||
PRIVATE | ||
cudaq::cudaq-common | ||
cudaq-qec | ||
) | ||
|
||
# Conditionally link TensorRT libraries | ||
if(TENSORRT_LIBRARY AND TENSORRT_ONNX_LIBRARY) | ||
target_link_libraries(${MODULE_NAME} PRIVATE | ||
${TENSORRT_LIBRARY} | ||
${TENSORRT_ONNX_LIBRARY} | ||
CUDA::cudart | ||
) | ||
endif() | ||
|
||
set_target_properties(${MODULE_NAME} PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/decoder-plugins | ||
) | ||
|
||
# RPATH configuration | ||
# ============================================================================== | ||
|
||
if (NOT SKBUILD) | ||
set_target_properties(${MODULE_NAME} PROPERTIES | ||
BUILD_RPATH "$ORIGIN:${TENSORRT_ROOT}/lib" | ||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../tensorrt_libs" | ||
) | ||
|
||
# Let CMake automatically add paths of linked libraries to the RPATH: | ||
set_target_properties(${MODULE_NAME} PROPERTIES | ||
INSTALL_RPATH_USE_LINK_PATH TRUE) | ||
else() | ||
# CUDA-Q install its libraries in site-packages/lib (or dist-packages/lib) | ||
# Thus, we need the $ORIGIN/../lib | ||
set_target_properties(${MODULE_NAME} PROPERTIES | ||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../tensorrt_libs" | ||
) | ||
endif() | ||
|
||
# Install | ||
# ============================================================================== | ||
|
||
install(TARGETS ${MODULE_NAME} | ||
COMPONENT qec-lib-plugins | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/decoder-plugins | ||
) | ||
|
||
|
||
|
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.
Uh oh!
There was an error while loading. Please reload this page.