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

Illegal instruction 4 with old Mac #764

Closed
ntustison opened this issue May 1, 2019 · 6 comments
Closed

Illegal instruction 4 with old Mac #764

ntustison opened this issue May 1, 2019 · 6 comments

Comments

@ntustison
Copy link
Member

Just in case anybody else runs across this issue--

I have an old Mac Pro (Early 2009). Any binary from compiling the latest ANTs gives me the error "Illegal instruction: 4". I traced it to this change. Using the previous version of the file corrects this problem. Based on the commit message, I've tried changing the optimization flags to

  -DANTs_C_OPTIMIZATION_FLAGS:STRING="-march=native"
  -DANTs_CXX_OPTIMIZATION_FLAGS:STRING="-march=native"
  -DANTs_C_WARNING_FLAGS:STRING="-Wall -Werror"
  -DANTs_CXX_WARNING_FLAGS:STRING="-Wall -Werror"

and

  -DANTs_C_OPTIMIZATION_FLAGS:STRING="-march=native"
  -DANTs_CXX_OPTIMIZATION_FLAGS:STRING="-march=native"

but neither attempt caused things to work.

@cookpa
Copy link
Member

cookpa commented Jul 16, 2019

This has come up a couple of times for users lately. I think it may indirectly depend on the OS because different compilers might make a different guess about the optimizer flags, but the underlying issue is wrong optimization flags being set for the CPU.

I don't think the command line options will work because the error arises in ITK, and command line CMake options don't get passed through to the external projects in a Superbuild.

There is apparently a way to fix this

https://cmake.org/pipermail/cmake/2018-January/067002.html

@gdevenyi
Copy link
Contributor

To be clear, the devs believe the issue is that your CPU is older than corei7, which is what our default "arch" setting is:
/CMake/ITKSetStandardCompilerFlags.cmake@master#L245

You can adjust this by adding "-march=native" to your compile options.

@cookpa
Copy link
Member

cookpa commented Nov 29, 2019

Do we think any of the recent CMake changes have fixed this?

@gdevenyi
Copy link
Contributor

No, the issue is that a commit from @hjmjohnson set the lowest level of instruction sets to "new" CPUs:

set(InstructionSetOptimizationFlags
# https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/i386-and-x86_002d64-Options.html
# NOTE the corei7 release date was 2008
-mtune=native # Tune the code for the computer used compile ITK, but allow running on generic cpu archetectures
-march=corei7 # Use ABI settings to support corei7 (circa 2008 ABI feature sets, core-avx circa 2013)
)
endif()

The solution is the user can override these settings.

@cookpa
Copy link
Member

cookpa commented Dec 11, 2019

I found a machine that produces this error, so I looked into it a bit. Adding

  -DSuperBuild_ANTS_C_OPTIMIZATION_FLAGS="-mtune=native -march=native" \
  -DSuperBuild_ANTS_CXX_OPTIMIZATION_FLAGS="-mtune=native -march=native" 

to the cmake call worked (using GCC 4.9.1 on Linux). I guess for portable builds one would want to replace "native" with "x86-64".

It looks like "corei7" has been removed from the list of GCC supported architectures:

https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html

So I'm not sure what a modern GCC will do with "-march=corei7".

@cookpa
Copy link
Member

cookpa commented Dec 11, 2019

Updated the Wiki, going to close this and related issues

https://github.com/ANTsX/ANTs/wiki/Compiling-ANTs-on-Linux-and-Mac-OS#compilation-fails-or-run-time-errors-occur-with-illegal-instruction-errors

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

3 participants