Problem with cython using Ubuntu 20.04

Description of problem

I am having a problem with cython on Ubuntu 20.04.3 LTS running on my laptop with the following processor: 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz × 8.

Brian2 was installed via pip in a venv virtual environment.

From the error (see below) it seems -march=native is not supported. And tigerlake, Intel’s code name for my processor, is not a valid argument to -march and -mtune.

Unfortunately I don’t know what to try next… Any help would be very much appreciated! Thanks in advance.

Minimal code to reproduce problem

I ran this example:
https://brian2.readthedocs.io/en/stable/examples/CUBA.html

What you have aready tried

First tried with default gcc-9 / g+±9.
Updated to gcc-10 and g+±10 and set them as priority via update-alternatives.
Tried setting CC=gcc and CXX=g++ in the terminal.
Checked that CC is set to gcc-10 via readlink -f $(which cc).
Ran the brian2 test suite finding that many tests fail.

Full traceback of error (if relevant)

WARNING    Removing unsupported flag '-march=native' from compiler flags. [brian2.codegen.cpp_prefs]
cc1plus: error: bad value (‘tigerlake’) for ‘-march=’ switch
cc1plus: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client icelake-server cascadelake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 btver1 btver2 native
cc1plus: error: bad value (‘tigerlake’) for ‘-mtune=’ switch
cc1plus: note: valid arguments to ‘-mtune=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client icelake-server cascadelake bonnell atom silvermont slm goldmont goldmont-plus tremont knl knm intel x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 btver1 btver2 generic native
/home/andrew/.cython/brian_extensions/_cython_magic_c60dbfbef46564730dc92eef23e9555e.cpp:36:10: fatal error: Python.h: No such file or directory
   36 | #include "Python.h"
      |          ^~~~~~~~~~
compilation terminated.
WARNING    Cannot use Cython, a test compilation failed: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1 (CompileError)
Certain compiler configurations (e.g. clang in a conda environment on OS X) are known to be problematic. Note that you can switch the compiler by setting the 'CC' and 'CXX' environment variables. For example, you may want to try 'CC=gcc' and 'CXX=g++'. [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]
INFO       Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]
1 Like

Hi @andrewl . I am a bit confused by the output. It claims that -march=native is not accepted, but then later says that native is one of the possible options for -march (in contrast to tigerlake). I suspect that there is interference with compiler options set from somewhere else. Brian itself only sets the options given in prefs.codegen.cpp.extra_compile_args_gcc, which should be something like ['-w', '-O3', '-ffast-math', '-fno-finite-math-only', '-march=native', '-std=c++11']. But Python’s extension build system will also honour other flags set via environment variables. Could you have a look at the CFLAGS and CXXFLAGS environment variables, in particular whether they contain e.g. -march=tigerlake? It might be that unsetting these variables before running the Brian script fixes the problem.

I have a similar error (Ubuntu 18.04, i5-7500). Both environment variables, CFLAGS and CXXFLAGS, are empty.

In my case the trace reads as follows:

WARNING    Removing unsupported flag '-w' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Removing unsupported flag '-O3' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Removing unsupported flag '-ffast-math' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Removing unsupported flag '-fno-finite-math-only' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Removing unsupported flag '-march=native' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Removing unsupported flag '-std=c++11' from compiler flags. [brian2.codegen.cpp_prefs]
WARNING    Cannot use Cython, a test compilation failed: command 'gcc' failed: No such file or directory (CompileError)
Certain compiler configurations (e.g. clang in a conda environment on OS X) are known to be problematic. Note that you can switch the compiler by setting the 'CC' and 'CXX' environment variables. For example, you may want to try 'CC=gcc' and 'CXX=g++'. [brian2.codegen.runtime.cython_rt.cython_rt.failed_compile_test]
INFO       Cannot use compiled code, falling back to the numpy code generation target. Note that this will likely be slower than using compiled code. Set the code generation to numpy manually to avoid this message:
prefs.codegen.target = "numpy" [brian2.devices.device.codegen_fallback]

Hi @carlo Your problem seems to be quite different: it says No such file or directory for the gcc command, i.e. it seems you do not have the C/C++ compiler installed. Since you are on Ubuntu, installing it via sudo apt-get install build-essential should work.

Yes, thanks! I just installed python3-dev (recommended by a college) this morning and that solved it already.

Thanks for your fast reply! :slight_smile:

1 Like

Hi again @andrewl . One more useful thing to debug this issue: could you please set the environment variable DISTUTILS_DEBUG to 1 when running the code? This should then give more information together with the error message.

Thanks @mstimberg for your help! I have it running now and will get back with more details as soon as I can.