Build ROCm XGBoost from source

Build ROCm XGBoost from source#

2026-02-05

3 min read time

Applies to Linux

Prerequisites#

Before proceeding, ensure that you have installed a supported ROCm version, operating system, and Python environment that are compatible with the ROCm-Finance libraries. Verify that your system includes a supported AMD Instinct GPU. For guidance, see ROCm-Finance installation prerequisites.

For a consistent and streamlined setup experience, it’s recommended to use a ROCm development environment Docker container. See Install ROCm-Finance for instructions.

Build from source#

  1. Install required software dependencies.

    RUN apt-get update && apt-get install -y --no-install-recommends git libomp-dev python3-venv curl ca-certificates gpg wget
    RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
    RUN echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
    RUN apt-get update
    RUN apt-get install -y cmake libgtest-dev libgmock-dev
    
  2. Clone the ROCm/xgboost source code from GitHub.

    git clone --recurse-submodules https://github.com/rocm/xgboost.git
    
  3. Create and activate a Python virtual environment.

    python -m venv xgboost-build
    source xgboost-build/bin/activate
    
  4. Build the shared object library.

    # Set the GPU target
    export AMDGPU_TARGETS="gfx942"
    export CMAKE_PREFIX_PATH=/opt/rocm/lib/cmake/
    export CMAKE_MODULE_PATH=/opt/rocm/lib/cmake
    export CMAKE_POLICY_VERSION_MINIMUM=3.5
    export CMAKE_C_COMPILER=hipcc
    export CMAKE_CXX_COMPILER=hipcc
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib/llvm/lib/
    export LDFLAGS="-L/opt/rocm/lib -Wl,-rpath,/opt/rocm/lib"
    
    cd xgboost
    cmake -DUSE_HIP=1 -DUSE_RCCL=1 -DGOOGLE_TEST=1 -S . -B build
    cmake --build build -- -j 8
    
  5. Build and install the Python package.

    cd python-package
    pip install setuptools pytest build wheel
    python3 -m build --wheel .
    pip install dist/amd_xgboost*.whl
    
  6. Verify the installation.

    pip show amd_xgboost
    
  7. Install dependencies.

    pip install pytest joblib hypothesis scikit-learn rich fastrlock cachetools fsspec packaging \
      numba==0.60 pandas==2.2.3 pyarrow==19.0 typing-extensions>=4.0.0
    pip install amd-cupy amd-hipdf --index-url=https://pypi.amd.com/rocm-7.1.1/simple/
    
    pip install pytest joblib hypothesis scikit-learn rich fastrlock cachetools fsspec packaging \
      numba==0.60 pandas==2.2.3 pyarrow==19.0 typing-extensions>=4.0.0
    pip install amd-cupy amd-hipdf --index-url=https://pypi.amd.com/rocm-7.0.2/simple/
    
    pip install pytest joblib hypothesis scikit-learn rich fastrlock cachetools fsspec packaging
    pip install amd-cupy amd-hipdf --extra-index-url=https://pypi.amd.com/simple/
    
  8. Run the Python examples.

    pytest tests/python-gpu