How to enable AVX / AVX2 in VirtualBox 6.1.16 with Ubuntu 20.04 64bit?
Asked Answered
A

3

14

TL;DR:

  • Tensorflow 1.15 crashes on my virtual machine when imported by Python (error message is Illegal instruction (core dumped)), very probably thanks to AVX and AVX2 being disabled on it.
  • My host machine (Windows 10 64bit) has AVX and AVX2 (validated using Cygwin, see more details below) [CPU is Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz]
  • On guest machine (Ubuntu 20.04 64bit using VirtualBox 6.1.16, same happens with 18.04), AVX and AVX2 are missing.
  • Following advice from existing threads, I ran VBoxManage setextradata "Ubuntu20" VBoxInternal/CPUM/IsaExts/AVX 1 and VBoxManage setextradata "Ubuntu20" VBoxInternal/CPUM/IsaExts/AVX2 1 on the host machine and restarted the guest machine - nothing changed (the guest machine's name is Ubuntu20).

any advice?

For more details:

Output of cat /proc/cpuinfo on the host machine using Cygwin - it has avx in avx2:

.....
processor       : 7
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
model name      : Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
stepping        : 9
cpu MHz         : 3600.000
cache size      : 256 KB
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts
 acpi mmx fxsr sse sse2 ss ht tm pbe pni dtes64 est tm2 ssse3 fma cx16 xtpr pdcm sse4_1 sse4_2 movbe 
popcnt aes xsave osxsave avx f16c rdrand hypervisor lahf_lm ida xsaveopt pln pts dtherm fsgsbase 
tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt
TLB size        : 0 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

Output of cat /proc/cpuinfo on the guest machine - avx and avx2 are missing:

processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 158
model name  : Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
stepping    : 9
microcode   : 0xffffffff
cpu MHz     : 3599.996
cache size  : 8192 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx 
fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid 
tsc_known_freq pni ssse3 pcid sse4_1 sse4_2 hypervisor lahf_lm invpcid_single pti fsgsbase invpcid 
md_clear flush_l1d arch_capabilities
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 7199.99
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:
Abiogenetic answered 18/1, 2021 at 18:56 Comment(8)
Check your virtualbox config settings for pass-through of CPU features like AVX. Some VMs unfortunately default to not doing that, perhaps to enable suspend -> restore on a host without AVX.Grandsire
I think the question is, exactly which settings would those be? OP seems to have tried to do this with the setextradata commands.Malliemallin
Oh I see. Maybe the command line has changed, IDK. Try using the management GUI: if you can find a guest-CPU option for AVX in it, it should work.Grandsire
I looked for such settings all over the GUI, but didn't found anything. I used setextradata (wrote it in the tl;dr section), but it didn't help, AVX and AVX2 are still not supported. This is visible both when executing cat /proc/cpuinfo and when looking at the logs, which indicate the reading of the two "extradata" values I set to 1, while still later showing for both AVX and AVX2 the value 0 (1), meaning that it is disabled on the guest, while being supported by the host.Abiogenetic
if you are using windows and especially wsl2 beware of hyper-v and axv are mutually exclusive.forums.virtualbox.org/viewtopic.php?f=25&t=99390Nucleotidase
avx requires xsave, nested paging, and nested virtualization (See VBox/VMM/VMMR3/CPUMR3CpuId.cpp). However, nested virtualization seem unavailable when Hyper-V is on, as of vbox v6.1.22.Happygolucky
I'm having a similar problem with Solana on VBox 6.1.38 - none of the below fixes it.Encephalo
One more workaround for the above is use linux subsytem for windows instead of virtualbox. You follow similar steps as linux machine. Get the tensorflow libraries compiled with pip.Decaliter
T
16

As @George-Zheng mentioned, if you see a Turtle icon then you have Hyper-V enabled. Following the recommendations on the link he provided can fix this issue and you will notice this because the Turtle now became a Chip with a V instead.

To summarize the instructions:

  1. Open a Command Prompt in Windows Host as Administrator.

    • Find the Command Prompt icon and right-click. Choose Run As Administrator.
  2. Disable Hypervisor lunch

    bcdedit /set hypervisorlaunchtype off

  3. Disable Microsoft Hyper-V

    DISM /Online /Disable-Feature:Microsoft-Hyper-V

  4. Shutdown quick shutdown -s -t 2

  5. Wait a few seconds before turn it on.

If issues persists, insists once or twice more. Second time worked for me.

Tomlin answered 1/7, 2021 at 17:5 Comment(2)
Thank you, that fixed it, runs much better now and not getting SIGILL. General recommendation should probably be 1. Restart PC and don't open any VM applications, 2. Follow the steps to disable Hyper-VVerdugo
Thank you for solve my issue, and also, after I full disabled Hyper-V, my vm running more faster than before. I can't believe that it's not checked on Windows features, but still active at background and trying to slow everything.Midlands
U
2

I was faced with a similar issue. My windows CPU had the right flags enabled, but importing tensorflow was failing with illegal instruction on my ubuntu20.04 VM. As mentioned above, I confirmed hypervisorlaunchtype was set to off. The issue was something had gone wrong during VirtualBox Manager installation. So, I uninstalled it and then reinstalled it. The first time I did it showed me some errors, so I repeated it again and this time I got a clean installation without any errors. I confirmed my ubuntu20.04 VM was now showing the correct CPU flags as I expected. I still needed to uninstall/reinstall tensorflow and numpy to get it to work properly. Adding it here if anyone else finds it useful.

Unpolled answered 30/9, 2021 at 5:10 Comment(0)
N
2

As an addition to Pato Sandaña's solution, the reason you've got Windows Hyper-V turned on in the first place could be activating a Windows security feature. I remembered that a while ago I got a recommendation from Windows to turn a security feature on - "Core isolation"/"Memory integrity". You can find it from: Windows Security => Device security => Core isolation details => Memory integrity. As soon as I turned this feature off and restarted my PC to let Windows apply the change, the Turtle icon was gone and the "Illegal instruction" error as well.

Bad thing is, the disabled "Memory integrity" feature is stated to "Prevent attacks from inserting malicious code into high-security processes". It is a "Security feature that use virtualization-based security". Thought disabling the Microsoft Hyper-V feature should have the same effect and is a more general solution, as on your PC there could be other Windows features currently using Hyper-V: https://learn.microsoft.com/en-us/troubleshoot/windows-client/application-management/virtualization-apps-not-work-with-hyper-v

Nesbitt answered 16/11, 2022 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.