Skip to content

cannot use gcc option -ffast-math to enable vectorization #347

@srlantz

Description

@srlantz

If -ffast-math is included on the gcc compile line, the resulting code segfaults. This option seems desirable because it might improve mkFit's timing performance, by enabling a higher degree of vectorization. (On the other hand, there are indications that increased vectorization might be affecting physics performance negatively, based on comparisons of icc-vectorized with icc-unvectorized and gcc; see the comments by @mmasciov on issue #346.)

Background: using godbolt.org, I acted upon a months-old suggestion from @makortel and experimented with a very simple code consisting of a single loop that calls sin(). I found in agreement with him that the -ffast-math option is sufficient to induce gcc to insert calls to the vectorized sin() function from libmvec, given a recent enough glibc. The necessary suboptions were found to be (by @dan131riley, and confirmed by me) -fno-math-errno -ffinite-math-only -fno-rounding-math -funsafe-math-optimizations. Without these 4 suboptions, gcc is constrained not to vectorize this loop. Here is a link where anyone can reproduce those experiments: https://godbolt.org/z/qT9j7bvx1

The specific suboption of -ffast-math that breaks mkFit seems to be -funsafe-math-optimizations.

A further clue is that if intrinsics are disabled and auto-vectorization is limited by -DMPT_SIZE=1, the resulting code does NOT segfault with -ffast-math. The specific make and run commands that were successful on lnx7188, after doing source xeon_scripts/init-env.sh, were

make distclean
make -j 24 AVX2:=1 CXX:=g++ USE_INTRINSICS:="-DMPT_SIZE=1" CPPUSERFLAGS="-ffast-math"
./mkFit/mkFit --input-file ../../data2/112X_TTbar_PU50_MULTI.bin --cmssw-n2seeds --num-events 6400 --num-thr 64 --num-thr-ev 32 --build-mimi --num-iters-cmssw 1

We have known for some time that vectorization alters aspects of math operations, which may affect the precision of intermediate results. This is likely the reason for past variations in numbers of builtcands (issue #267), and may be at work again here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions