Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XHOST detection fails #2023

Closed
susilehtola opened this issue Oct 27, 2020 · 7 comments
Closed

XHOST detection fails #2023

susilehtola opened this issue Oct 27, 2020 · 7 comments

Comments

@susilehtola
Copy link
Member

Running CMake on my laptop with Fedora 32 results in

-- Performing Test CMAKE_CXX_FLAGS [-xHost] - Failed
-- Performing Test CMAKE_CXX_FLAGS [-march=native] - Failed
-- Performing Test CMAKE_CXX_FLAGS [/arch:AVX2] - Failed
CMake Warning at cmake/psi4OptionsTools.cmake:108 (message):
  Option unfulfilled as none of -xHost;-march=native;/arch:AVX2 valid
Call Stack (most recent call first):
  cmake/psi4OptionsTools.cmake:162 (add_C_or_CXX_flags)
  cmake/psi4OptionsTools.cmake:187 (add_CXX_flags)
  cmake/psi4OptionsTools.cmake:202 (add_flags)
  CMakeLists.txt:134 (option_with_flags)

CMakeError.log is

Performing C SOURCE FILE Test test_option failed with the following output:
Change Dir: /home/work/psi4/objdir/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/gmake cmTC_686f3/fast && /usr/bin/gmake  -f CMakeFiles/cmTC_686f3.dir/build.make CMakeFiles/cmTC_686f3.dir/build
gmake[1]: Entering directory '/home/work/psi4/objdir/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_686f3.dir/src.c.o
/usr/lib64/ccache/cc   -Dtest_option -xHost   -xHost -o CMakeFiles/cmTC_686f3.dir/src.c.o   -c /home/work/psi4/objdir/CMakeFiles/CMakeTmp/src.c
cc: error: language Host not recognized
cc: error: language Host not recognized
gmake[1]: *** [CMakeFiles/cmTC_686f3.dir/build.make:86: CMakeFiles/cmTC_686f3.dir/src.c.o] Error 1
gmake[1]: Leaving directory '/home/work/psi4/objdir/CMakeFiles/CMakeTmp'
gmake: *** [Makefile:141: cmTC_686f3/fast] Error 2


Source file was:
int main(void) { return 0; }

making it seem that the CMake files aren't even testing the flags.

If I change the order in CMakeLists.txt so that -march=native comes first, the output is correct:

-- Setting option ENABLE_XHOST: ON
-- Performing Test CMAKE_C_FLAGS [-march=native] - Success, Appending
-- Performing Test CMAKE_CXX_FLAGS [-march=native] - Success, Appending
@susilehtola
Copy link
Member Author

Since the problem is that CMake is not detecting the proper flags, this issue also affects all the other options

option_with_flags(ENABLE_XHOST "Enables processor-specific optimization (with MSVC, it enables AVX2 instructions)" ON
                  "-xHost" "-march=native" "/arch:AVX2")
option_with_flags(ENABLE_CODE_COVERAGE "Enables details on code coverage" OFF
                  "-ftest-coverage")
option_with_flags(ENABLE_BOUNDS_CHECK "Enables bounds check in Fortran" OFF
                  "-ftrapuv -check all -fpstkchk" "-fcheck=all" "-fbounds-check -fcheck-array-temporaries")
option_with_flags(ENABLE_ASAN "Enables address sanitizer (requires similarly compiled Python and Numpy)" OFF
                  "-fsanitize=address -fno-omit-frame-pointer")
option_with_flags(ENABLE_TSAN "Enables thread sanitizer (requires similarly compiled Python and Numpy)" OFF
                  "-fsanitize=thread -fPIE -pie -fno-omit-frame-pointer")
option_with_flags(ENABLE_UBSAN "Enables undefined behavior sanitizer (requires similarly compiled Python and Numpy)" OFF
                  "-fsanitize=undefined -fno-omit-frame-pointer")
option_with_flags(ENABLE_MSAN "Enables memory sanitizer (requires similarly compiled Python and Numpy)" OFF
                  "-fsanitize=memory -fPIE -pie -fno-omit-frame-pointer")

@loriab
Copy link
Member

loriab commented Oct 27, 2020

What compiler is this? Perhaps it has an option -x<language>?

@susilehtola
Copy link
Member Author

$ gcc --version
gcc (GCC) 10.2.1 20201005 (Red Hat 10.2.1-5)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

From the man page

       You can specify the input language explicitly with the -x option:

       -x language
           Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name
           suffix).  This option applies to all following input files until the next -x option.  Possible values for language are:

                   c  c-header  cpp-output
                   c++  c++-header  c++-cpp-output
                   objective-c  objective-c-header  objective-c-cpp-output
                   objective-c++ objective-c++-header objective-c++-cpp-output
                   assembler  assembler-with-cpp
                   ada
                   d
                   f77  f77-cpp-input f95  f95-cpp-input
                   go
                   brig

       -x none
           Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if -x has not
           been used at all).

so yes, looks like -xHost gets parsed as a language override.

@loriab
Copy link
Member

loriab commented Oct 27, 2020

That's annoying of GCC. xHost (for Intel) is before march (for Gnu) b/c the former also has a march.

The other flags (enable_code_coverage through enable_msan) aren't necessarily affected, right?

@susilehtola
Copy link
Member Author

Yes, that's true. However, the test program failed to build with -xHost so it is odd that the CMake scripts would not proceed to test the further alternatives.

@loriab
Copy link
Member

loriab commented Oct 27, 2020

The underlying cmake cmd is checking for a compiler error code, not compilation failure.

I'm confused as to why this is appearing now, as the -x<lang> has been in GCC for many years (at least since 4.8.5).

@loriab
Copy link
Member

loriab commented Oct 27, 2020

Ok, the only non-invasive way I see around this is the below in the main CM file (change primary language as needed):

if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
option_with_flags(ENABLE_XHOST "Enables processor-specific optimization (with MSVC, it enables AVX2 instructions)" ON
                  "-xHost" "-march=native" "/arch:AVX2")
else()
option_with_flags(ENABLE_XHOST "Enables processor-specific optimization (with MSVC, it enables AVX2 instructions)" ON
                  "-march=native" "-xHost" "/arch:AVX2")
endif()

For Intel, -march=native might be a near approximation to -xHost, but I'd rather use the latter official flag.
Do you want to try this out for Libxc, @susilehtola?

I observed another problem that when conda compilers are present and -DCMAKE_CXX_COMPILER=icpc passed, that the -fno-plt set in the envvar CXXFLAGS by conda env activation was unsupported by Intel and so triggered all three ENABLE_XHOST options to fail unless CXXFLAGS= explicitly cleared/set beforehand. I had deliberately not made psi4 CMake dependent on envvars, but it looks like CMake started doing that in 3.10, hmpf. https://cmake.org/cmake/help/v3.10/manual/cmake-env-variables.7.html#manual:cmake-env-variables(7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants