abiosoft / abiosoft/colima

Enabling AVX instructions on x86_64 arch VM with colima on M1 Mac

Offen
#315 17 Kommentare 5 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Go
Sterne
30.8k
Forks
613
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### Describe the Issue

I'd like to enable AVX instructions so that I can use Tensorflow packages direct from Python's PyPi inside the colima VM. Without it, I get this error message and an exception that seems cannot be safely caught:

> The TensorFlow library was compiled to use AVX instructions, but these aren't available on your machine.

I'm desperately trying to avoid having to recompile the Tensorflow package _without_ AVX instructions enabled. This will add package management complexity I want to avoid at all costs.

N.b. I'm not trying to actually do high-intensity ML work in this scenario: this is just unit tests and local development of an inference server within a Docker container. The actual deployment environment has Intel Xeon processors under the hood. Tensorflow seems not to even want to start up without AVX instructions available.

### Version

#### Colima Version:

```
colima version 0.4.2
git commit: f112f336d05926d62eb6134ee3d00f206560493b

runtime: docker
arch: x86_64
client: v20.10.14
server: v20.10.11
```

#### Lima Version:

```
limactl version 0.11.0
```

#### Qemu Version

```
qemu-img version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
```

### Operating System

- [x] ~~macOS Intel~~
- [X] macOS m1
- [x] ~~Linux~~

```
$ sw_vers
ProductName: macOS
ProductVersion: 12.3.1
BuildVersion: 21E258
```

### To Reproduce

Steps to reproduce the behavior:

1. `colima start --arch x86_64 --cpu 2 --memory 4 --cpu-type max,+avx,+avx2 --disk 60`
2. `colima ssh`
3. `grep avx /proc/cpuinfo`
4. See no output

### Expected behavior

I'd expect `avx` to be in the output of /proc/cpuinfo.

### Additional context

I'm 99% sure that AVX is implemented in QEMU but I speculate based on the present behavior that it may not be enableable on an ARM64 Mac.

https://wiki.qemu.org/Internships/ProjectIdeas/AVX - 2019 internship project to implement AVX in qemu
https://github.com/andikleen/qemu-avx - dead project that’s 9 years old but was successful, so I’ll bet it was upstreamed

However, qemu lists it:

```
$ qemu-system-x86_64 -cpu help | grep avx
avic avx avx-vnni avx2 avx512-4fmaps avx512-4vnniw avx512-bf16
avx512-fp16 avx512-vp2intersect avx512-vpopcntdq avx512bitalg avx512bw
avx512cd avx512dq avx512er avx512f avx512ifma avx512pf avx512vbmi
avx512vbmi2 avx512vl avx512vnni bmi1 bmi2 bus-lock-detect cid cldemote
```

I however [found a user comment that asserts](https://gitlab.com/qemu-project/qemu/-/issues/164#note_569163249):

> the fact that qemu lists a bunch of "Available CPUs" that require AVX2 [qemu-cpu.txt](https://gitlab.com/qemu-project/qemu/uploads/2966ea0e80707814993aac423556ea40/qemu-cpu.txt) definitely looks like a bug.

That is, `qemu-system-x86_64 -cpu help` says that avx is available when it's not available currently on aarch64 host and x86_64 guest.

I've tried the `--cpu-type` option as:

1.
2. `max`
4. `Skylake-Client`
5. `max,+avx,+avx2`

The running qemu command as of the last option:

```
qemu-system-x86_64 -m 4096 -cpu max,+avx,+avx2 -machine q35,accel=tcg -smp 2,sockets=1,cores=2,threads=1 -drive if=pflash,format=raw,readonly=on,file=/Users/colin/.colima/_wrapper/share/qemu/edk2-x86_64-code.fd -boot order=d,splash-time=0,menu=on -drive file=/Users/colin/.lima/colima/basedisk,media=cdrom,readonly=on -drive file=/Users/colin/.lima/colima/diffdisk,if=virtio -cdrom /Users/colin/.lima/colima/cidata.iso -netdev user,id=net0,net=192.168.5.0/24,dhcpstart=192.168.5.15,hostfwd=tcp:127.0.0.1:60775-:22 -device virtio-net-pci,netdev=net0,mac=52:55:55:bd:45:24 -device virtio-rng-pci -display none -device virtio-vga -device virtio-keyboard-pci -device virtio-mouse-pci -parallel none -chardev socket,id=char-serial,path=/Users/colin/.lima/colima/serial.sock,server=on,wait=off,logfile=/Users/colin/.lima/colima/serial.log -serial chardev:char-serial -chardev socket,id=char-qmp,path=/Users/colin/.lima/colima/qmp.sock,server=on,wait=off -qmp chardev:char-qmp -name lima-colima -pidfile /Users/colin/.lima/colima/qemu.pid -netdev socket,id=vlan,fd=3 -device virtio-net-pci,netdev=vlan,mac=5a:94:ef:a7:40:5a
```

I note the presence of `-cpu max,+avx,+avx2` as qemu seems to expect.

The ultimate question is this: **How can I enable AVX instructions for a Colima-managed VM?"

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.