Newshot

在裸机 UEFI 中运行 Nvidia 驱动(以及启用 GPU 的 LLM)

Translation(model translation, not the source's own text)

Repository files navigation

题图
题图

GPUOS - 在 NVIDIA GPU 上托管并运行 LLM 的裸机应用

本仓库旨在回答一个问题:完整的桌面操作系统究竟在多大程度上拖慢了 LLM 的 TPS。

GPUOS 是一个 x86_64 UEFI 应用,它使用真实的 NVIDIA 驱动与 GPU 通信,并搭载运行 Llama-3.2-1B 的测试框架。

性能测量环境

硬件

  • CPU: AMD Ryzen 9 9950X @ 5.76 GHz
  • GPU: NVIDIA GeForce RTX 4070
  • RAM: 32 GiB DDR5 @ 5200 MHz

本对比中使用的主机操作系统环境

  • OS: Ubuntu 26.04.1 LTS
  • Kernel: Linux 7.0.0-44-generic

测量指标

在 benchmark.cpp 中的 PROMPTS 下,有一组共 11 个不同的提示词交由 Llama-3.2-1B 回答。针对每个回答,计算最小、最大、平均和中位数 TPS。运行 10 次后,这些结果汇总为一个最终结果。

该基准测试搭配改编后的 Llama 测试框架,运行于以下环境:

  • Linux 用户空间(下文记为 "Linux")
  • 作为 UEFI 应用运行在 KVM 下,GPU 通过 VFIO 直通(下文记为 "VM")
  • 作为裸机 UEFI 应用直接在 CPU 上启动(下文记为 "UEFI")

测量结果

各环境下的中位数 TPS 如下:

LinuxVMUEFI
163.5163.6164

Linux 与 VM 实际上相同,而裸机环境仅有轻微(且一致的)0.5 TPS 提升。我认为 Linux/VM 环境中轻微的 TPS 下降纯粹是上下文切换造成的。

构建

前置条件

  • gcc 和 binutils(ld、objcopy)
  • gnu-efi(Ubuntu/Debian: apt install gnu-efi)
  • NVIDIA CUDA toolkit,用于 nvcc(将 GPU 内核编译为 cubin)
  • mtools(mcopy)和 dosfstools(mkfs.vfat)
  • git,以及 curl 或 wget
  • 对于 VM 目标:qemu-system-x86_64 和 OVMF(ovmf 包)

获取依赖

GPUOS 静态链接 NVIDIA 的开源 GPU 内核驱动,并在运行时加载 GGUF 模型。二者均不在本仓库中。使用以下命令获取两者:

这会将 NVIDIA/open-gpu-kernel-modules 克隆并固定到 620.73.04 版本,放入 ../open-gpu-kernel-modules(本仓库的同级目录,也是 Makefile 期望的位置),并将 Llama-3.2-1B-Instruct F16 GGUF 下载到 models/。它还会报告任何缺失的构建工具。

构建


        make            # the UEFI application: build/BOOTX64.EFI and build/gpuos.img (EFI only)
make llm-img    # bootable image bundling the app, the weights and the GPU kernels
      

make llm-img 会生成 build/gpuos_llm.img,这是一个按模型大小调整的 FAT32 镜像。它将 EFI 应用放在 /EFI/BOOT/BOOTX64.EFI,将 GGUF 和 llama.cubin 放在文件系统根目录,应用在运行时正是从启动卷的这些位置读取它们。使用不同的模型:make llm-img GGUF=/path/to/model.gguf。

运行

VM(GPU 通过 VFIO 直通)

首先将 GPU(两个功能)绑定到 vfio-pci,然后:


        cp /usr/share/OVMF/OVMF_VARS_4M.fd build/OVMF_VARS.fd
sudo qemu-system-x86_64 -machine q35,accel=kvm -cpu host,-x2apic -enable-kvm -m 8G -no-reboot \
  -drive if=pflash,format=raw,unit=0,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
  -drive if=pflash,format=raw,unit=1,file=build/OVMF_VARS.fd \
  -drive format=raw,file=build/gpuos_llm.img \
  -device vfio-pci,host=0000:01:00.0,multifunction=on \
  -device vfio-pci,host=0000:01:00.1 \
  -display none -serial null -serial file:serial.log
      

直通的 GPU 驱动其自身连接的显示器。要在交互提示符下输入,还需直通一个 USB 键盘,例如:-device qemu-xhci,id=xhci -device usb-host,bus=xhci.0,vendorid=0xVVVV,productid=0xPPPP。

裸机


        make llm-img
sudo dd if=build/gpuos_llm.img of=/dev/sdX bs=16M oflag=direct status=progress
      

将 /dev/sdX 替换为你的 USB 设备(这会将其擦除),然后从固件启动菜单启动它。使用 USB 键盘进行交互。

交互式使用

在 > 提示符后,输入一条消息并按 Enter 开始对话。输入 [[benchmark]] 可运行提示词测试套件并打印 TPS 中位数。输入 /quit 退出。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