Page 1 of 1

Making AVX a configurable option

PostPosted: Tue Mar 08, 2016 9:28 pm
by kiwifb
In ntl-9.6.3 you introduced automatic detection of AVX and FMA (as well pclmul but more on that later). The detection is "magical" which is problematic for packagers like me (I am active in both sage and Gentoo).

The automatic detection means that you have to select the hardware that will be supported by a binary package. If you build a package on a machine with AVX that binary will only work on machines with AVX. So from a packager point of view I want to be able to turn hardware specific optimisation manually. I would be OK with something that is on by default but can be turned off for people producing binaries.

I am not so concerned by pclmul as I imagine it is for the gf2x code. A binary package will almost certainly ship gf2x as a separate library to which ntl will be linked and it is easy to disable in the gf2x package (did that one a long time ago).

Re: Making AVX a configurable option

PostPosted: Sat Mar 12, 2016 9:27 pm
by victorshoup
I just uploaded a new version of NTL (v9.7.0).
In this latest version (and maybe earlier I don't remember), here is what happens.
By default, NTL will add the flag -march=native to the gcc command line.
With that, the AVX and PCLMUL automagic detection will work based on the
hardware characteristics of the machine you are compiling on.

To override this behavior, configure NTL with NATIVE=off.
This will prevent -march=native from being emitted.
Now you can set the CXXFLAGS manually to "target" for a particular architecture.
For example, if you leave CXXFLAGS at its default value, then
the AVX autodetection will give a negative result: be default, GCC will
compile things for a "generic" x86-64 target, and the AVX checking code
should fail.

So I think with the current configuration options, you should be able to get
whatever you want (short of something like "fat binaries", which is unlikely to
happen any time soon).

Hope that helps.

Re: Making AVX a configurable option

PostPosted: Sun Mar 13, 2016 1:48 am
by kiwifb
I had a concern with the use of `-march=native` because it is x86 only (so is AVX) but I see you check it is working before putting it in use. So all is well.