← Open Source
cyrusbehr

tensorrt-cpp-api

TensorRT C++ API Tutorial.

TutorialsTool-specific tutorialsC++
Open on GitHub
Momentum
+0stars in 24 hours0.0%
811
Stars
105
Forks
+-3
This week
4
Contributors
Created 2021-10-25 · Updated 2026-10-15 · #13581 today
Top developers
cyrusbehrthomaskleivenwicyn

cyrusbehr/tensorrt-cpp-api is ranked 13,581 with 811 stars.

Same-category comparison

cyrusbehr/tensorrt-cpp-api is ranked 13,581 among these 8 peers; GoogleCloudPlatform/keras-idiomatic-programmer is ranked 13,578.

Same-category comparison
NameRankMetrics
awslabs/amazon-bedrock-agent-samples13,554
Language:
Python
Stars:
813
Forks:
283
Description:
Example Jupyter notebooks 📓 and code scripts 💻 for using Amazon Bedrock Agents 🤖 and its functionalities.
PracticalDL/Practical-Deep-Learning-Book13,564
Language:
Jupyter Notebook
Stars:
812
Forks:
339
Description:
Official code repo for the O'Reilly Book - Practical Deep Learning for Cloud, Mobile & Edge.
ShawnyXiao/TextClassification-Keras13,566
Language:
Python
Stars:
812
Forks:
185
Description:
Text classification models implemented in Keras, including: FastText, TextCNN, TextRNN, TextBiRNN, TextAttBiRNN, HAN, RCNN, RCNNVariant, etc.
GoogleCloudPlatform/keras-idiomatic-programmer13,578
Language:
Jupyter Notebook
Stars:
811
Forks:
277
Description:
Books, Presentations, Workshops, Notebook Labs, and Model Zoo for Software Engineers and Data Scientists wanting to learn the TF.Keras Machine Learning framework.
erikaduan/r_tips13,589
Language:
R
Stars:
810
Forks:
205
Description:
R programming tips for data cleaning, data visualisation, statistical modelling and machine learning.
unpingco/Python-for-Probability-Statistics-and-Machine-Learning13,604
Language:
Jupyter Notebook
Stars:
809
Forks:
300
Description:
Jupyter Notebooks for Springer book "Python for Probability, Statistics, and Machine Learning".
kale5195/chilloutai13,619
Language:
Python
Stars:
807
Forks:
104
SkafteNicki/dtu_mlops13,623
Language:
Python
Stars:
806
Forks:
680
Description:
Exercises and supplementary material for the machine learning operations course at DTU.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguageC++
CategoryTutorials
SubcategoryTool-specific tutorials
Stars811
Forks105
Contributors4
Created date2021-10-25
Updated date2026-10-15
Stars in 1 day0
Stars in 7 days-3
Rank13,581
Previous rank19,269
Rank change5,688
7-day stars rank18,659
Previous 7-day stars rank18,594
7-day stars rank change-65
Total stars rank13,195
Previous total stars rank13,182
Total stars rank change-13
CountryUSA
README summary

It targets **TensorRT ≥ 10** (built to the TensorRT 11 surface), CUDA 12, C++20, Linux. Features **Engine cache that's actually safe. ** Build-or-load keyed by ONNX content hash + build options TensorRT version + GPU UUID, with a JSON sidecar and atomic writes. A stale cache (changed model, options, driver, or GPU) is detected and rebuilt instead of silently misused. ** Per-input min/opt/max optimization profiles; -aware ; one optimization profile per execution context for concurrent dynamic-shape inference. ** leases execution

contexts for multi-stream inference; every call runs on a caller-provided . The engine is thread-compatible; the pool is thread-safe. ** No , OpenCV, or spdlog types in any public header (PImpl + version-gated, generated ). Consumers need TensorRT at runtime, not compile time. ** / / …; precision is version-aware and never a silent no-op (it errors clearly when a mode isn't achievable). **Optional fused preprocessing** ( ): one CUDA kernel does letterbox-resize → BGR↔RGB → per-channel normalize → HWC→NCHW → cast, no intermediate

buffers. 07 ms | 937 inf/s | | YOLOv8n | FP32 | 2. 00 ms | 499 inf/s | | MobileNetV2 | FP16 | 0. The library's work is everything around that call: zero-copy name-keyed IO with no per-call allocations or nested-vector copies, a stream-ordered allocator, and the no-throw / API. The Python bindings run the same path within ~13% of C++ ( ). Install TensorRT and CUDA are system/externally provided. In brief: Then in a downstream project: Python: (builds the wheel via scikit

-build-core). Examples has four runnable reference programs, each consuming the installed package: **classification** (ImageNet top-5), **detection** (YOLOv8n + NMS), **segmentation** (DeepLabV3), and a **zero-copy Python** demo with a C++/Python perf-parity benchmark. Documentation Quickstart & core concepts Installation Upgrading from v6 API reference: (HTML in ) Sister projects This library is the inference backend for YOLOv8-TensorRT-CPP and YOLOv9-TensorRT-CPP (object detection, segmentation, pose). Scope Linux, CUDA 12, TensorRT ≥ 10, CNN-style vision models. Windows and LLM

/transformer-specific features are out of scope. Install the hooks with (clang-format + cmake-format); CI runs the build, the CPU test suite, sanitizers, and a Python wheel build. Contributors This project follows the all-contributors specification.

Frequently asked questions

How many stars and forks are recorded?

cyrusbehr/tensorrt-cpp-api has 811 stars and 105 forks.

What is the repository rank?

cyrusbehr/tensorrt-cpp-api is ranked 13,581.

What language and category are recorded?

cyrusbehr/tensorrt-cpp-api has 811 stars, uses C++ and belongs to Tutorials.

Which repository is closest in rank?

cyrusbehr/tensorrt-cpp-api is compared with GoogleCloudPlatform/keras-idiomatic-programmer, ranked 13,578 with 811 stars.

README

TensorRT C++ API

A modern, no-throw C++ library for high-performance GPU inference of CNN models with NVIDIA TensorRT — with optional zero-copy Python bindings.

tensorrt_cpp_api turns an ONNX model into a cached, optimized TensorRT engine and runs it with a small, leak-free API: name-keyed tensors at the boundary, caller-owned CUDA streams, explicit host/device transfers, and a Status/Result error model — no exceptions, no OpenCV or TensorRT types in the public headers. It targets TensorRT ≥ 10 (built to the TensorRT 11 surface), CUDA 12, C++20, Linux.

#include 
using namespace trtcpp;

int main() {
    // Build an FP16 engine from ONNX, or load it from the on-disk cache if one is already current.
    BuildOptions opt;
    opt.precision = Precision::kFp16;
    opt.engineCacheDir = "engines";
    auto engine = EngineBuilder{}.buildAndLoad("model.onnx", opt);
    if (!engine) {
        std::fprintf(stderr, "%s\n", engine.status().message().c_str());
        return 1;
    }

    Stream stream;  // owns a CUDA stream — or Stream::wrap(existingHandle) to use yours
    auto input = Tensor::allocate(DType::kFloat32, Shape{1, 3, 640, 640}, Device::kCuda).value();
    // ... fill `input` (e.g. via the fused preproc kernel) ...

    auto output = engine->inferSingle({{engine->inputNames().front(), input.view()}}, stream);
    if (!output) return 1;

    auto host = output->toHost(stream).value();   // explicit D2H + sync; never implicit
    std::span scores = host.as().value();
    // ... post-process `scores` ...
}

Features

  • Engine cache that's actually safe. Build-or-load keyed by ONNX content hash + build options
    • TensorRT version + GPU UUID, with a JSON sidecar and atomic writes. A stale cache (changed model, options, driver, or GPU) is detected and rebuilt instead of silently misused.
  • Dynamic shapes, done right. Per-input min/opt/max optimization profiles; -1-aware Shape; one optimization profile per execution context for concurrent dynamic-shape inference.
  • Concurrency. EnginePool leases execution contexts for multi-stream inference; every call runs on a caller-provided Stream. The engine is thread-compatible; the pool is thread-safe.
  • No leaky abstractions. No nvinfer1, OpenCV, or spdlog types in any public header (PImpl + version-gated, generated build_config.h). Consumers need TensorRT at runtime, not compile time.
  • Quantization without surprises. Precision::kFp16 / kInt8Qdq / kFp8 …; precision is version-aware and never a silent no-op (it errors clearly when a mode isn't achievable).
  • Optional fused preprocessing (tensorrt_cpp_api::preproc): one CUDA kernel does letterbox-resize → BGR↔RGB → per-channel normalize → HWC→NCHW → cast, no intermediate buffers.
  • Optional zero-copy Python bindings (trtcpp): feed CuPy / PyTorch / Numba GPU arrays in and get them back via __cuda_array_interface__ / DLPack — no host round-trips, GIL released during inference. See examples/python.
  • Installable. cmake --install produces a find_package(tensorrt_cpp_api)-consumable package.

Performance

Single-stream inference latency on an RTX 3080 Laptop GPU (preallocated, zero-copy enqueue loop — examples/benchmark), TensorRT 10:

Model Precision Latency Throughput
YOLOv8n FP16 1.07 ms 937 inf/s
YOLOv8n FP32 2.00 ms 499 inf/s
MobileNetV2 FP16 0.31 ms 3199 inf/s

Inference time is TensorRT-bound — it is the enqueueV3 cost of the engine itself, so the wrapper adds no measurable inference overhead. The library's work is everything around that call: zero-copy name-keyed IO with no per-call allocations or nested-vector copies, a stream-ordered allocator, and the no-throw Status/Result API. The Python bindings run the same path within ~13% of C++ (examples/python/benchmark_parity.py).

Install

TensorRT and CUDA are system/externally provided. In brief:

cmake -S . -B build -DTRT_CPP_API_BUILD_PREPROC=ON        # add -DTensorRT_DIR= for a tarball
cmake --build build -j$(nproc)
cmake --install build --prefix /opt/trtcpp

Then in a downstream project:

find_package(tensorrt_cpp_api REQUIRED)
target_link_libraries(myapp PRIVATE tensorrt_cpp_api::tensorrt_cpp_api tensorrt_cpp_api::preproc)

Python: pip install . (builds the trtcpp wheel via scikit-build-core). Full details — apt vs tarball TensorRT, build options, Python — are in docs/install.md.

Examples

examples/ has four runnable reference programs, each consuming the installed package: classification (ImageNet top-5), detection (YOLOv8n + NMS), segmentation (DeepLabV3), and a zero-copy Python demo with a C++/Python perf-parity benchmark. examples/download_models.sh fetches the models.

Documentation

Sister projects

This library is the inference backend for YOLOv8-TensorRT-CPP and YOLOv9-TensorRT-CPP (object detection, segmentation, pose).

Scope

Linux, CUDA 12, TensorRT ≥ 10, CNN-style vision models. Windows and LLM/transformer-specific features are out of scope.

Contributing

Issues and PRs welcome. Install the hooks with pre-commit install (clang-format + cmake-format); CI runs the build, the CPU test suite, sanitizers, and a Python wheel build. If this project helps you, a ⭐ is appreciated — connect on LinkedIn.

Contributors


Loic Tetrel

💻


thomaskleiven

💻


WiCyn

💻

This project follows the all-contributors specification.

License

See LICENSE. Version history is in CHANGELOG.md.

Nearby in the ranking
Similar items