Skip to content

Enable GPU if available in Makefile#171

Merged
ericcurtin merged 1 commit intomainfrom
Makefile-changes
Sep 29, 2025
Merged

Enable GPU if available in Makefile#171
ericcurtin merged 1 commit intomainfrom
Makefile-changes

Conversation

@ericcurtin
Copy link
Contributor

@ericcurtin ericcurtin commented Sep 24, 2025

Also some podman-compatibility fixes, trying to compare why GPU access works in podman and not docker and vice versa for debugging reasons.

Summary by Sourcery

Enable GPU device passthrough in the Makefile and improve podman compatibility in the Dockerfile

Enhancements:

  • Add TARGETARCH build argument and update FROM references to include the docker.io registry for multi-architecture and podman compatibility
  • Detect /dev/dri in the Makefile and pass the GPU device flag to docker-run if available

Copilot AI review requested due to automatic review settings September 24, 2025 21:44
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 24, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR enhances GPU support by adding conditional host /dev/dri mapping in the Makefile, parameterizes the target architecture for selecting the correct Llama server binary, and standardizes Docker image references to docker.io for improved Podman and Docker compatibility.

Class diagram for Makefile variables and Dockerfile ARGs

classDiagram
  class Makefile {
    BASE_IMAGE : string
    DOCKER_IMAGE : string
    PORT : int
    MODELS_PATH : string
    GPU_DEVICE_FLAG : string
    LLAMA_ARGS : string
  }
  class Dockerfile {
    GO_VERSION : string
    LLAMA_SERVER_VERSION : string
    LLAMA_SERVER_VARIANT : string
    TARGETARCH : string
    LLAMA_BINARY_PATH : string
    BASE_IMAGE : string
  }
  Makefile --> Dockerfile : "Uses Dockerfile ARGs in build/run"
  Makefile : +docker-run()
  Dockerfile : +builder stage
  Dockerfile : +llama-server stage
  Dockerfile : +final stage
Loading

File-Level Changes

Change Details Files
Unified Docker image references to docker.io for consistent Podman and Docker compatibility
  • Prefixed builder and final stage base images with docker.io
  • Updated FROM golang image to use docker.io/library/golang
  • Updated BASE_IMAGE reference to docker.io prefix in final stage
Dockerfile
Parameterized target architecture for Llama server binary path
  • Introduced TARGETARCH build argument defaulting to BUILDARCH
  • Incorporated TARGETARCH into LLAMA_BINARY_PATH
Dockerfile
Enabled GPU device mapping in Makefile if /dev/dri exists
  • Added GPU_DEVICE_FLAG variable checking for /dev/dri
  • Injected GPU_DEVICE_FLAG into docker-run command arguments
Makefile

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
Contributor

Summary of Changes

Hello @ericcurtin, 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 build and runtime environment by enabling automatic GPU detection and utilization within Docker containers, and improves container runtime compatibility by explicitly defining image registry paths in the Dockerfile. These changes aim to streamline development and debugging, particularly when comparing GPU access behavior between Docker and Podman.

Highlights

  • GPU Auto-detection: The Makefile now includes logic to automatically detect the presence of a GPU (by checking for /dev/dri) and pass the appropriate --device /dev/dri flag to Docker when running the container, enabling GPU acceleration if available.
  • Explicit Docker Image Paths: The Dockerfile has been updated to use fully qualified image names (e.g., docker.io/library/golang) for base images, which can improve compatibility across different container runtimes, including Podman.
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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables GPU access for the Docker container when GPU devices are available and includes podman-compatibility improvements. The changes allow the application to leverage GPU acceleration when the hardware is present while maintaining compatibility with different container runtimes.

Key changes:

  • Auto-detection of GPU devices in the Makefile to conditionally pass GPU flags
  • Addition of podman-compatible image references in the Dockerfile
  • Architecture variable initialization for better cross-platform support

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Makefile Adds GPU device detection and conditional GPU flag passing to docker run command
Dockerfile Updates image references for podman compatibility and adds TARGETARCH variable initialization

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@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!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `Makefile:10` </location>
<code_context>
 DOCKER_IMAGE := docker/model-runner:latest
 PORT := 8080
 MODELS_PATH := $(shell pwd)/models-store
+GPU_DEVICE_FLAG := $(shell if [ -d /dev/dri ]; then echo "--device /dev/dri"; fi)
 LLAMA_ARGS ?=

</code_context>

<issue_to_address>
**suggestion:** GPU_DEVICE_FLAG only checks for /dev/dri, which may not cover all GPU device scenarios.

This logic may not detect all GPU types, such as NVIDIA devices under /dev/nvidia*. Please update to support a wider range of GPU hardware.

```suggestion
GPU_DEVICE_FLAG := $(shell \
    FLAGS=""; \
    if [ -d /dev/dri ]; then FLAGS="$$FLAGS --device /dev/dri"; fi; \
    if ls /dev/nvidia* 1>/dev/null 2>&1; then \
        for dev in /dev/nvidia*; do \
            FLAGS="$$FLAGS --device $$dev"; \
        done; \
    fi; \
    echo "$$FLAGS" \
)
```
</issue_to_address>

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
Contributor

@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 introduces GPU support by passing through the device to the Docker container and improves podman compatibility by using fully qualified image names in the Dockerfile. The changes are a good step forward. My main feedback is to make the GPU detection in the Makefile more robust by adding support for NVIDIA GPUs, which are common for AI/ML workloads. The current implementation only supports GPUs using /dev/dri (like Intel/AMD). I've provided a specific suggestion to improve this.

@ericcurtin ericcurtin force-pushed the Makefile-changes branch 2 times, most recently from eefca6e to 77999fe Compare September 24, 2025 21:50
Copilot AI review requested due to automatic review settings September 24, 2025 21:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings September 24, 2025 22:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings September 25, 2025 00:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI review requested due to automatic review settings September 25, 2025 00:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Also some podman-compatibility fixes, trying to compare why GPU
access works in podman and not docker and vice versa for debugging
reasons.

Also, make "docker run" a shell script, mainly so we can run
shellcheck on it.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin
Copy link
Contributor Author

This ready for re-review @doringeman

Copy link

@p1-0tr p1-0tr left a comment

Choose a reason for hiding this comment

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

LGTM

@ericcurtin ericcurtin merged commit dafd755 into main Sep 29, 2025
5 checks passed
@ericcurtin ericcurtin deleted the Makefile-changes branch September 29, 2025 08:33
@doringeman
Copy link
Contributor

Tiny fix here: #187.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants