Skip to content

Add ROCm (AMD GPU) support to studio setup#4583

Closed
danielhanchen wants to merge 1 commit into
mainfrom
rocm-studio-support-v2
Closed

Add ROCm (AMD GPU) support to studio setup#4583
danielhanchen wants to merge 1 commit into
mainfrom
rocm-studio-support-v2

Conversation

@danielhanchen
Copy link
Copy Markdown
Member

Summary

Adds AMD ROCm GPU detection to the llama.cpp build step in studio/setup.sh, based on the work in #4390 by @edamamez, rebased onto current main with bug fixes.

  • Detects ROCm via hipcc (PATH, /opt/rocm/bin, /opt/rocm-*/bin) only when no CUDA toolchain is present
  • Resolves the real ROCm root via readlink -f on hipcc and hipconfig -R (fixes the symlink/variable-collision bug from Add support for ROCm in Studio setup #4390)
  • Sets ROCM_PATH and HIP_PATH for cmake
  • Uses HIPCXX via hipconfig -l instead of legacy CMAKE_C_COMPILER=hipcc (fixes upstream deprecation warning)
  • Auto-detects gfx architecture via rocminfo with tightened regex (gfx[0-9]{3,4})
  • Adds ROCm-specific driver-only and CPU-only fallback messages
  • CUDA detection is unchanged and takes priority on mixed-toolchain hosts

Changes are limited to the GPU detection block in studio/setup.sh (71 lines added, 4 lines modified).

Bugs fixed vs #4390

  1. ROCM_PATH symlink bug [8/8 reviewers]: Original PR set ROCM_PATH to the hipcc binary path instead of the ROCm root directory
  2. Legacy hipcc compiler [7/8 reviewers]: Original PR used -DCMAKE_C_COMPILER=hipcc which is deprecated upstream
  3. HIP_PATH not set [2/8 reviewers]: Some ROCm builds need HIP_PATH exported alongside ROCM_PATH

Test plan

  • Verified all 6 GPU detection code paths pass (CUDA-only, ROCm-only, both/CUDA-wins, CPU-only, CUDA-driver-only, ROCm-driver-only)
  • Confirmed git diff origin/main touches only studio/setup.sh
  • Confirmed main features preserved (run_quiet_no_exit, _SKIP_GGUF_BUILD, uv/fast_install, WSL handling)

Add GPU backend detection for ROCm alongside existing CUDA support in
the llama.cpp build step. When hipcc is found and no CUDA toolchain is
present, the build uses GGML_HIP=ON with proper ROCm root resolution
via readlink/hipconfig, sets ROCM_PATH and HIP_PATH, uses the
upstream-recommended HIPCXX compiler path, and auto-detects the gfx
architecture via rocminfo.

CUDA detection is unchanged and takes priority on mixed-toolchain hosts.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly enhances the studio/setup.sh script by integrating robust AMD ROCm GPU support for llama.cpp builds. It introduces a comprehensive detection mechanism for ROCm toolchains, prioritizing CUDA when both are present, and correctly configures environment variables and CMake arguments. The changes also resolve several issues identified in a previous attempt, ensuring accurate ROCm root detection, proper compiler usage, and architecture auto-detection, thereby expanding GPU acceleration capabilities for users with AMD hardware.

Highlights

  • ROCm GPU Detection: Added comprehensive AMD ROCm GPU detection to the studio/setup.sh script, prioritizing CUDA when both toolchains are present.
  • ROCm Root Resolution: Implemented robust logic to resolve the real ROCm root directory using readlink -f on hipcc and hipconfig -R, fixing a symlink bug from a previous PR.
  • Environment Variable Configuration: Ensured correct ROCM_PATH and HIP_PATH environment variables are set for CMake, addressing a missing HIP_PATH issue.
  • Modern HIP Compiler Usage: Switched to using HIPCXX via hipconfig -l for the HIP compiler, moving away from the deprecated CMAKE_C_COMPILER=hipcc method.
  • AMD GPU Architecture Auto-detection: Integrated auto-detection of AMD GPU architectures (gfx targets) using rocminfo with a tightened regex, allowing for optimized builds.
  • Improved Fallback Messages: Added specific fallback messages for CPU-only builds when only ROCm or CUDA drivers are detected without their respective compilers.
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.

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
Copy Markdown
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 enhances the studio/setup.sh script to include support for AMD ROCm GPUs, in addition to the existing NVIDIA CUDA support. The script now intelligently detects either CUDA or ROCm, configuring the build process accordingly. For ROCm, it sets GGML_HIP and exports necessary environment variables like ROCM_PATH and HIP_PATH, and attempts to detect specific AMD GPU architectures for targeted compilation. A review comment suggests an improvement to ensure that the directory containing hipcc is consistently added to the PATH to guarantee that all related ROCm tools, such as hipconfig and rocminfo, are discoverable during the build process.

Comment thread studio/setup.sh
export PATH="$(dirname "$ROCM_HIPCC"):$PATH"
GPU_BACKEND="rocm"
fi
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The script correctly adds the hipcc directory to PATH when hipcc is found in specific /opt/rocm locations. However, if hipcc is found via command -v hipcc (meaning it's already in the system's PATH), its directory is not explicitly added to PATH by the script. This could lead to hipconfig or rocminfo not being found later if they reside in the same hipcc directory but that directory is not fully covered by the existing PATH for all necessary ROCm tools. Explicitly adding the hipcc directory to PATH after its discovery ensures all related ROCm tools are discoverable for subsequent commands, regardless of how hipcc was initially found.

Suggested change
fi
# Ensure the directory containing hipcc is in PATH for hipconfig/rocminfo
if [ -n "$ROCM_HIPCC" ]; then
_HIPCC_DIR="$(dirname "$ROCM_HIPCC")"
# Only add if not already in PATH to avoid duplicates
[[ ":$PATH:" != *":$_HIPCC_DIR:"* ]] && export PATH="$_HIPCC_DIR:$PATH"
fi

@danielhanchen
Copy link
Copy Markdown
Member Author

Superseded by a new PR that preserves the original contributor's git history.

@danielhanchen danielhanchen deleted the rocm-studio-support-v2 branch March 25, 2026 10:54
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.

1 participant