Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 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
42c2b32
Made minor mods to build_wheels.yaml
wsttiger Oct 17, 2025
5ad505b
Hardcoding TensorRT package name for now
wsttiger Oct 21, 2025
2d08b88
Added debugging info
wsttiger Oct 21, 2025
4defcfd
Edits to build_wheel.sh
wsttiger Oct 21, 2025
62cdbac
more edits of build_wheel.yaml for debugging
wsttiger Oct 21, 2025
d4e79a9
Added TensorRT library path to LD_LIBRARY_PATH for auditwheel
wsttiger Oct 21, 2025
d8489f7
modified test_wheels to check for GPU's
wsttiger Oct 21, 2025
6ba9191
Merge from main - fixed conflict in test_wheels.sh
wsttiger Oct 22, 2025
eea3198
Removed the hardcoding of TensorRT version and path from the build_wh…
wsttiger Oct 22, 2025
33359f5
Added all optional dependencies to cudaq_qec
wsttiger Oct 22, 2025
5e38f6a
Fixed small bug in pyproject.toml for QEC
wsttiger Oct 23, 2025
be6a52f
Added extra NVIDIA index for installing dependencies (wheels)
wsttiger Oct 23, 2025
f152a6c
Fixes for the build_wheels.yaml CI/CD pipeline
wsttiger Oct 24, 2025
55ae990
Fixed RPATH in trt_decoder (plugin)
wsttiger Oct 24, 2025
07ed875
Remove extra bloat
wsttiger Oct 24, 2025
108a8b9
Installed and enabled Git LFS for trt_decoder tests
wsttiger Oct 25, 2025
d090aca
Moved build_engine_from_onnx.py to scripts directory
wsttiger Oct 27, 2025
2e727c0
Parameterize CUDA version for TensorRT installation in CI workflows
wsttiger Oct 27, 2025
626ee9a
Map CUDA 12.6 to 12.9 for TensorRT downloads in build_wheels workflow
wsttiger Oct 27, 2025
65fdcee
Fixed minor bug
wsttiger Oct 27, 2025
ac18d2b
Removed the x86_64 constraint on the trt_decoder tests, also removed …
wsttiger Oct 28, 2025
b645807
Formatting
wsttiger Oct 28, 2025
8e0ab06
Re-enabled building trt_decoder for ARM architecture
wsttiger Oct 28, 2025
60e703d
Added try/catch around instantiating decoder
wsttiger Oct 28, 2025
e9825b3
Formatting
wsttiger Oct 28, 2025
c2c61db
Re-enabled ARM in pyproject.toml.cu13
wsttiger Oct 28, 2025
2b39242
no tensorrt-cu13
wsttiger Oct 28, 2025
663ba48
tensorrt-cu13 is back in
wsttiger Oct 28, 2025
9626a12
Re-calibrated the warning messages
wsttiger Oct 31, 2025
13e5c69
Created a more focused set of test data
wsttiger Oct 31, 2025
6ea6ec9
Added check for CUDA
wsttiger Oct 31, 2025
32e8e64
Formatting
wsttiger Oct 31, 2025
3642fc8
Merge branch 'main' into add_trt_decoder
wsttiger Oct 31, 2025
30da7ce
Reduced the number of syndromes to 30
wsttiger Oct 31, 2025
5389216
nvidia-cublas-cuXXX -> nvidia-cublas
wsttiger Nov 1, 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
18 changes: 16 additions & 2 deletions .github/workflows/all_libs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,21 @@ 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 (amd64)
if: matrix.platform == 'amd64'
run: |
apt-cache search tensorrt | awk '{print "Package: "$1"\nPin: version *+cuda${{ matrix.cuda_version }}\nPin-Priority: 1001\n"}' | tee /etc/apt/preferences.d/tensorrt-cuda${{ matrix.cuda_version }}.pref > /dev/null
apt update
apt install -y tensorrt-dev

- name: Install TensorRT (arm64)
if: matrix.platform == 'arm64'
run: |
apt-cache search tensorrt | awk '{print "Package: "$1"\nPin: version *+cuda13.0\nPin-Priority: 1001\n"}' | tee /etc/apt/preferences.d/tensorrt-cuda13.0.pref > /dev/null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is installing CUDA 13 regardless of what ${{matrix.cuda_version}} is, so it is installing it in our 12.6 images, too. I believe (?) this should not be installed for CUDA 12.6 because we are not supporting CUDA 12 + ARM for this, right?

Point of reference: https://github.com/NVIDIA/cudaqx/actions/runs/18989982159/job/54240883357#step:12:41 shows the CUDA 13 version being installed in AR CUDA 12.6. (I found this because our GitLab pipeline is broken for ARM right now, and I am still investigating.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be addressed by #332. @wsttiger take a look and let me know what you think.

apt update
apt install -y tensorrt-dev

