Newshot

Running the Nvidia driver inside baremetal UEFI (and a GPU enabled LLM)

Original text(via HN AI)

Repository files navigation

题图
题图

GPUOS - Bare metal application that hosts and LLM running on NVIDIA GPUs

This repository was created to answer a question of how much is a full deskopt operating system getting in the way of LLM TPS.

GPUOS is a x86_64 UEFI application that uses the real NVIDIA driver to talk to the GPU and a harness from running Llama-3.2-1B.

Performance measurement environment

Hardware

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

Host OS enviroment used in this comparison

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

Measurement metric

In benchmark.cpp under PROMPTS there are a set of 11 different prompts Llama-3.2-1B is asked. Upon each answer min, max, mean and median TPS is calculated. After 10 runs those results are aggregated into one final result.

This benchmark with the adapted Llama harness is ran under:

  • Linux Userspace (Noted further as "Linux")
  • As an UEFI app under KVM with GPU passed through via VFIO (Noted further as "VM")
  • As a baremetal UEFI application booted directly on the CPU (Noted further as "UEFI")

Measurement results

Median TPS across these enviromnets are as follows:

LinuxVMUEFI
163.5163.6164

Linux and VM are effectively the same, while there's only a slight (and consistent) 0.5 TPS improvement in the baremetal environment. I believe the slight TPS regression in Linux/VM environment is purely an artifact of context switching.

Building

Prerequisites

  • gcc and binutils (ld, objcopy)
  • gnu-efi (Ubuntu/Debian: apt install gnu-efi)
  • NVIDIA CUDA toolkit, for nvcc (compiles the GPU kernels to cubin)
  • mtools (mcopy) and dosfstools (mkfs.vfat)
  • git, and curl or wget
  • For the VM target: qemu-system-x86_64 and OVMF (ovmf package)

Fetch dependencies

GPUOS statically links NVIDIA's open GPU kernel driver and loads a GGUF model at runtime. Neither lives in this repo. Fetch both with:

This clones NVIDIA/open-gpu-kernel-modules pinned to 620.73.04 into ../open-gpu-kernel-modules (a sibling of this repo, which is where the Makefile expects it), and downloads the Llama-3.2-1B-Instruct F16 GGUF into models/. It also reports any missing build tools.

Build


        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 produces build/gpuos_llm.img, a FAT32 image sized to the model. It places the EFI app at /EFI/BOOT/BOOTX64.EFI and the GGUF plus llama.cubin at the filesystem root, which is where the app reads them from the boot volume at runtime. Use a different model with make llm-img GGUF=/path/to/model.gguf.

Running

VM (GPU passed through via VFIO)

Bind the GPU (both functions) to vfio-pci first, then:


        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
      

The passed-through GPU drives its own attached monitor. To type at the interactive prompt, pass a USB keyboard through too, for example: -device qemu-xhci,id=xhci -device usb-host,bus=xhci.0,vendorid=0xVVVV,productid=0xPPPP.

Bare metal


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

Replace /dev/sdX with your USB device (this erases it), then boot it from the firmware boot menu. Use a USB keyboard to interact.

Interactive use

At the > prompt, type a message and press Enter to chat. Type [[benchmark]] to run the prompt suite and print the median TPS. Type /quit to exit.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. 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 ↗