3

I have server with several GPUs. My idea is to attach them to different VMs in order to use that VMs in CUDA (or OpenCL) calculations.

My setup:

  1. CPU: Intel Xeon E5-2670
  2. GPUs:

    • 1 x Radeon HD 7970

      $ lspci -nn | grep Rad
        83:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT [Radeon HD 7970/8970 OEM / R9 280X] [1002:6798]
        83:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Tahiti XT HDMI Audio [Radeon HD 7970 Series] [1002:aaa0]
      
    • 2 x GeForce GTX Titan Black

  3. Linux kernel 3.14.6
  4. VirtualBox version 4.3.28_OSEr100309

I want to be able to attach any GPU, but lets start with Radeon one.

I found several guides. Most useful is from Arch Wiki: PCI passthrough via OVMF.

I enabled VT-D in BIOS:

$ grep 'vmx|svm|0xc0f' /proc/cpuinfo
flags           : ... vme ... vmx ...

I enabled IOMMU:

$ dmesg|grep -e DMAR -e IOMMU
[    0.000000] Intel-IOMMU: enabled
[    0.089689] dmar: IOMMU 0: reg_base_addr fbffe000 ver 1:0 cap d2078c106f0462 ecap f020fe
[    0.089698] dmar: IOMMU 1: reg_base_addr ebffc000 ver 1:0 cap d2078c106f0462 ecap f020fe
[    0.089833] IOAPIC id 2 under DRHD base  0xfbffe000 IOMMU 0
[    0.089835] IOAPIC id 0 under DRHD base  0xebffc000 IOMMU 1
[    0.089836] IOAPIC id 1 under DRHD base  0xebffc000 IOMMU 1
[    1.440173] IOMMU 0 0xfbffe000: using Queued invalidation
[    1.440176] IOMMU 1 0xebffc000: using Queued invalidation
[    1.440191] IOMMU: Setting RMRR:
[    1.440241] IOMMU: Setting identity map for device 0000:00:1d.0 [0xbddbf000 - 0xbddd5fff]
[    1.440332] IOMMU: Setting identity map for device 0000:00:1a.0 [0xbddbf000 - 0xbddd5fff]
[    1.440375] IOMMU: Prepare 0-16MiB unity mapping for LPC
[    1.440413] IOMMU: Setting identity map for device 0000:00:1f.0 [0x0 - 0xffffff]
[    5.356692] vboxpci: IOMMU found

I isolated GPUs with pci-stub:

$ dmesg | grep pci-stub
[    0.000000] Command line: BOOT_IMAGE=../vmlinuz-linux root=/dev/sda1 ro nomodeset intel_iommu=on pci-stub.ids=1002:6798,1002:aaa0 initrd=../initramfs-linux.img
[    0.000000] Kernel command line: BOOT_IMAGE=../vmlinuz-linux root=/dev/sda1 ro nomodeset intel_iommu=on pci-stub.ids=1002:6798,1002:aaa0 initrd=../initramfs-linux.img
[    1.544921] pci-stub: add 1002:6798 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[    1.545003] pci-stub 0000:83:00.0: claimed by stub
[    1.545107] pci-stub: add 1002:AAA0 sub=FFFFFFFF:FFFFFFFF cls=00000000/00000000
[    1.545186] pci-stub 0000:83:00.1: claimed by stub

And also blacklisted modules and fglrx isn't loaded after boot:

$ cat /etc/modprobe.d/blacklist-fglrx.conf
blacklist radeon
blacklist fglrx

When I try to attach that pci, I catch following error:

VBoxManage: error: Device with host PCI address already attached to this VM
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "AttachHostPCIDevice(iHostAddr, iGuestAddr, TRUE)" at line 2736 of file VBoxManageModifyVM.cpp

May be the reason is in IOMMU groups (because Audio and Video part of my GPU is one group):

$ find /sys/kernel/iommu_groups/ -type l | grep 22
/sys/kernel/iommu_groups/22/devices/0000:83:00.0
/sys/kernel/iommu_groups/22/devices/0000:83:00.1

But I don't know how to attach whole group at once.

Any ideas?

P.S. I don't stick to any particular VM. If it is possible not with VirtualBox but with something else, I would be happy.

  • you should try vmware player; the free version is not as stable as virtual box but it can deal with peripherals easily – user3566929 Oct 14 '15 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.