- name: Build
id: build
Expand Down Expand Up @@ -92,7 +106,7 @@ jobs:
LD_LIBRARY_PATH: ${{ env.MPI_PATH }}/lib:${{ env.LD_LIBRARY_PATH }}
shell: bash
run: |
pip install numpy pytest cupy-cuda${{ steps.config.outputs.cuda_major }}x cuquantum-cu${{ steps.config.outputs.cuda_major }} torch lightning ml_collections mpi4py transformers quimb opt_einsum torch nvidia-cublas-cu${{ steps.config.outputs.cuda_major }} cuquantum-python-cu${{ steps.config.outputs.cuda_major }}==25.09
pip install numpy pytest cupy-cuda${{ steps.config.outputs.cuda_major }}x cuquantum-cu${{ steps.config.outputs.cuda_major }} torch lightning ml_collections mpi4py transformers quimb opt_einsum torch nvidia-cublas cuquantum-python-cu${{ steps.config.outputs.cuda_major }}==25.09
# The following tests are needed for docs/sphinx/examples/qec/python/tensor_network_decoder.py.
if [ "$(uname -m)" == "x86_64" ]; then
# Stim is not currently available on manylinux ARM wheels, so only
Expand Down
64 changes: 58 additions & 6 deletions .github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,59 @@ jobs:
build-type: Release

steps:
- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

- name: Configure
id: config
run: |
cuda_major=`echo ${{ matrix.cuda_version }} | cut -d . -f1`
echo "cuda_major=$cuda_major" >> $GITHUB_OUTPUT
# Map CUDA 12.6 to 12.9 for TensorRT filename
if [ "${{ matrix.cuda_version }}" == "12.6" ]; then
tensorrt_cuda_version="12.9"
tensorrt_cuda_major="12"
else
tensorrt_cuda_version="${{ matrix.cuda_version }}"
tensorrt_cuda_major="$cuda_major"
fi
echo "tensorrt_cuda_version=$tensorrt_cuda_version" >> $GITHUB_OUTPUT
echo "tensorrt_cuda_major=$tensorrt_cuda_major" >> $GITHUB_OUTPUT
tensorrt_major_version="10.13.3"
tensorrt_minor_version="9"
tensorrt_version="${tensorrt_major_version}.${tensorrt_minor_version}"
echo "tensorrt_major_version=$tensorrt_major_version" >> $GITHUB_OUTPUT
echo "tensorrt_version=$tensorrt_version" >> $GITHUB_OUTPUT

- name: Install TensorRT (amd64)
shell: bash
if: matrix.platform == 'amd64'
run: |
mkdir -p /trt_download
pushd /trt_download
pwd
wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/${{ steps.config.outputs.tensorrt_major_version }}/tars/TensorRT-${{ steps.config.outputs.tensorrt_version }}.Linux.x86_64-gnu.cuda-${{ steps.config.outputs.tensorrt_cuda_version }}.tar.gz
tar -zxvf TensorRT-${{ steps.config.outputs.tensorrt_version }}.Linux.x86_64-gnu.cuda-${{ steps.config.outputs.tensorrt_cuda_version }}.tar.gz
pwd
popd
find /trt_download/TensorRT-${{ steps.config.outputs.tensorrt_version }} -name "NvInfer.h"
find /trt_download/TensorRT-${{ steps.config.outputs.tensorrt_version }} -name "NvInferRuntime.h"

- name: Install TensorRT (arm64)
shell: bash
if: matrix.platform == 'arm64'
run: |
mkdir -p /trt_download
pushd /trt_download
pwd
wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/${{ steps.config.outputs.tensorrt_major_version }}/tars/TensorRT-${{ steps.config.outputs.tensorrt_version }}.Linux.aarch64-gnu.cuda-13.0.tar.gz
tar -zxvf TensorRT-${{ steps.config.outputs.tensorrt_version }}.Linux.aarch64-gnu.cuda-13.0.tar.gz
pwd
popd
find /trt_download/TensorRT-${{ steps.config.outputs.tensorrt_version }} -name "NvInfer.h"
find /trt_download/TensorRT-${{ steps.config.outputs.tensorrt_version }} -name "NvInferRuntime.h"

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

# Do this early to help validate user inputs (if present)
- name: Fetch assets
Expand Down Expand Up @@ -123,6 +166,7 @@ jobs:
--cudaq-prefix /usr/local/cudaq \
--build-type ${{ inputs.build_type }} \
--python-version ${{ matrix.python }} \
--tensorrt-path /trt_download/TensorRT-${{ steps.config.outputs.tensorrt_version }} \
--version ${{ inputs.version || '0.99.99' }}

- name: Upload artifact
Expand Down Expand Up @@ -332,11 +376,19 @@ jobs:
cuda_version: ['12.6', '13.0']

steps:

- name: Install git for LFS
shell: bash
run: |
apt update
apt install -y --no-install-recommends git git-lfs

- name: Get code
uses: actions/checkout@v4
with:
set-safe-directory: true

lfs: true # download assets file(s) for TRT tests

- name: Configure
id: config
run: |
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/lib_qec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ jobs:
# ========================================================================
# Build library
# ========================================================================
- name: Install build requirements
run: |
apt install -y --no-install-recommends gfortran libblas-dev wget

- name: Install TensorRT (amd64)
if: matrix.platform == 'amd64'
run: |
apt-cache search tensorrt | awk '{print "Package: "$1"\nPin: version *+cuda${{ matrix.cuda_version }}\nPin-Priority: 1001\n"}' | tee /etc/apt/preferences.d/tensorrt-cuda${{ matrix.cuda_version }}.pref > /dev/null
apt update
apt install -y tensorrt-dev

- name: Install TensorRT (arm64)
if: matrix.platform == 'arm64'
run: |
apt-cache search tensorrt | awk '{print "Package: "$1"\nPin: version *+cuda13.0\nPin-Priority: 1001\n"}' | tee /etc/apt/preferences.d/tensorrt-cuda13.0.pref > /dev/null
apt update
apt install -y tensorrt-dev

- name: Build
id: build
Expand All @@ -86,7 +103,7 @@ jobs:
- name: Install python requirements
shell: bash
run: |
pip install numpy pytest cupy-cuda${{ steps.config.outputs.cuda_major }}x cuquantum-cu${{ steps.config.outputs.cuda_major }} quimb opt_einsum torch nvidia-cublas-cu${{ steps.config.outputs.cuda_major }} cuquantum-python-cu${{ steps.config.outputs.cuda_major }}==25.09
pip install numpy pytest cupy-cuda${{ steps.config.outputs.cuda_major }}x cuquantum-cu${{ steps.config.outputs.cuda_major }} quimb opt_einsum torch nvidia-cublas cuquantum-python-cu${{ steps.config.outputs.cuda_major }}==25.09
# The following tests are needed for docs/sphinx/examples/qec/python/tensor_network_decoder.py.
if [ "$(uname -m)" == "x86_64" ]; then
# Stim is not currently available on manylinux ARM wheels, so only
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/scripts/build_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ show_help() {
echo " --cudaq-prefix Path to CUDA-Q's install prefix"
echo " (default: \$HOME/.cudaq)"
echo " --python-version Python version to build wheel for (e.g. 3.11)"
echo " --tensorrt-path Path to TensorRT installation directory"
echo " (default: /trt_download/TensorRT-10.13.3.9)"
echo " --devdeps Build wheels suitable for internal testing"
echo " (not suitable for distribution but sometimes"
echo " helpful for debugging)"
Expand Down Expand Up @@ -68,6 +70,15 @@ parse_options() {
exit 1
fi
;;
--tensorrt-path)
if [[ -n "$2" && "$2" != -* ]]; then
tensorrt_path=("$2")
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
--devdeps)
devdeps=true
shift 1
Expand Down Expand Up @@ -99,6 +110,7 @@ parse_options() {
cudaq_prefix=$HOME/.cudaq
build_type=Release
python_version=3.11
tensorrt_path=/trt_download/TensorRT-10.13.3.9
devdeps=false
wheels_version=0.0.0
cuda_version=12
Expand Down Expand Up @@ -136,7 +148,7 @@ export CUDAQX_SOLVERS_VERSION=$wheels_version
cd libs/qec
cp pyproject.toml.cu${cuda_version} pyproject.toml

SKBUILD_CMAKE_ARGS="-DCUDAQ_DIR=$cudaq_prefix/lib/cmake/cudaq"
SKBUILD_CMAKE_ARGS="-DCUDAQ_DIR=$cudaq_prefix/lib/cmake/cudaq;-DTENSORRT_ROOT=$tensorrt_path"
if ! $devdeps; then
SKBUILD_CMAKE_ARGS+=";-DCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN=/opt/rh/gcc-toolset-11/root/usr/lib/gcc/${ARCH}-redhat-linux/11/"
fi
Expand All @@ -146,9 +158,12 @@ $python -m build --wheel

CUDAQ_EXCLUDE_LIST=$(for f in $(find $cudaq_prefix/lib -name "*.so" -printf "%P\n" | sort); do echo "--exclude $f"; done | tr '\n' ' ')

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/_skbuild/lib" \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/_skbuild/lib:$tensorrt_path/lib" \
$python -m auditwheel -v repair dist/*.whl $CUDAQ_EXCLUDE_LIST \
--wheel-dir /wheels \
--exclude libcudart.so.${cuda_version} \
--exclude libnvinfer.so.10 \
--exclude libnvonnxparser.so.10 \
${PLAT_STR}

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

add_subdirectory(decoders/plugins/example)
add_subdirectory(decoders/plugins/trt_decoder)
add_subdirectory(codes)
add_subdirectory(device)

Expand Down
Loading