53

I'm on SUSE Linux Enterprise 10/11 machines. I launch my regressions to a farm of machines running Intel processors. Some of my tests fail because my tools are built using a library which requires AVX/AVX2 instruction support. I get an Illegal exception error.

In Linux, is there any commands I can use to determine what is the CPU code/family name?

I believe AVX and AVX2 are available onward from Intel SandyBridge and Haswell family, respectively.

Rodrigo de Azevedo
  • 1,097
  • 9
  • 17
user4979733
  • 3,181
  • 4
  • 26
  • 41

5 Answers5

71

Run this command:

grep avx /proc/cpuinfo

Or

grep avx2 /proc/cpuinfo

This will give you:

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx avx2 hypervisor lahf_lm arat tsc_adjust xsaveopt

khrm
  • 5,363
  • 1
  • 22
  • 26
45

On linux (or unix machines) the information about your cpu is in /proc/cpuinfo. You can extract information from there by hand, or with a grep command (grep flags /proc/cpuinfo).

Also most compilers will automatically define __AVX2__ so you can check for that too.

hr0m
  • 2,643
  • 5
  • 28
  • 39
  • FWIW fails for me with g++ 10.3 and clang++ 12 on a cpu that has it. Unless I add `-mavx2` which, sadly, makes is circular. `march=native` also shows it. Using it with `-march=native` on an old CPU does not indeed the the 'not defined' state. So yes, good answer, _but one needs to trigger it correctly_ too. – Dirk Eddelbuettel Nov 20 '21 at 16:40
  • @DirkEddelbuettel: Yes, compile-time CPU feature flags mean they're assumed baseline for all computers that will run this program. GCC and Clang's default for that is normally configured to be just SSE2 and other things that are baseline for x86-64. Use `gcc -march=native` to make it enable all CPU features your CPU has, making a binary that might not run (correctly or at all) on other CPUs. (Intel has usually been forward-compatible, so this-CPU-or-newer can safe run binaries from `-march=native`, except for their backslide with AVX-512 missing in Alder Lake.) – Peter Cordes Oct 17 '22 at 05:13
  • Other useful options include `-march=x86-64-v3` (Haswell feature-level, but still generic tuning, unfortunately there's still no generic-avx2 tuning that only cares about quirks and preferences of CPUs that support AVX2). https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels / https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html. – Peter Cordes Oct 17 '22 at 05:16
16

You can also run lscpu and check the list of instructions at the end.

Ibrahim A
  • 181
  • 1
  • 4
4

I like to use this command: lscpu

Then specifically: lscpu | grep avx

2

You can test for availability of SIMD instruction sets and other CPU features by examining /proc/cpuinfo, e.g.

$ grep avx2 /proc/cpuinfo
flags       : fpu vme ... sse4_1 sse4_2 ... bmi1 avx2 ... bmi2 ...
Paul R
  • 208,748
  • 37
  • 389
  • 560