1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[VirtualBox]Windows上のUbuntuからAVX系命令セットにアクセスできないときの対処

Last updated at Posted at 2024-11-28

恐怖の「Illegal instruction (core dumped)」

機械学習を行うためUbuntu上にPython環境を整え、必要なライブラリをpip3でインストール後、いざ実行!

import keras

数秒の沈黙後、無に等しい情報量のエラーが出た。

Illegal instruction (core dumped)

何?

AVXが必要らしい

どうもKeras(というよりTensorFlowのv1.6以降)は、AVXというCPUの拡張機能が必要らしい。
Illegal instruction (core dumped) after running import tensorflow #17411

そこでUbuntu上で次のコマンドを実行し確認した。

$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               167
Model name:          11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
Stepping:            1
CPU MHz:             2495.998
BogoMIPS:            4991.99
Hypervisor vendor:   KVM
Virtualization type: full
L1d cache:           48K
L1i cache:           32K
L2 cache:            512K
L3 cache:            16384K
NUMA node0 CPU(s):   0,1
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 pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 movbe popcnt aes rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ibrs_enhanced fsgsbase bmi1 bmi2 invpcid rdseed clflushopt arat md_clear flush_l1d arch_capabilities

Flagsの中にavxとavx2がない。
最近のIntelCPUは基本的にAVX、AVX2に対応しているはずなので(Celeronとか下位は除く)、どうもおかしい。

過去にDocker desktopをインストールしている

調べを進めると、WindowsのHyper-Vという機能が有効化されているとVirtualBoxがAVX系の命令セットにアクセスできないらしい。(参考
はて、そんな機能オンにした記憶はないが。

...Dockerか

DockerをインストールするとHyper-Vが有効になる(らしい)ので、これを無効化する必要がある。

「Hyper-V」を無効化

  • PowerShellを管理者として実行
    image.png

以下のコマンドで現在の状態を確認できる

$ bcdedit

以下の項目があればHyper-Vが有効になっているので

hypervisorlaunchtype    Auto

次のコマンドで無効化後、ホストであるWindowsPCを再起動する(Ubuntuではない)

$ bcdedit /set hypervisorlaunchtype off

場合によってはコンセントからプラグを抜く必要もあるようです。

Windowsの「コア分離」から「メモリ整合性」を無効化

それでもうまくいかない。

で、これも無効化する必要があった。これも要再起動。(virtualbox.org
image.png
image.png
(脆弱な状態にある可能性があるらしい、しらん)

解決

avxとavx2がある、やったー!

$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               167
Model name:          11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz
Stepping:            1
CPU MHz:             2495.998
BogoMIPS:            4991.99
Hypervisor vendor:   KVM
Virtualization type: full
L1d cache:           48K
L1i cache:           32K
L2 cache:            512K
L3 cache:            16384K
NUMA node0 CPU(s):   0,1
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 pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt arat md_clear flush_l1d arch_capabilities

もちろんKerasも動くようになった。

おわり

Hyper-Vを無効化したのでDockerが動かなくなるかもしれないけど、今は使ってないのでヨシ!

追記

しっかり起動しなくなっていた。
image.png
どちらかを使うたびにHyper-V切り替えないといけないの面倒だなぁ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?