Ubuntu 24.04下编译支持ROCm加速的llama.cpp

llama.cpp官方编译发布的ubuntu版本只支持cpu和vulkan版本,如需原生ROCm加速,需要自行编译。

这提供了对支持HIP的AMD GPU的GPU加速。确保已安装ROCm。您可以从Linux发行版的包管理器或此处下载ROCm快速入门(Linux)。

复制代码
# 安装必要的依赖
sudo apt install cmake git libcurl4-openssl-dev
# 克隆代码
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp

# 执行编译
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" cmake -S . -B build -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx906 -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release -- -j 28

如果编译成功,在可以在llama.cpp/build/bin 中查看到全部的cli和so

复制代码
# 测试命令
./build/bin/llama-cli 

# 打印
ggml_cuda_init: GGML_CUDA_FORCE_MMQ:    no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 ROCm devices:
  Device 0: AMD Radeon Graphics, gfx906:sramecc-:xnack- (0x906), VMM: no, Wave Size: 64
build: 0 (unknown) with cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 for x86_64-linux-gnu
main: llama backend init
main: load the model and apply lora adapter, if any
llama_model_load_from_file_impl: using device ROCm0 (AMD Radeon Graphics) (0000:05:00.0) - 32732 MiB free
gguf_init_from_file: failed to open GGUF file 'models/7B/ggml-model-f16.gguf'
llama_model_load: error loading model: llama_model_loader: failed to load model from models/7B/ggml-model-f16.gguf
llama_model_load_from_file_impl: failed to load model
common_init_from_params: failed to load model 'models/7B/ggml-model-f16.gguf', try reducing --n-gpu-layers if you're running out of VRAM
main: error: unable to load model

可以看到已经加载了ROCm后端,表示成功。

相关推荐
玖石书21 小时前
Ubuntu 更换 USTC 镜像源完整指南(AMD64 / AARCH64)
linux·运维·ubuntu
zbyyd21 小时前
Linux 进程间通信(IPC):信号、消息队列、共享内存与信号量详解
linux·运维·c语言
闲云野鹤在人间1 天前
KVM虚拟化实战|CentOS‑Stream8 两种安装方式+模板制作+基础使用
linux·运维·服务器·centos
小张同学a.1 天前
Docker 容器实战 2—— docker 仓库
linux·运维·服务器·docker·容器
Android系统攻城狮1 天前
Linux PipeWire深度解析之pw_core_get_registry调用流程与实战(九十一)
linux·运维·服务器·音频进阶·pipewire音频实战进阶
小义_1 天前
JDK 深度解析
java·linux·开发语言·python·面试
邪修king1 天前
Re:Linux 系统编程篇 (十二):进程篇(一)基础与 fork 系统调用全解
linux·运维·服务器
牢姐与蒯1 天前
Linux进程(五).之环境变量
linux·运维·服务器·ubuntu
黑臂麒麟1 天前
Harmony鸿蒙实战应用4:随手账本——编辑与删除账单
ubuntu·华为·鸿蒙
raindayinrain1 天前
深入理解Linux内核--系统调用,性能优化
linux·性能优化·系统调用·返回值·入参·内核态用户态地址访问