openucx/ucx

UCX fails to build with Intel compilers in optimized mode

Closed this issue · 8 comments

Recent Intel compilers (I checked starting from 2023.2) automatically enable fast-math mode for optimized builds. This mode allows optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs. While most compilers will simply translate isnan and isinf to always false, recent Intel compilers took a different approach resulting in the following errors while building UCX in optimized mode.

.../ucx-master/src/ucs/datastruct/linear_func.h:171:9: error: explicit comparison with NaN in fast floating point mode [-Werror,-Wtautological-constant-compare]
    if (isnan(x) || isinf(x)) {
        ^~~~~~~~
.../ucx-master/src/ucs/datastruct/linear_func.h:171:21: error: explicit comparison with infinity in fast floating point mode [-Werror,-Wtautological-constant-compare]
    if (isnan(x) || isinf(x)) {

A quick hack is to force Intel compilers to switch in precise floating point mode for the incriminating function (ucs_linear_func_compose).

diff --git a/src/ucs/datastruct/linear_func.h b/src/ucs/datastruct/linear_func.h
index 31e168df1..0808f775e 100644
--- a/src/ucs/datastruct/linear_func.h
+++ b/src/ucs/datastruct/linear_func.h
@@ -157,6 +157,7 @@ ucs_linear_func_compose(ucs_linear_func_t outer, ucs_linear_func_t inner)
  *         double value.
  *
  */
+#pragma float_control(precise,on)
 static inline ucs_status_t
 ucs_linear_func_intersect(ucs_linear_func_t func1, ucs_linear_func_t func2,
                           double *x_intersect)

Unfortunately, the proposed "solution" only works for the Intel compilers, all other compilers will choke with an unknown-pragma error. I fiddled a little around and it seems the culprit is the extremely restrictive -Werror flag added by configure. Without it I was able to successfully compile in all cases.

Can you please try to partially disable fast-math optimization with -fno-finite-math-only? Else we could wrap isnan()/isinf() with __FINITE_MATH_ONLY__ being false, but seems that ICX does not use that define, do you find anything related that would be set by ICX?

Adding CFLAGS=-fno-finite-math-only solves the problem.

Few additional issues:

  • ADD_COMPILER_FLAG_IF_SUPPORTED add the flags to all compilers, which requires the C and CXX compilers to be of the same type. I confirm that building with icx/g++ does not work.
  • the -fopenmp OpenMP flag added by configure is not supported by icx. Instead it asks for -qopenmp. Again, this is triggered by the use of -Werror, if I remote it everything goes smoothly.

Could you please try #9893 using build instructions in description? For openmp, how are you configuring UCX?

  1. Using a slightly older version of the Intel compiler 2021.10.0 (gcc version 11.4.1 compatibility), everything works (including the OpenMP support) without the patch.
configure:           C compiler:   icc -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -Wno-missing-field-initializers -Wno-unused-parameter -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -fno-finite-math-only -Wno-pointer-sign -Werror-implicit-function-declaration -Wshadow -Werror=declaration-after-statement
configure:         C++ compiler:   icpc -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -Wno-missing-field-initializers -Wno-unused-parameter -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -fno-finite-math-only
  1. Using Intel compilers 2024.0.2, with **--disable-openmp** --disable-logging --disable-params-check and using CC=icx-cc CXX=icx (the old icc/icpc compilers names were removed) with your patch works.
configure:           C compiler:   icx-cc -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -fmax-type-align=16 -funwind-tables -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-label -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -Wno-language-extension-token -fno-finite-math-only -Wno-c99-extensions -Wno-pointer-sign -Werror-implicit-function-declaration -Wno-format-zero-length -Wnested-externs -Wshadow -Werror=declaration-after-statement
configure:         C++ compiler:   icx -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -fmax-type-align=16 -funwind-tables -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-label -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -Wno-language-extension-token -fno-finite-math-only -Wno-c99-extensions
  1. Using Intel compilers 2024.0.2, with --disable-logging --disable-params-check and using CC=icx-cc CXX=icx (I just removed the --disable-openmp) with your patch does not work.
configure:           C compiler:   icx-cc -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -fmax-type-align=16 -funwind-tables -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-label -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -Wno-language-extension-token -fno-finite-math-only -Wno-c99-extensions -Wno-pointer-sign -Werror-implicit-function-declaration -Wno-format-zero-length -Wnested-externs -Wshadow -Werror=declaration-after-statement
configure:         C++ compiler:   icx -O3 -g -Wall -Werror -diag-error 10006 -diag-error 10148 -diag-disable 269 -fmax-type-align=16 -funwind-tables -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-label -Wno-long-long -Wno-endif-labels -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations -Winvalid-pch -Wno-language-extension-token -fno-finite-math-only -Wno-c99-extensions

The error message is:

icx: error: icx: Use of '-qopenmp' recommended over '-fopenmp' [-Werror,-Wrecommended-option]
  1. I gave it what it wants and set CFLAGS="-Wno-recommended-option" before configure. With this and Intel compilers 2024.0.2 and your patch everything WORKS.

thanks, updated PR with -Wno-recommended-option, could you please double check?

I confirm the new patch works as expected.

fix merged