Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass ASAHI, CUDA, HIP, HSA prefixed env vars to container #526

Merged
merged 2 commits into from
Dec 29, 2024

Conversation

abn
Copy link
Contributor

@abn abn commented Dec 28, 2024

Relates-to: #525

Summary by Sourcery

Build:

  • Pass environment variables prefixed with ASAHI, CUDA, HIP, and HSA to the container via get_env_vars.

Copy link
Contributor

sourcery-ai bot commented Dec 28, 2024

Reviewer's Guide by Sourcery

This pull request introduces a change to pass environment variables prefixed with ASAHI, CUDA, HIP, and HSA to the container. It also refactors the code to determine the GPU type and number.

Sequence diagram for container setup with GPU environment variables

sequenceDiagram
    participant C as Container Setup
    participant G as get_env_vars()
    participant GPU as get_gpu()
    participant OS as Operating System

    C->>G: Call get_env_vars()
    G->>GPU: Call get_gpu()
    GPU->>OS: Check /sys/bus/pci/devices for GPU info
    OS-->>GPU: Return GPU memory info
    alt GPU found
        GPU-->>G: Return GPU type and number
    else No GPU found
        GPU->>OS: Check /etc/os-release
        OS-->>GPU: Return OS info
        GPU-->>G: Return Asahi or null
    end
    G->>OS: Get environment variables
    OS-->>G: Return matching env vars
    G-->>C: Return GPU and env vars
Loading

Class diagram for GPU environment handling

classDiagram
    class Common {
        +get_gpu(): Tuple[str, int]
        +get_env_vars(): Dict[str, str]
        +engine_version(engine: str): str
    }

    class Kube {
        -_gen_env_vars(): str
        +generate()
    }

    class Quadlet {
        +generate()
    }

    Kube ..> Common: uses
    Quadlet ..> Common: uses
    note for Common "Centralized GPU and env var handling"
Loading

File-Level Changes

Change Details Files
Environment variables with specific prefixes are now passed into the container.
  • Added get_env_vars function to retrieve environment variables with prefixes ASAHI, CUDA, HIP, and HSA.
  • Modified setup_container to pass retrieved environment variables to the container.
  • Added tests to verify environment variable passing.
  • Updated quadlet and kube generation to include environment variables.
ramalama/common.py
ramalama/model.py
ramalama/quadlet.py
ramalama/kube.py
test/system/030-run.bats
test/system/040-serve.bats
Refactored GPU handling logic.
  • Moved get_gpu function from model.py to common.py.
  • Removed duplicate get_gpu function from model.py.
ramalama/common.py
ramalama/model.py

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@ericcurtin
Copy link
Collaborator

I think this is fine, but we have to be mindful of the generators for Quadlet, etc. to ensure the env vars get taken into account there also

@abn
Copy link
Contributor Author

abn commented Dec 28, 2024

I will push up a change to include those as well.

@abn
Copy link
Contributor Author

abn commented Dec 28, 2024

@ericcurtin I am curious however, if the better change is to enable explicit --env | -e option for the serve command instead. But if the generated files are always expected to be used on the local machine, this should be fine I reckon.

@abn
Copy link
Contributor Author

abn commented Dec 28, 2024

@sourcery-ai review

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 @abn - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

test/system/030-run.bats Show resolved Hide resolved
@ericcurtin ericcurtin merged commit 542ef33 into containers:main Dec 29, 2024
11 checks passed
@abn abn deleted the pass-env-vars branch December 29, 2024 21:03
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.

2 participants