SWIFTSIM / SWIFT

Modern astrophysics and cosmology particle-based code. Mirror of gitlab developments at https://gitlab.cosma.dur.ac.uk/swift/swiftsim
http://www.swiftsim.com
GNU Lesser General Public License v3.0
88 stars 58 forks source link

Error compiling/running with AVX2 #25

Closed ricitron closed 2 years ago

ricitron commented 2 years ago

I'm having an issue with AVX2 on an AMD processor.

When I compile with ./configure CC=icc --with-hydro=planetary --with-equation-of-state=planetary the compilation complete but I get the following error when trying to run the planetary example: "Please verify that both the operating system and the processor support Intel(R) X87, CMOV, MMX, FXSAVE, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, MOVBE, POPCNT, F16C, AVX, FMA, BMI, LZCNT and AVX2 instructions."

Some googling let me to believe this was due to AVX2 compatibility issues with some AMD processors.

I was able to successfully run the example using the following: ./configure CC=icc --enable-optimization=no CFLAGS="-O3 -mavx" --with-hydro=planetary --with-equation-of-state=planetary based on the suggestion in Issue#13.

However I am not sure how this decreased optimization affects the code. Are there alternative/better flags I should be using to compile given this issue?

MatthieuSchaller commented 2 years ago

That will depend on your exact processor unfortunately. So I think you will have to tests things yourself. You can also look at what flags are activated by default by our script and then just remove the one(s) from that list that are not compatible.

We have not seen that problem on the AMD Rome of Milan with any ICC. What is the specific CPU you are running on?

LonelyCat124 commented 2 years ago

Can you test using -O3 -xCORE-AVX2 -fma for your CFLAGS without optimization on and see if that works? From a quick google they seem to be the recommended flags for Zen2 with icc by prace (https://prace-ri.eu/wp-content/uploads/Best-Practice-Guide_AMD.pdf). The same doc suggests -O3 -xSSE4.2 outperforms -xAVX as well. (I think -m and -x mean the same).

If you're compiling on the relevant cores, you could also try -xHost.

There are a few of those instruction sets you said not listed on here: https://en.wikichip.org/wiki/amd/microarchitectures/zen_2 (LZCNT/X87) but I'm not sure if they're the issue.

pwdraper commented 2 years ago

When using Intel compilers and AMD you need to avoid using any -x flags. That includes some Intel specific checks which trigger this error.

ricitron commented 2 years ago

Thank you for the quick replies. I am compiling on an AMD EPYC 7351 processor.

Using -O3 -xCORE-AVX2 -fma and -O3 -xSSE4.2 did not work, however following the document (https://prace-ri.eu/wp-content/uploads/Best-Practice-Guide_AMD.pdf) I was able to successfully compile using -O3 -march=core-avx2 -fma -ftz -fomit-frame-pointer.

MatthieuSchaller commented 2 years ago

On the Durham system, our automated script picked -O3 -ansi-alias -fma -ftz -fomit-frame-pointer -march=core-avx2 automatically for the flags when using the Intel compiler. That seems to be your winning combination as well.

The system uses AMD EPYC 7542 CPUs. It may be that our detection script somehow missed your CPU id and used incorrect flags.