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

The "-march=native" flag vs. the compiler used when Python extensions are built #31228

Closed
mkoeppe opened this issue Jan 13, 2021 · 41 comments
Closed

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Jan 13, 2021

(from #31132)

#27122 determines whether CC accepts -march=native and then adds it globally to CFLAGS in build/bin/sage-build-env.

However, Python extension modules are compiled with the compiler listed in sysconfig. On macOS with homebrew, using /usr/bin/python3, this could be clang, which does not accept -march=native.

Depends on #3113
Depends on #30725

CC: @kliem @zlscherr @jhpalmieri

Component: build: configure

Reviewer: Jonathan Kliem

Issue created by migration from https://trac.sagemath.org/ticket/31228

@mkoeppe mkoeppe added this to the sage-9.3 milestone Jan 13, 2021
@kliem
Copy link
Contributor

kliem commented Jan 13, 2021

comment:2

Do we manually set the Compiler to be different somewhere vor is this enforced by using system python? If not, is there a reasonable place to check this?

Can this happen to python modules only?

@kliem
Copy link
Contributor

kliem commented Jan 13, 2021

comment:3

There is CFLAGS_NON_NATIVE etc that should be used in case the compiler changes.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 13, 2021

comment:4

This is the standard behavior of python's distutils. Only Python extension modules are affected.

m4/sage_check_python_for_venv defines a macro used by build/pkgs/python3/spkg-configure.m4 to check the suitability of distutils.

These are probably the best places to put additional checks.

@kliem
Copy link
Contributor

kliem commented Jan 13, 2021

comment:5

I see. I can add a file compiling with -march=native in m4/sage_check_python_for_venv. In case of failure, I have to export something.

If this fails, I have to build extension modules with export CFLAGS=CFLAGS_NON_NATIVE and export CXXFLAGS=CXXFLAGS_NON_NATIVE somehow.

@kliem
Copy link
Contributor

kliem commented Jan 13, 2021

comment:6

Much easier would be to give completely up on march=native in this case.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 13, 2021

comment:7

Replying to @kliem:

Much easier would be to give completely up on march=native in this case.

Yes, I think that would be better. Otherwise too many spkg-install files would have to be changed. I don't see a clean way of implementing this in the helper functions sdh_pip_install and sdh_setup_bdist_wheel.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2021

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2021

Commit: 289b162

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

2c60025m4/sage_check_python_for_venv.m4: Warn if python3 is misconfigured like it is currently in homebrew
ee679bdbuild/pkgs/python3/spkg-configure.m4: Do not check sysconfig CPPFLAGS so that /usr/bin/python3 is accepted on macOS; reject broken homebrew python3 unless requested explicitly with configgure --with-python=...
29aee87build/pkgs/python3: Update to 3.9.0rc2
e61d464build/pkgs/python3: Update to 3.9.0
f8bb56dbuild/pkgs/python3: Update to 3.9.1
0e3513fbuild/pkgs/pip: Update to 20.3.3
41d7e7aMerge branch 'u/jhpalmieri/new_wheel' of git://trac.sagemath.org/sage into t/30589/upgrade-python-3.9
76d5fd1Merge branch 't/30589/upgrade-python-3.9' into t/31132/homebrew__unused_packages__singular__pari_______in__usr_local_leak_into_build_when_using_homebrew_s_python3
289b162m4/sage_check_python_for_venv.m4: Factor out macros SAGE_PYTHON_DISTUTILS_C_CONFTEST, SAGE_PYTHON_DISTUTILS_CXX_CONFTEST

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2021

Dependencies: #31132

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2021

comment:11

Let's do this on top of #31132, which has modified the same files.

I have added one commit that refactors m4/sage_check_python_for_venv.m4 as preparation.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

e38057ebuild/pkgs/python3/spkg-configure.m4: If '-march' has been set, check if it works with the compilers used for extension buildings

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2021

Changed commit from 289b162 to e38057e

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2021

comment:13

Here's an attempt

@kliem
Copy link
Contributor

kliem commented Jan 14, 2021

comment:14

Looks plausible, however I don't see exactly, where -march=native was added such that this command fails.

            AS_IF([CC="$CC" CXX="$CXX" conftest_venv/bin/python3 conftest.py --verbose build --build-base=conftest.dir >& AS_MESSAGE_LOG_FD 2>&1 ], [

Maybe we need to add -march=native yet:

            AS_IF([CC="$CC" CXX="$CXX" CFLAGS="-march=native" CXXFLAGS="-march=native" conftest_venv/bin/python3 conftest.py --verbose build --build-base=conftest.dir >& AS_MESSAGE_LOG_FD 2>&1 ], [

But I'm just hoping they are respected.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 14, 2021

comment:15

Yes, I meant to add CFLAGS="$CFLAGS_MARCH" in these places

@kliem
Copy link
Contributor

kliem commented Jan 15, 2021

Author: Matthias Koeppe

@kliem
Copy link
Contributor

kliem commented Jan 15, 2021

New commits:

3a86a18add CFLAGS and CXXFLAGS

@kliem
Copy link
Contributor

kliem commented Jan 15, 2021

Changed commit from e38057e to 3a86a18

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2021

comment:17

On homebrew, this will have to be tested together with #31227 if a current XCode version is in use

@kliem
Copy link
Contributor

kliem commented Jan 16, 2021

comment:18

There is a merge conflict with #31227.

Does the problem show up during github workflows? (If so, I can fix the merge conflict and test whether the problem goes away.)

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 16, 2021

comment:19

It showed up when I tried in on my local machine.
But now I think the observed failures are actually caused by some outdated code in install scripts of some packages, which explicitly set CC=clang - see #30725.

@kliem
Copy link
Contributor

kliem commented Jan 22, 2021

comment:20

Instead of disabling -march=native alltogether, one might get away with just disabling it in sdh_pip_install.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

comment:21

I prefer the easy solution as currently implemented, see comment 7 above

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 23, 2021

Changed commit from 3a86a18 to 09b03d2

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 23, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

02c2684R is already compiled without -march=native
24b4fccset EXTRACFLAGS instead of CFLAGS
44be967make code a bit more stable against future changes
f56e65efix CFLAGS for python3/spkg-build.in by running testcflags.sh after determination of the compiler
09b03d2Merge branch 'u/gh-kliem/macos__spkg_install__remove_outdated__building_with_clang__code___which_conflicts_with___march_native_' of git://trac.sagemath.org/sage into t/31228/the___march_native__flag_vs__the_compiler_used_when_python_extensions_are_built

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

Changed dependencies from #31132 to #31132, #30725

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

comment:26

Upgrading this to blocker, because this ticket is needed to get cython installation to work again (when python uses clang instead of gcc):

#30725 comment:50

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

comment:27

Replying to @kliem:

New commits:

3a86a18add CFLAGS and CXXFLAGS

I think this commit is needed, isn't it?

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

Reviewer: Jonathan Kliem, https://github.com/kliem/sage/pull/35/checks

@kliem
Copy link
Contributor

kliem commented Jan 23, 2021

comment:29

I just started github actions along with commit 3a86a18f345a1c98411aa05254bff58ac02c3180.

Please tell me, if I need to pull other tickets yet as mentioned in:

#30725 comment:42

Btw, I personally would find it useful, those tickets needed to fix github actions on top of the current beta are collected somewhere.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

comment:30

Replying to @kliem:

Replying to @kliem:

New commits:

3a86a18 add CFLAGS and CXXFLAGS

I think this commit is needed, isn't it?

Right, something like this. I'll try to dig out the commits that I was using

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 23, 2021

comment:31

I have pushed the branch to #31227. Maybe we can skip the present ticket and do everything in #31227.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 25, 2021

Changed author from Matthias Koeppe to none

@mkoeppe mkoeppe removed this from the sage-9.3 milestone Jan 25, 2021
@kliem
Copy link
Contributor

kliem commented Jan 25, 2021

@kliem
Copy link
Contributor

kliem commented Jan 25, 2021

Changed dependencies from #31132, #30725 to #3113, #30725

@kliem
Copy link
Contributor

kliem commented Jan 25, 2021

Changed reviewer from Jonathan Kliem, https://github.com/kliem/sage/pull/35/checks to Jonathan Kliem

@kliem
Copy link
Contributor

kliem commented Jan 25, 2021

Changed commit from 09b03d2 to none

@kliem
Copy link
Contributor

kliem commented Jan 25, 2021

comment:33

Agreed.

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

No branches or pull requests

3 participants