NBISweden / MrBayes

MrBayes is a program for Bayesian inference and model choice across a wide range of phylogenetic and evolutionary models. For documentation and downloading the program, please see the home page:
http://NBISweden.github.io/MrBayes/
GNU General Public License v3.0
224 stars 78 forks source link

'./configure --disable-avx --enable-avx=no' has no effect #280

Closed jowodo closed 1 year ago

jowodo commented 1 year ago

What is the current observed behaviour?

Compile on AVX2 capable machine:

$ git clone https://github.com/NBISweden/MrBayes
$ cd MrBayes
$ ./configure --disable-avx # same goes for --enable-avx=no
$ make | grep avx2
gcc -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -msse4a -msha -maes -mavx -mfma -mavx2 -mrdrnd -mbmi -mbmi2 -madx -mabm  -O3 -DNDEBUG -std=c99 -pedantic  -Wall   -o mb mb-bayes.o mb-best.o mb-command.o mb-likelihood.o mb-mbbeagle.o mb-mcmc.o mb-model.o mb-proposal.o mb-sumpt.o mb-utils.o  -lm  -lreadline

Execute on AVX incapable machine:

$ ./src/mb -h
Illegal instruction (core dumped)

Even after removing -mavx2 from the Makefile mb is compiled with -mavx2 flag:

$ git clone https://github.com/NBISweden/MrBayes
$ cd MrBayes
$ ./configure --disable-avx # same goes for --enable-avx=no
$ sed -i "s/-mavx2//" Makefile 
$ make | grep avx2
gcc -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -msse4a -msha -maes -mavx -mfma -mavx2 -mrdrnd -mbmi -mbmi2 -madx -mabm  -O3 -DNDEBUG -std=c99 -pedantic  -Wall   -o mb mb-bayes.o mb-best.o mb-command.o mb-likelihood.o mb-mbbeagle.o mb-mcmc.o mb-model.o mb-proposal.o mb-sumpt.o mb-utils.o  -lm  -lreadline

What is the expected/wanted behaviour?

Compile without `-mavx2 flag

Would you be able to compile and run MrBayes to test fixes to this bug?

What is the environment that you run MrBayes in?

Version: 3.2.7a Features: SSE readline Host type: x86_64-unknown-linux-gnu (CPU: x86_64) Compiler: gnu 8.5.0

kusalananda commented 1 year ago

This is expected and explained in the section entitled "Disabling the SSE, AVX and FMA code paths" in the INSTALL document:

Disabling the SSE, AVX and FMA code paths
------------------------------------------------------------------------

MrBayes will use SSE, AVX and FMA instructions to speed up computations
on CPUs that support these instruction sets, if the compiler supports
it.  These code paths are however optional, and if you suspect a bug in
part of this code, you may use "--disable-sse", "--disable-avx" and/or
"--disable-fma" to disable it when running the "configure" script.

Note however, that disabling SSE will also disable AVX and FMA, and
disabling AVX will also disable FMA.

Note also that disabling these accelerated code paths will not remove
the "-msse" (etc.) compiler flags.  These compiler flags affects what
instructions the compiler is allowed to generate, not what code path is
chosen for compilation.

What this says is that --disable-avx (and --disable-sse) option will disable the compilation of the code that uses explicit AVX (or SSE) vector instructions. If the system on which the code is being compiled supports AVX, the compilation may still enable the -mavx (or similar) compiler options, even if --disable-avx is used (because this configuration option is used solely to disable the specially optimised code paths).

jowodo commented 1 year ago

Thanks for the hint and sorry for not searching the documentation first. Is there a possibility to compile without AVX2 on AVX2 supporting machines, though? Editing the Makefile doesn't work as mentioned in the original post. Doesn't make use the Makefile as configuration file?

Thanks a lot!

kusalananda commented 1 year ago

Thanks for the hint and sorry for not searching the documentation first. Is there a possibility to compile without AVX2 on AVX2 supporting machines, though? Editing the Makefile doesn't work as mentioned in the original post. Doesn't make use the Makefile as configuration file?

Thanks a lot!

Editing the Makefile works, but you will have to edit the correct Makefile. The Makefile in the src subdirectory is the one used when the executable is compiled.

sed -i.bak '/^SIMD_FLAGS/ s/-mavx2//' src/Makefile
jowodo commented 1 year ago

Thanks a lot! Of course I have to edit the correct Makefile 😄 I had to add some sed expressions like -e '/^CPUEXT_FLAGS/ s/-mrdrnd//'. Now it works!