24.2d NVIDIA_VISIBLE_DEVICES and NVIDIA_DRIVER_CAPABILITIES environment variables

📦 Nvidia Software Stack 📖 GPU-Accelerated Containers

🔍 Context Introduction

When you run a container with GPU access, two environment variables control which GPUs are visible and what GPU features are available inside the container. Without setting these correctly, your container may see no GPUs at all, or may crash when trying to use certain NVIDIA driver capabilities (like CUDA, NVML, or video encoding).

The NVIDIA Container Toolkit automatically sets these variables when you use the --gpus flag with Docker, but understanding them helps you troubleshoot issues and fine-tune GPU access for your workloads.


⚙️ What is NVIDIA_VISIBLE_DEVICES?

This variable tells the container which physical GPUs to expose.

  • Purpose: Controls GPU visibility inside the container.
  • Common values:
  • all — Makes all GPUs on the host available.
  • 0 — Only GPU 0 is visible.
  • 0,1 — GPUs 0 and 1 are visible.
  • none — No GPUs are visible (useful for testing).
  • void — Same as none, but prevents fallback to all.
  • Default behavior: If not set, the container sees no GPUs.

💡 Tip: Use all for most training workloads. Use specific GPU IDs for multi-container deployments where each container needs a dedicated GPU.


🛠️ What is NVIDIA_DRIVER_CAPABILITIES?

This variable defines which driver features the container can use.

  • Purpose: Controls which NVIDIA driver libraries are mounted into the container.
  • Common values:
  • compute — Allows CUDA and CUDA-related operations.
  • utility — Allows nvidia-smi and basic monitoring.
  • graphics — Enables OpenGL and Vulkan (for rendering).
  • video — Enables video encode/decode (NVENC/NVDEC).
  • display — Enables display output (rarely needed in containers).
  • all — Enables all capabilities (convenient but heavy).

  • Default behavior: If not set, the container defaults to utility only — which means CUDA will not work.

⚠️ Warning: If you run a PyTorch or TensorFlow container without setting compute, your GPU will appear as "not available" even though nvidia-smi works.


📊 Visual Representation: NVIDIA Container Runtime Environment Variables

This diagram displays the primary runtime control environment variables used to tune GPU configuration inside containers.

flowchart LR Env["Runtime Variables"] --> Visible["NVIDIA_VISIBLE_DEVICES (Select GPUs)"] Env --> Cap["NVIDIA_DRIVER_CAPABILITIES (compute,utility,video)"] Env --> Req["NVIDIA_REQUIRE_CUDA (Minimum driver version checks)"] classDef cpu fill:#eafaf1,stroke:#76b900,stroke-width:2px,rx:6px,ry:6px; classDef memory fill:#f0f7ff,stroke:#3498db,stroke-width:1.5px,rx:4px,ry:4px; classDef system fill:#f1f5f9,stroke:#64748b,stroke-width:1.5px; class Env cpu; class Visible,Cap,Req memory;

📊 Comparison Table: Common Use Cases

Use Case NVIDIA_VISIBLE_DEVICES NVIDIA_DRIVER_CAPABILITIES
🧠 Deep learning training (PyTorch/TensorFlow) all compute,utility
🎥 Video transcoding (FFmpeg with NVENC) 0 video,utility
🖥️ Remote desktop / OpenGL rendering all graphics,display,utility
🔬 CUDA development / debugging 0,1 compute,utility
📊 Monitoring only (no compute) all utility

🕵️ How They Work Together

These two variables are independent but complementary:

  • NVIDIA_VISIBLE_DEVICES decides which GPUs are seen.
  • NVIDIA_DRIVER_CAPABILITIES decides what those GPUs can do.

Example scenario:
If you set NVIDIA_VISIBLE_DEVICES=0 and NVIDIA_DRIVER_CAPABILITIES=video, then: - Only GPU 0 is visible inside the container. - That GPU can only be used for video encoding/decoding — CUDA operations will fail.


🧪 Practical Tips for New Engineers

  • Start with all for both when experimenting — it's the most permissive and least likely to cause errors.
  • Reduce scope for production — only grant the capabilities your workload actually needs (e.g., don't enable graphics for a training container).
  • Check visibility by running nvidia-smi inside the container. If it shows no GPUs, check NVIDIA_VISIBLE_DEVICES.
  • Check capabilities by running a small CUDA program. If it fails with "CUDA driver version is insufficient", check NVIDIA_DRIVER_CAPABILITIES.
  • Remember the default — if you don't set NVIDIA_DRIVER_CAPABILITIES, you get utility only. Always set it explicitly for compute workloads.

✅ Summary

Variable Controls Common Value for AI Workloads
NVIDIA_VISIBLE_DEVICES Which GPUs are visible all
NVIDIA_DRIVER_CAPABILITIES Which driver features are available compute,utility

These two environment variables are the gatekeepers of GPU access in containers. Mastering them will save you hours of debugging when your GPU-accelerated application doesn't work as expected.