Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Conversation

@ekcasey
Copy link
Contributor

@ekcasey ekcasey commented Sep 25, 2025

With Docker 19.03+, NVIDIA Container Toolkit integrates via an OCI prestart hook instead of a separate nvidia runtime. When checking for CUDA support, assume existence of the runtime hook (nvidia-container-runtime) on the path indicates CUDA support.

Older setups with nvidia-docker2 we may still require --runtime=nvidia. Check for this when creating the containers and only supply --runtime=nvidia when such a runtime is available. Assume the existence of the runtime also implies CUDA support.

Summary by Sourcery

Enhance GPU support detection to handle both Docker 19.03+ prestart hook integration and legacy nvidia runtime configurations

Enhancements:

  • ProbeGPUSupport now first checks for the nvidia-container-runtime binary on PATH and assumes CUDA support if found
  • Extract HasNVIDIARuntime helper to query the Docker engine for an "nvidia" runtime
  • Conditionally set hostConfig.Runtime to "nvidia" in container creation only when the nvidia runtime is actually available

In Docker 19.03+ NVIDIA Container Toolkit can integrates via an OCI prestart hook
instead of requiring  to be listed as a separate runtime.

Signed-off-by: Emily Casey <[email protected]>
Docker may support CUDA GPUs without explicit nvidia runtime.

Signed-off-by: Emily Casey <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 25, 2025

Reviewer's Guide

The PR enhances CUDA support detection by first checking for the nvidia-container-runtime binary, then falling back to an existing nvidia runtime via the Docker API, and updates container creation to only apply the nvidia runtime when available.

Sequence diagram for improved CUDA support detection

sequenceDiagram
    participant Caller
    participant "ProbeGPUSupport()"
    participant "exec.LookPath('nvidia-container-runtime')"
    participant "HasNVIDIARuntime()"
    participant "dockerClient.Info()"
    Caller->>"ProbeGPUSupport()": call
    "ProbeGPUSupport()"->>"exec.LookPath('nvidia-container-runtime')": check for binary
    alt Binary found
        "ProbeGPUSupport()"-->>Caller: return GPUSupportCUDA
    else Binary not found
        "ProbeGPUSupport()"->>"HasNVIDIARuntime()": check for runtime
        "HasNVIDIARuntime()"->>"dockerClient.Info()": get info
        "dockerClient.Info()"-->>"HasNVIDIARuntime()": info
        alt Runtime found
            "HasNVIDIARuntime()"-->>"ProbeGPUSupport()": true
            "ProbeGPUSupport()"-->>Caller: return GPUSupportCUDA
        else Runtime not found
            "HasNVIDIARuntime()"-->>"ProbeGPUSupport()": false
            "ProbeGPUSupport()"-->>Caller: return GPUSupportNone
        end
    end
Loading

File-Level Changes

Change Details Files
Enhance CUDA support detection with binary and runtime checks
  • Use exec.LookPath to detect nvidia-container-runtime on PATH
  • Extract HasNVIDIARuntime helper to inspect info.Runtimes from Docker
  • Refactor ProbeGPUSupport to return CUDA support based on these checks
pkg/gpu/gpu.go
Conditionally set Docker runtime for GPU containers
  • Invoke HasNVIDIARuntime in CreateControllerContainer before assigning hostConfig.Runtime
  • Wrap runtime assignment in an if-check to avoid unnecessary --runtime flags
pkg/standalone/containers.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link

Summary of Changes

Hello @ekcasey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's ability to detect and utilize CUDA GPU support across various Docker configurations. It introduces a more adaptive detection mechanism that prioritizes modern Docker 19.03+ setups using OCI hooks, while still supporting older environments that rely on the explicit nvidia runtime. This ensures that GPU capabilities are correctly identified and applied during container creation, improving compatibility and robustness.

Highlights

  • Improved CUDA Detection Logic: The ProbeGPUSupport function now first checks for the presence of nvidia-container-runtime on the system's PATH, which is indicative of CUDA support in modern Docker 19.03+ environments using OCI prestart hooks.
  • Refactored NVIDIA Runtime Check: A new helper function, HasNVIDIARuntime, has been introduced to explicitly check for the nvidia runtime configuration within the Docker daemon, centralizing this logic.
  • Conditional NVIDIA Runtime Assignment: When creating containers, the hostConfig.Runtime is now conditionally set to 'nvidia' only if the nvidia runtime is explicitly available, preventing potential issues on systems where CUDA support is provided via OCI hooks rather than a dedicated runtime.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves CUDA detection by first checking for nvidia-container-runtime on the system's PATH, which is the modern approach for Docker 19.03+, and then falls back to checking for a configured nvidia runtime for older setups. The logic for creating containers is also updated to only specify --runtime=nvidia when that runtime is actually available. The changes are well-reasoned and correctly implement the described logic. I have one suggestion to improve error handling by logging a warning if checking for the nvidia runtime fails, rather than silently ignoring the error.

Comment on lines +271 to +273
if ok, err := gpupkg.HasNVIDIARuntime(ctx, dockerClient); err == nil && ok {
hostConfig.Runtime = "nvidia"
}

Choose a reason for hiding this comment

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

medium

The current implementation silently ignores any error returned from gpupkg.HasNVIDIARuntime. While the logic correctly avoids setting the nvidia runtime in case of an error, it would be better to log a warning to inform the user that the check failed. This could help in debugging issues where GPU support is expected but not working correctly.

		if ok, err := gpupkg.HasNVIDIARuntime(ctx, dockerClient); err != nil {
			printer.Printf("Warning: failed to check for nvidia runtime: %v\n", err)
		} else if ok {
			hostConfig.Runtime = "nvidia"
		}

@ericcurtin ericcurtin merged commit cf549c5 into main Sep 26, 2025
8 checks passed
@ericcurtin ericcurtin deleted the cuda-detection branch September 26, 2025 10:09
Copy link
Contributor

@xenoscopic xenoscopic left a comment

Choose a reason for hiding this comment

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

Late to the party, but LGTM!

@ericcurtin
Copy link
Contributor

I will say this CUDA detection can be hard to get 100% right, there probably should be an option to manually specify CUDA (and in future, Vulkan, etc.).

And sometimes people want to specifically use a certain backend. There was a group of people I was working with at Ampere for example that wanted to do CPU inferencing rather than use the Nvidia GPU.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants