Skip to content
Open
Show file tree
Hide file tree
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 Sep 30, 2025
79a7e19
Formatting
wsttiger Sep 30, 2025
d88452f
Removed hardcoded paths to TensorRT installation
wsttiger Oct 1, 2025
e7ec736
Merge branch 'main' into add_trt_decoder
wsttiger Oct 1, 2025
7cbbeb1
Incorrect URL
wsttiger Oct 1, 2025
5287b09
Fixed up the references to cuda in CMake
wsttiger Oct 2, 2025
88b3cc1
Switched to finding cuda toolkit instead of hardcoding cuda headers
wsttiger Oct 3, 2025
1bfbb3d
Disabled trt_decoder for ARM
wsttiger Oct 6, 2025
4c040dc
Redo platform check for x86
wsttiger Oct 6, 2025
e01de62
Added include directory for the Arm64 arch
wsttiger Oct 7, 2025
ce0f24c
Removed cudaqx namespace
wsttiger Oct 7, 2025
e641f49
Added copyright notice
wsttiger Oct 7, 2025
f3d7a95
Added CUDAQ logging + minor details
wsttiger Oct 7, 2025
6533797
Handled CUDA (potential) errors + formatting
wsttiger Oct 8, 2025
83e957b
Removed block_size from trt_decoder logic (there's no parity check ma…
wsttiger Oct 8, 2025
cdb1754
Default initialization + formatting
wsttiger Oct 8, 2025
b6cfa6f
Added LFS (no assets yet), added training for E2E test with test AI d…
wsttiger Oct 12, 2025
aea8d56
Added test AI model (onnx)
wsttiger Oct 12, 2025
036b331
Formatting
wsttiger Oct 12, 2025
1deb4f5
Added test_trt_decoder.py - for the python path
wsttiger Oct 14, 2025
5db5c88
Added trt-decoder optional dependency to cudaq_qec pyproject.toml
wsttiger Oct 15, 2025
2fb89c7
Added platform detection to test_trt_decoder.py
wsttiger Oct 15, 2025
8fa4ef8
Modified platform checks
wsttiger Oct 15, 2025
4f133f9
Formatting
wsttiger Oct 15, 2025
fb16b36
Merge branch 'main' into add_trt_decoder
wsttiger Oct 16, 2025
c9e563f
DCO Remediation Commit for Scott Thornton <[email protected]>
wsttiger Oct 16, 2025
392f5de
Added installation of TensorRT to build_wheels.yaml
wsttiger Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.onnx filter=lfs diff=lfs merge=lfs -text
11 changes: 10 additions & 1 deletion .github/workflows/all_libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ jobs:

- name: Install build requirements
run: |
apt install -y --no-install-recommends gfortran libblas-dev
apt install -y --no-install-recommends gfortran libblas-dev wget

- name: Install TensorRT (x86_64 only)
if: matrix.platform == 'amd64'
run: |
wget https://developer.download.nvidia.com/compute/tensorrt/10.13.3/local_installers/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
dpkg -i nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
cp /var/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9/nv-tensorrt-local-4B177B4F-keyring.gpg /usr/share/keyrings/
apt update
apt install -y tensorrt-dev

- name: Build
id: build
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ jobs:
run: |
.github/workflows/scripts/build_cudaq.sh --python-version ${{ matrix.python }}

- name: Install build requirements
run: |
apt install -y --no-install-recommends wget

- name: Install TensorRT (x86_64 only)
if: matrix.platform == 'amd64'
run: |
wget https://developer.download.nvidia.com/compute/tensorrt/10.13.3/local_installers/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
dpkg -i nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
cp /var/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9/nv-tensorrt-local-4B177B4F-keyring.gpg /usr/share/keyrings/
apt update
apt install -y tensorrt-dev

- name: Build CUDA-QX wheels
env:
SUFFIX: ${{ matrix.platform == 'amd64' && 'x86_64' || 'aarch64' }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/lib_qec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ jobs:
# ========================================================================
# Build library
# ========================================================================
- name: Install build requirements
run: |
apt install -y --no-install-recommends gfortran libblas-dev wget

- name: Install TensorRT (x86_64 only)
if: matrix.platform == 'amd64'
run: |
wget https://developer.download.nvidia.com/compute/tensorrt/10.13.3/local_installers/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
dpkg -i nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9_1.0-1_amd64.deb
cp /var/nv-tensorrt-local-repo-ubuntu2404-10.13.3-cuda-12.9/nv-tensorrt-local-4B177B4F-keyring.gpg /usr/share/keyrings/
apt update
apt install -y tensorrt-dev

- name: Build
id: build
Expand Down
3 changes: 3 additions & 0 deletions assets/tests/surface_code_decoder.onnx
Git LFS file not shown
56 changes: 56 additions & 0 deletions libs/qec/include/cudaq/qec/trt_decoder_internal.h
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 &params);

/// @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 &params,
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
4 changes: 4 additions & 0 deletions libs/qec/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ add_library(${LIBRARY_NAME} SHARED
)

add_subdirectory(decoders/plugins/example)
# TensorRT decoder is only built for x86 architectures
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)")
add_subdirectory(decoders/plugins/trt_decoder)
endif()
add_subdirectory(codes)
add_subdirectory(device)

Expand Down
144 changes: 144 additions & 0 deletions libs/qec/lib/decoders/plugins/trt_decoder/CMakeLists.txt
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
)



Loading