Created
August 31, 2026 16:42
-
-
Save brand-it/4f8fdae9e13bfdc6e5481d30178bd8e6 to your computer and use it in GitHub Desktop.
A script I use to quickly build llama.cpp for nvidia spark dgx- NCCL enabled. can run multiple times to update server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| LLAMA_DIR="$HOME/llama.cpp" | |
| # 1. Clone or update | |
| cd "$HOME" | |
| if [ ! -d "$LLAMA_DIR/.git" ]; then | |
| echo "=== Cloning llama.cpp (first time) ===" | |
| git clone --depth 1 https://github.com/ggml-org/llama.cpp.git "$LLAMA_DIR" | |
| else | |
| echo "=== Updating llama.cpp ===" | |
| cd "$LLAMA_DIR" | |
| git pull | |
| fi | |
| cd "$LLAMA_DIR" | |
| # 2. Clean previous builds | |
| echo "Cleaning up old build cache..." | |
| rm -rf build build-cuda CMakeCache.txt CMakeFiles cmake_install.cmake | |
| # 3. Locate NCCL — find the real header + lib, not a guessed path. | |
| # NCCL's Makefile build lands headers in build/include and libs in build/lib. | |
| # Prefer that; fall back to a system install (e.g. /usr/local) if present. | |
| NCCL_H="" | |
| NCCL_LIB="" | |
| for root in "$HOME/nccl" /usr/local /usr; do | |
| if [[ -z "$NCCL_H" ]]; then | |
| NCCL_H=$(find "$root" -name 'nccl.h' -path '*/include/*' 2>/dev/null | head -1 || true) | |
| fi | |
| if [[ -z "$NCCL_LIB" ]]; then | |
| NCCL_LIB=$(find "$root" -name 'libnccl.so' 2>/dev/null | head -1 || true) | |
| fi | |
| [[ -n "$NCCL_H" && -n "$NCCL_LIB" ]] && break | |
| done | |
| if [[ -n "$NCCL_H" && -n "$NCCL_LIB" ]]; then | |
| NCCL_INC_DIR=$(dirname "$NCCL_H") | |
| NCCL_LIB_DIR=$(dirname "$NCCL_LIB") | |
| echo "NCCL header: $NCCL_H" | |
| echo "NCCL lib: $NCCL_LIB" | |
| NCCL_FLAGS="-DNCCL_LIBRARY=$NCCL_LIB -DNCCL_INCLUDE_DIR=$NCCL_INC_DIR" | |
| else | |
| NCCL_FLAGS="" | |
| echo "Warning: NCCL not found — building without NCCL (set up ~/nccl first)" | |
| fi | |
| # 4. Configure for Blackwell + NCCL | |
| echo "Configuring CMake (CUDA, FA, MoE, NCCL)..." | |
| cmake -B build \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DGGML_CUDA=ON \ | |
| -DGGML_CUDA_FA=ON \ | |
| -DGGML_MOE=ON \ | |
| -DGGML_CUDA_NCCL=ON \ | |
| $NCCL_FLAGS | |
| # 5. Compile | |
| echo "Compiling llama-server + llama-bench..." | |
| cmake --build build -j --target llama-server llama-bench | |
| # 6. Verify | |
| echo "=== Build complete ===" | |
| ./build/bin/llama-server --version | head -1 | |
| # 7. Set up runtime env for NCCL (only if we found it) | |
| if [[ -n "$NCCL_LIB_DIR" ]]; then | |
| cat > "$HOME/.nccl_env" <<EOF | |
| export LD_LIBRARY_PATH="$NCCL_LIB_DIR:/usr/local/cuda/lib64:${LD_LIBRARY_PATH}" | |
| export NCCL_DEBUG=INFO | |
| EOF | |
| echo "Runtime env written to ~/.nccl_env (source it before running multi-GPU)" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment