forked from ggml-org/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSCRIPT_compile_MI50.sh
More file actions
executable file
·203 lines (190 loc) · 11.1 KB
/
Copy pathSCRIPT_compile_MI50.sh
File metadata and controls
executable file
·203 lines (190 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
cat << 'EOF'
██╗ ██╗ █████╗ ███╗ ███╗ █████╗ ██████╗██████╗ ██████╗
██║ ██║ ██╔══██╗████╗ ████║██╔══██╗ ██╔════╝██╔══██╗██╔══██╗
██║ ██║ ███████║██╔████╔██║███████║ ██║ ██████╔╝██████╔╝
██║ ██║ ██╔══██║██║╚██╔╝██║██╔══██║ ██║ ██╔═══╝ ██╔═══╝
███████╗███████╗██║ ██║██║ ╚═╝ ██║██║ ██║ ╚██████╗██║ ██║
╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
██████╗ ███████╗██╗ ██╗ █████╗ ██████╗ ██████╗
██╔════╝ ██╔════╝╚██╗██╔╝██╔══██╗██╔═████╗██╔════╝
██║ ███╗█████╗ ╚███╔╝ ╚██████║██║██╔██║███████╗
██║ ██║██╔══╝ ██╔██╗ ╚═══██║████╔╝██║██╔═══██╗
╚██████╔╝██║ ██╔╝ ██╗ █████╔╝╚██████╔╝╚██████╔╝
╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ ╚═════╝ ╚═════╝
EOF
set -e
# 1. Check location
[[ ! -f "CMakeLists.txt" ]] && echo "Error: Not in llama.cpp root directory" && exit 1
# 2. Setup ROCm Environment Variables
export ROCM_PATH=${ROCM_PATH:-/opt/rocm}
export HIP_PATH=$ROCM_PATH
export HIP_PLATFORM=amd
export HIP_CLANG_PATH=$ROCM_PATH/llvm/bin
export PATH=$ROCM_PATH/bin:$ROCM_PATH/llvm/bin:$PATH
export LD_LIBRARY_PATH=$ROCM_PATH/lib:$ROCM_PATH/lib64:$ROCM_PATH/llvm/lib:${LD_LIBRARY_PATH:-}
if command -v amdgpu-arch &> /dev/null; then
AMDGPU_ARCH=$(amdgpu-arch | head -n 1)
echo "Detected AMD GPU Architecture: $AMDGPU_ARCH"
else
echo "Warning: amdgpu-arch tool not found. Defaulting to 'native'."
AMDGPU_ARCH="native"
fi
rm -rf build && mkdir -p build && cd build
# ============================================================================
# CMAKE FLAGS DOCUMENTATION
# ============================================================================
#
# CMAKE BUILD CONFIGURATION ===
#
# CMAKE_BUILD_TYPE Build type: Release, Debug, RelWithDebInfo, MinSizeRel
# CMAKE_C_COMPILER C compiler path (use ROCm clang for HIP)
# CMAKE_CXX_COMPILER C++ compiler path (use ROCm clang++ for HIP)
# CMAKE_HIP_ARCHITECTURES Target GPU arch: gfx906 (MI50/60)
# CMAKE_HIP_COMPILER_FORCED=1 Skip HIP compiler detection. Fixes bfloat16 duplicate symbol
# error on ROCm 6.x (hip_bf16.h multi-include bug) - see issue
#
# COMPILER FLAGS ===
#
# -O3 Maximum optimization level
# -march=native Optimize for host CPU architecture
# -mtune=native Tune instruction scheduling for host CPU
# -DNDEBUG Disable assert() checks (release mode)
# -Wno-ignored-attributes Suppress CUDA __host__/__device__ attribute warnings
# -Wno-cuda-compat Suppress CUDA compatibility warnings in HIP
# -Wno-unused-result Suppress unused return value warnings
#
# GGML GENERAL OPTIONS ===
#
# GGML_STATIC=OFF Static link libraries (ON=static, OFF=shared/dynamic)
# GGML_NATIVE=ON Enable CPU-native optimizations (AVX, AVX2, etc)
# GGML_LTO=OFF Link Time Optimization (slower build, faster binary)
# GGML_CCACHE=ON Use ccache for faster rebuilds if available
# GGML_OPENMP=ON Enable OpenMP for CPU parallelization
# GGML_CPU=ON Enable CPU backend
# GGML_CPU_HBM=OFF Use memkind for High Bandwidth Memory (HBM)
# GGML_CPU_REPACK=ON Runtime weight conversion Q4_0 -> Q4_X_X
# GGML_BACKEND_DL=OFF Build backends as dynamic libraries
# GGML_SCHED_NO_REALLOC=OFF Disable reallocations in ggml-alloc (debug)
#
# CPU SIMD INSTRUCTION SETS ===
#
# GGML_SSE42=ON Enable SSE 4.2 instructions
# GGML_AVX=ON Enable AVX instructions
# GGML_AVX2=ON Enable AVX2 instructions
# GGML_AVX_VNNI=OFF Enable AVX-VNNI (Alder Lake+)
# GGML_AVX512=OFF Enable AVX-512F instructions
# GGML_AVX512_VBMI=OFF Enable AVX-512 VBMI
# GGML_AVX512_VNNI=OFF Enable AVX-512 VNNI
# GGML_AVX512_BF16=OFF Enable AVX-512 BF16
# GGML_FMA=ON Enable FMA (Fused Multiply-Add)
# GGML_F16C=ON Enable F16C (half-float conversions)
# GGML_BMI2=ON Enable BMI2 bit manipulation
# GGML_AMX_TILE=OFF Enable Intel AMX tile instructions
# GGML_AMX_INT8=OFF Enable Intel AMX INT8
# GGML_AMX_BF16=OFF Enable Intel AMX BF16
#
# AMD HIP/ROCm BACKEND ===
#
# GGML_HIP=ON Enable AMD ROCm/HIP backend
# GGML_HIP_GRAPHS=OFF Use HIP graphs for kernel batching (experimental)
# GGML_HIP_NO_VMM=ON Disable Virtual Memory Management (required for MI50)
# GGML_HIP_ROCWMMA_FATTN=OFF Use rocWMMA for Flash Attention (CDNA2+ only)
# GGML_HIP_MMQ_MFMA=ON Use MFMA matrix instructions for MMQ (CDNA GPUs)
# GGML_HIP_EXPORT_METRICS=OFF Export kernel performance metrics
# GGML_HIP_NO_HIPBLASLT=OFF Disable hipBLASLt (enable if crashes on your ROCm)
#
# NVIDIA CUDA BACKEND ===
#
# GGML_CUDA=OFF Enable NVIDIA CUDA backend
# GGML_CUDA_FORCE_MMQ=OFF Force MMQ kernels instead of cuBLAS
# GGML_CUDA_FORCE_CUBLAS=OFF Force cuBLAS instead of MMQ kernels
# GGML_CUDA_NO_PEER_COPY=OFF Disable peer-to-peer GPU copies (multi-GPU)
# GGML_CUDA_NO_VMM=OFF Disable CUDA Virtual Memory Management
# GGML_CUDA_GRAPHS=ON Use CUDA graphs for kernel batching
#
# FLASH ATTENTION ===
#
# GGML_CUDA_FA=ON Enable Flash Attention CUDA/HIP kernels
# GGML_CUDA_FA_ALL_QUANTS=OFF Compile FA for all quant types (Q4, Q5, Q8, etc)
# ON = slower build, supports all quants
# OFF = faster build, only F16 FA
#
# OTHER GPU BACKENDS ===
#
# GGML_VULKAN=OFF Enable Vulkan backend (cross-platform GPU)
# GGML_VULKAN_DEBUG=OFF Enable Vulkan debug output
# GGML_VULKAN_VALIDATE=OFF Enable Vulkan validation layers
# GGML_METAL=OFF Enable Apple Metal backend (macOS/iOS)
# GGML_METAL_EMBED_LIBRARY=ON Embed Metal shaders in binary
# GGML_SYCL=OFF Enable Intel SYCL backend (oneAPI)
# GGML_OPENCL=OFF Enable OpenCL backend (Adreno GPUs)
# GGML_MUSA=OFF Enable Moore Threads MUSA backend
# GGML_WEBGPU=OFF Enable WebGPU backend (browsers)
# GGML_RPC=OFF Enable RPC for distributed inference
#
# OTHER ACCELERATORS ===
#
# GGML_BLAS=OFF Use BLAS library (OpenBLAS, MKL, etc)
# GGML_ACCELERATE=ON Use Apple Accelerate framework (macOS)
# GGML_LLAMAFILE=ON Use llamafile SGEMM kernels
# GGML_HEXAGON=OFF Enable Qualcomm Hexagon DSP backend
# GGML_ZENDNN=OFF Enable AMD ZenDNN for Zen CPUs
# GGML_ZDNN=OFF Enable IBM zDNN for Z mainframes
#
# LLAMA.CPP BUILD TARGETS ===
#
# LLAMA_BUILD_SERVER=ON Build llama-server (OpenAI-compatible HTTP API)
# LLAMA_BUILD_EXAMPLES=ON Build example programs (simple, batched, etc)
# LLAMA_BUILD_TOOLS=ON Build tools (quantize, bench, perplexity, etc)
# LLAMA_BUILD_TESTS=OFF Build test suite (slower, for development)
# LLAMA_BUILD_COMMON=ON Build common utilities library
# LLAMA_TOOLS_INSTALL=ON Install tools to system
#
# LLAMA.CPP FEATURES ===
#
# LLAMA_CURL=ON Enable libcurl for HuggingFace downloads (-hf flag)
# LLAMA_HTTPLIB=ON Use cpp-httplib if curl disabled
# LLAMA_OPENSSL=OFF Use OpenSSL for HTTPS support
# LLAMA_LLGUIDANCE=OFF Include LLGuidance for structured output
#
# DEBUG & SANITIZERS ===
#
# GGML_ALL_WARNINGS=ON Enable all compiler warnings
# GGML_FATAL_WARNINGS=OFF Treat warnings as errors (-Werror)
# GGML_SANITIZE_THREAD=OFF Enable ThreadSanitizer (race detection)
# GGML_SANITIZE_ADDRESS=OFF Enable AddressSanitizer (memory errors)
# GGML_SANITIZE_UNDEFINED=OFF Enable UndefinedBehaviorSanitizer
# GGML_GPROF=OFF Enable gprof profiling
#
# ============================================================================
{
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER="$ROCM_PATH"/llvm/bin/clang \
-DCMAKE_CXX_COMPILER="$ROCM_PATH"/llvm/bin/clang++ \
-DCMAKE_HIP_ARCHITECTURES="$AMDGPU_ARCH" \
-DCMAKE_HIP_COMPILER_FORCED=1 \
-DCMAKE_C_FLAGS="-O3 -march=native -mtune=native -DNDEBUG -ffast-math -fno-finite-math-only -ffp-contract=fast" \
-DCMAKE_CXX_FLAGS="-O3 -march=native -mtune=native -DNDEBUG" \
-DCMAKE_HIP_FLAGS="-Wno-ignored-attributes -Wno-cuda-compat -Wno-unused-result" \
-DGGML_HIP=ON \
-DGGML_HIP_GRAPHS=ON \
-DGGML_HIP_NO_VMM=ON \
-DGGML_HIP_EXPORT_METRICS=ON \
-DGGML_NATIVE=ON \
-DGGML_CUDA_FA=ON \
-DGGML_CUDA_FA_ALL_QUANTS=ON \
-DGGML_CUDA_FORCE_MMQ=OFF \
-DGGML_CUDA_FORCE_CUBLAS=OFF \
-DGGML_CUDA_NO_PEER_COPY=ON \
-DLLAMA_BUILD_SERVER=ON \
-DLLAMA_BUILD_EXAMPLES=ON \
-DLLAMA_BUILD_TOOLS=ON \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_CURL=ON \
-DLLAMA_STATIC=OFF
make -j"$(nproc)"
echo ""
echo "Build complete: ./build/bin/llama-cli, llama-server, llama-bench"
} 2>&1 | tee ../compilation_log.txt