Skip to main content
The CUDA execution provider enables high-performance inference on NVIDIA GPUs with optimized kernels for generative AI workloads.

Requirements

Hardware

  • NVIDIA GPU with Compute Capability 6.0 or higher
  • Recommended: RTX 20 series or newer for optimal performance
  • Minimum: 4GB GPU memory (varies by model size)

Software

  • CUDA Toolkit 11.8 or 12.x
  • cuDNN 8.x or later
  • NVIDIA driver 520.61.05 or newer (Linux) / 528.33 or newer (Windows)
The CUDA provider is included in the onnxruntime-genai-cuda package.

Installation

Basic Configuration

Python API

genai_config.json

Configure CUDA in your model configuration:

GPU Memory Management

Memory Allocation

The CUDA provider uses ONNX Runtime’s allocator for GPU memory:
GPU Memory Limit: Set gpu_mem_limit to restrict CUDA memory usage (in bytes). This is useful for multi-tenant scenarios.

KV Cache Management

ONNX Runtime GenAI optimizes key-value cache management:
When using beam search (num_beams > 1), past_present_share_buffer must be set to False. CUDA graph is also incompatible with beam search.

Performance Tuning

CUDA Graph Optimization

Enable CUDA graphs to reduce kernel launch overhead:
CUDA graphs are only compatible with greedy search (num_beams=1). Disable for beam search scenarios.

Multi-Profile Support

Optimize for multiple sequence lengths:

Stream Configuration

The CUDA provider uses a dedicated stream for async operations. Memory transfers are optimized using pinned host memory:

Precision Options

FP16 Inference

The CUDA provider supports FP16 for reduced memory and faster inference:
  • Memory: Higher usage
  • Speed: Baseline performance
  • Precision: Full precision
  • Hardware: All CUDA GPUs

Advanced Configuration

Device Selection

Select a specific GPU in multi-GPU systems:

Session Options

Fine-tune ONNX Runtime session settings:

Troubleshooting

Out of Memory Errors

Performance Issues

Switch to FP16 model variants for Tensor Core acceleration.

Driver Compatibility

Verify CUDA installation:

Benchmarking

Next Steps

Model Optimization

Optimize models for CUDA deployment

Memory Management

Learn advanced memory techniques