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

Fix arch option in setup.py to work properly + not trigger on MSVC #3429

Merged
merged 17 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ matrix:
name: "Power PC"
os: linux
arch: ppc64le
if: type = cron
#if: type = cron
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
before_install:
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-ppc64le.sh -O miniconda.sh
- mkdir $HOME/.conda
Expand Down Expand Up @@ -42,7 +42,7 @@ matrix:
dist: focal
virt: vm
group: edge
if: type = cron
#if: type = cron
before_install:
- python -m pip install cython "numpy>=1.19.2" scipy
- python -m pip install --no-build-isolation hypothesis matplotlib pytest pytest-cov pytest-xdist tqdm threadpoolctl
Expand Down
2 changes: 1 addition & 1 deletion package/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#use_cython=False
#keep_cythonized=True
## enable cpu specific optimizations
#march="native"
march=native
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
[wheel]
universal = 1

Expand Down
34 changes: 28 additions & 6 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ def using_clang():
return is_clang

hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def using_msvc():
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
"""Will we be using an MSVC compiler?"""
# from numpy.random setup.py
is_msvc = (platform.platform().startswith('Windows') and
platform.python_compiler().startswith('MS'))
return is_msvc

def extensions(config):
# usually (except coming from release tarball) cython files must be generated
use_cython = config.get('use_cython', default=cython_found)
Expand All @@ -280,12 +287,6 @@ def extensions(config):
extra_compile_args.extend(['-Wall', '-pedantic'])
define_macros.extend([('DEBUG', '1')])

# allow using architecture specific instructions. This allows people to
# build optimized versions of MDAnalysis.
arch = config.get('march', default=False)
if arch:
extra_compile_args.append('-march={}'.format(arch))

# encore is sensitive to floating point accuracy, especially on non-x86
# to avoid reducing optimisations on everything, we make a set of compile
# args specific to encore see #2997 for an example of this.
Expand All @@ -295,6 +296,27 @@ def extensions(config):
else:
encore_compile_args.append('-O3')

# allow using architecture specific instructions. This allows people to
# build optimized versions of MDAnalysis. Do here so not included in encore
arch = config.get('march', default=False)
if arch:
if using_msvc():
# MSVC doesn't have a good equivalent for the march flag
pass
else:
if platform.machine() == 'x86_64':
extra_compile_args.append('-march={}'.format(arch))
elif platform.machine() == 'arm':
# arm prefers the use of mcpu only
extra_compile_args.append('-mcpu={}'.format(arch))
elif platform.machine() == 'ppc64le':
# PowerPC prefers the use of mcpu and mtune
extra_compile_args.append('-mcpu={}'.format(arch))
extra_compile_args.append('-mtune={}'.format(arch))
else:
# platform specific optimizations skipped
pass

cpp_extra_compile_args = [a for a in extra_compile_args if 'std' not in a]
cpp_extra_compile_args.append('-std=c++11')
cpp_extra_link_args=[]
Expand Down