华为A800I A2 arm64架构鲲鹏920cpu的ubuntu22.04 tls配置直通的grub配置
ubuntu的grub文件配置
结合配置链接:https://yunwei.blog.csdn.net/article/details/153411516?fromshare=blogdetail&sharetype=blogdetail&sharerId=153411516&sharerefer=PC&sharesource=qq_42534026&sharefrom=from_link
在执行链接的流程之后就可以继续在此文档继续配置。
关系项配置
GRUB_CMDLINE_LINUX="arm-smmu.enable=1 iommu.passthrough=1 iommu=pt smmu.enable=1 default_hugepagesz=2M hugepagesz=2M hugepages=65536"
更改之后更新配置
update-grub

解读
arm-smmu.enable=1
启用 ARM 架构的 SMMU(System Memory Management Unit,相当于 ARM 版的 IOMMU),是设备透传的核心前提。
功能:为透传的硬件(如 NPU)分配独立的内存地址空间,隔离虚拟机与宿主机内存,避免地址冲突。 你的服务器是 arm64 架构(之前 YAML 中 architecture: arm64),必须启用 SMMU 才能让 NPU 从宿主机透传到虚拟机,否则透传会失败(设备无法被虚拟机识别)。
iommu.passthrough=1
启用 IOMMU 直通模式(Passthrough),让透传的设备(如 NPU)直接访问物理内存,跳过内核中间层干预。 减少内存访问延迟,提升 NPU 计算性能(NPU 是算力密集型设备,直通模式能避免内核转发带来的性能损耗)。
iommu=pt
缩写自 iommu.passthrough=1,作用完全一致,是更简洁的写法,双重确认启用直通模式。 避免单一参数不生效(部分内核版本对参数写法有兼容差异),确保 IOMMU 直通必然启用。
smmu.enable=1
重复启用 SMMU 功能(与 arm-smmu.enable=1 功能重叠),属于冗余保险配置。 部分 ARM 服务器内核可能只识别其中一个参数,双重启用确保 SMMU 不会因参数识别问题失效(NPU 透传的关键保障)。
default_hugepagesz=2M
设置默认 “大页内存” 尺寸为 2MB。大页内存:相对于普通 4KB 小页,大页能减少内存地址转换的开销,提升内存访问效率。 NPU 处理任务时需要占用大量连续内存(如模型训练、数据推理),大页能避免内存碎片化,让 NPU 更快访问数据。
hugepagesz=2M
明确指定大页内存的尺寸为 2MB(与 default_hugepagesz 呼应,确保参数一致性)。 避免内核自动分配其他尺寸大页(如 1GB),导致 NPU 驱动不兼容(华为 Ascend 驱动默认适配 2MB 大页)。
hugepages=65536
分配 65536 个 2MB 大页,总大小 = 65536 × 2MB = 128GB 大页内存。 为 NPU 预留充足的连续物理内存,满足大模型训练、批量数据处理等场景的内存需求(你的虚拟机配置了 16GB 内存,宿主机分配 128GB 大页能充分支撑 NPU 算力发挥)。
完整文件

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'GRUB_DEFAULT="gnulinux-advanced-168a118f-797e-42c6-b915-22ee32283fc8>gnulinux-5.15.0-25-generic-advanced-168a118f-797e-42c6-b915-22ee32283fc8"
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="arm-smmu.enable=1 iommu.passthrough=1 iommu=pt smmu.enable=1 default_hugepagesz=2M hugepagesz=2M hugepages=65536"# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
