1+ #! /bin/bash
2+
3+ set -e
4+
5+ echo " === llama.cpp GFX906 Benchmark Script ==="
6+ echo
7+
8+ # Colors for output
9+ RED=' \033[0;31m'
10+ GREEN=' \033[0;32m'
11+ YELLOW=' \033[1;33m'
12+ NC=' \033[0m' # No Color
13+
14+ # Step 1: Update submodules
15+ echo -e " ${GREEN} [1/4] Updating submodules...${NC} "
16+ git submodule update --init --recursive
17+
18+ # Step 2: Build the project with GFX906 support
19+ echo -e " ${GREEN} [2/4] Building llama.cpp with GFX906 support...${NC} "
20+ cmake -B build -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx906 -DCMAKE_BUILD_TYPE=Release
21+ cmake --build build --config Release -j$( nproc)
22+
23+ # Step 3: Check for model and download if needed
24+ MODEL_DIR=" models"
25+ MODEL_FILE=" llama-2-7b.Q4_0.gguf"
26+ MODEL_PATH=" ${MODEL_DIR} /${MODEL_FILE} "
27+ MODEL_URL=" https://huggingface.co/TheBloke/Llama-2-7B-GGUF/resolve/main/llama-2-7b.Q4_0.gguf"
28+
29+ echo -e " ${GREEN} [3/4] Checking for model...${NC} "
30+
31+ # Create models directory if it doesn't exist
32+ mkdir -p " ${MODEL_DIR} "
33+
34+ if [ -f " ${MODEL_PATH} " ]; then
35+ echo -e " ${YELLOW} Model already exists at ${MODEL_PATH}${NC} "
36+ else
37+ echo -e " ${YELLOW} Model not found. Downloading from Hugging Face...${NC} "
38+ echo " This may take a while (~3.8 GB file)..."
39+
40+ # Download with wget (with progress bar)
41+ if command -v wget & > /dev/null; then
42+ wget -c " ${MODEL_URL} " -O " ${MODEL_PATH} " --show-progress
43+ # Fallback to curl if wget is not available
44+ elif command -v curl & > /dev/null; then
45+ curl -L " ${MODEL_URL} " -o " ${MODEL_PATH} " --progress-bar
46+ else
47+ echo -e " ${RED} Error: Neither wget nor curl found. Please install one of them.${NC} "
48+ exit 1
49+ fi
50+
51+ if [ $? -eq 0 ]; then
52+ echo -e " ${GREEN} Model downloaded successfully!${NC} "
53+ else
54+ echo -e " ${RED} Error downloading model. Please check your internet connection.${NC} "
55+ exit 1
56+ fi
57+ fi
58+
59+ # Step 4: Run benchmark
60+ echo -e " ${GREEN} [4/4] Running benchmark...${NC} "
61+ echo " Configuration:"
62+ echo " - Model: ${MODEL_PATH} "
63+ echo " - GPU layers: 99 (full offload)"
64+ echo " - Flash attention: disabled"
65+ echo " - Prompt sizes: 512, 1024"
66+ echo " - Generation sizes: 128, 256"
67+ echo
68+
69+ # Check if the binary exists
70+ if [ ! -f " build/bin/llama-bench" ]; then
71+ echo -e " ${RED} Error: llama-bench binary not found. Build may have failed.${NC} "
72+ exit 1
73+ fi
74+
75+ # Run the benchmark
76+ ./build/bin/llama-bench -m " ${MODEL_PATH} " -ngl 99 -fa 0 -p 512,1024 -n 128,256
77+
78+ echo
79+ echo -e " ${GREEN} === Benchmark Complete ===${NC} "
0 commit comments