Skip to main content

Trench-Mark

PyPI version License: MIT Platform

Trench-Mark is an automated, hardware-safe TensorRT benchmarking and deployment CLI designed specifically for resource-constrained NVIDIA Jetson edge devices (Orin Nano, Orin NX, Xavier, AGX).

The tool automates the evaluation loop: compiling hardware-fused TensorRT engines without triggering Out-Of-Memory (OOM) crashes, and collecting microsecond-accurate GPU execution telemetry alongside peak unified memory consumption.


Key Capabilities

  • OOM-Safe Engine Compilation: Caps workspace limits and redirects intermediate build artifacts directly to physical disk storage, preventing the Linux kernel from killing processes on unified memory hardware.
  • Pure Compute Telemetry: Uses native CUDA hardware events with isolated PCIe data transfers to measure pure GPU execution time without host-to-device transfer noise.
  • Hardware Telemetry: Polls the Tegra kernel interface asynchronously in a dedicated monitoring thread to log real-time unified memory spikes.
  • True Throughput Metrics: Automatically translates raw TensorRT Queries Per Second (QPS) into True Frame Throughput (FPS = QPS * Batch Size).

Installation

From PyPI

pip install trench_mark

System Prerequisites

  • NVIDIA Jetson running JetPack 5.x or JetPack 6.x
  • TensorRT and trtexec installed and accessible in system $PATH
  • Python 3.8+
  • ultralytics package (for exporting YOLO models)

Quick Start

Step 1: Export the YOLO Model to ONNX

Before running Trench-Mark, you must export your YOLO model to the ONNX format with dynamic batching enabled. Run the following command in your terminal:

yolo export model=yolov8n.pt format=onnx opset=12 dynamic=True

Step 2: Run the Benchmark

Once the .onnx file is generated, pass it to Trench-Mark. Profile the model across batch sizes 1, 4, and 8 for FP32, FP16, and INT8:

sudo trench-mark -m yolov8n.onnx -b 1 4 8 -p fp32 fp16 int8

Running with sudo is recommended so the background monitoring thread has permission to poll the tegrastats kernel interface.


CLI Reference

trench-mark [-h] -m MODEL [-s INPUT_SHAPE] [--input-name INPUT_NAME]
            [-p {fp32,fp16,int8} [{fp32,fp16,int8} ...]]
            [-b BATCH_SIZES [BATCH_SIZES ...]] [-i ITERATIONS]
            [-w WARMUP] [--workspace WORKSPACE]

Parameter Breakdown

Flag Type Default Description
-m, --model str Required Local path to the exported .onnx file.
-s, --input-shape str 3x640x640 Single image tensor dimensions in Channel x Height x Width format (CHW).
--input-name str images Name of the primary input node inside the ONNX graph. Ultralytics YOLO models default to images.
-p, --precisions list fp32 fp16 int8 Precision modes to compile and test. Supported values: fp32, fp16, int8.
-b, --batch-sizes int 1 4 8 Space-separated list of dynamic batch sizes to evaluate sequentially.
-i, --iterations int 500 Number of execution cycles per test to ensure statistical stability.
-w, --warmup int 50 Hardware pre-conditioning window in milliseconds to stabilize GPU clock speeds.
--workspace int 2048 Maximum memory pool allocated to TensorRT tactic selection in megabytes (MB).

Common Use Cases

1. High-Resolution Model Evaluation

To test higher input resolutions (such as 1280x1280), make sure to export your model at that resolution first, then run:

sudo trench-mark -m yolov8s_highres.onnx -s 3x1280x1280 -b 1 2 -p fp16

2. Rapid Single-Frame Latency Testing

To verify real-time response time on batch size 1 with fewer iterations:

sudo trench-mark -m yolov8n.onnx -b 1 -p fp16 int8 -i 200

Understanding Output Metrics

Precision  | Batch   | Latency (ms)    | Throughput (FPS)   | Peak RAM (MB)
---------------------------------------------------------------------------
FP16       | 1       | 6.79            | 147.20             | 5328
FP16       | 4       | 24.88           | 160.76             | 5497
FP16       | 8       | 47.77           | 167.44             | 5345
  • Latency (ms): The mean hardware compute time required to execute the entire batch on the GPU. Batch 1 represents your single-frame reaction time.
  • Throughput (FPS): Represents True Frames Per Second, calculated as QPS * Batch Size. Increasing batch size allows Tensor Cores to process multiple images per kernel launch, improving overall pipeline throughput at the expense of per-batch latency.
  • Peak RAM (MB): The maximum unified memory footprint captured by tegrastats. TensorRT INT8 and FP16 tactics often allocate larger scratchpad memory pools to accelerate matrix operations on Tensor Cores.

Memory Safety and Jetson Optimization

  1. Workspace Boundary: The --workspace 2048 flag restricts the builder memory pool to 2GB. This prevents TensorRT from consuming all unified RAM during tactic autotuning and crashing the host Linux system.
  2. Temporary Disk Allocation: Engine compilation directs temporary intermediate files directly to disk rather than holding them in memory.
  3. Swap Memory Recommended: When building larger models on 8GB Orin Nano boards, verify you have configured an SSD swap file:
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
  1. Execution Audit Logs: Every run writes a full trace containing system metadata, environment flags, and raw command logs to ./logs/benchmark_<TIMESTAMP>.log.

Troubleshooting

Corrupted 0-Byte Engines

If an engine build aborts unexpectedly, TensorRT may leave behind an empty 0-byte file. Trench-Mark checks file sizes before benchmarking and marks corrupted engines for recompilation. To manually clean your engine cache, run:

rm -rf models/*.engine trt.cache

Shape Profile Violations

If a test fails with shape dimension errors, the requested batch size exceeds the upper limit built into the cached engine. Delete the older engine file or use the automatic versioned naming convention so a new profile covering the higher batch size can be compiled.


License

This project is licensed under the MIT License. See the LICENSE file for full terms.

Metadata

Release files for trench-mark 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trench-mark 1.0.6
File Size Uploaded Provenance Actions
trench_mark-1.0.6.tar.gz 29.3 kB Without provenance Details for trench_mark-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trench-mark 1.0.6
File Interpreter ABI Platform Actions
trench_mark-1.0.6-py3-none-any.whl Python 3 none any Details for trench_mark-1.0.6-py3-none-any.whl

Total release size: 54.4 kB

Release files / trench_mark-1.0.6.tar.gz

Download URL trench_mark-1.0.6.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
65c6424fdeb53724f1991c7c6c9b4249bb6595f5623dfb6b612702e465f43de8
BLAKE2b-256 checksum
How to use checksums
fad938744adab9b7864c1b472f27ea2c8f4442c563411922b1dc6348f6cdf3e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / trench_mark-1.0.6-py3-none-any.whl

Download URL trench_mark-1.0.6-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b70f6c7961dfcb29283afe28d2a472a9b8ab44bc396a43db416a6b76dc3c6a9
BLAKE2b-256 checksum
How to use checksums
e6018715473011178d2b1544d9b4df05e7fff3f88e7da29a9fda0b9354854d71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for trench-mark 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page