Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 84fb67c7 authored by GD's avatar GD
Browse files

fix issue with numpy and blas_opt_info/lapack_opt_info + add availability check for openMP

parent e1fe14d3
No related branches found
No related tags found
No related merge requests found
import os import os
import platform # import platform
import sys import sys
from setuptools import setup, Extension, find_packages from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
from distutils.util import get_platform # from distutils.util import get_platform
def check_openmp():
# see https://stackoverflow.com/questions/16549893/programatically-testing-for-openmp-support-from-a-python-setup-script/16555458#16555458
import os, tempfile, textwrap, subprocess, shutil
# see http://openmp.org/wp/openmp-compilers/
omp_test = textwrap.dedent(
r"""
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d over %d\n", omp_get_thread_num(), omp_get_num_threads());
}
"""
)
try:
tmpdir = tempfile.mkdtemp()
filename = r'test.c'
with open(os.path.join(tmpdir, filename), 'w') as file:
file.write(omp_test)
with open(os.devnull, 'w') as fnull:
result = subprocess.call(
['cc', '-fopenmp' ,'-o',
os.path.join(tmpdir, "exec"),
os.path.join(tmpdir, filename)],
stdout=fnull, stderr=fnull
)
except:
result = 1
finally:
shutil.rmtree(tmpdir)
# output : 0 if ok, 1 if not
return result
def get_config(): def get_config():
# Import numpy here, only when headers are needed # Import numpy here, only when headers are needed
...@@ -26,41 +61,75 @@ def get_config(): ...@@ -26,41 +61,75 @@ def get_config():
else: else:
cc_flags.append('-m32') cc_flags.append('-m32')
for _ in np.__config__.blas_opt_info.get('extra_compile_args', []): # blas/lapack compile/linking info
if _ not in cc_flags: try:
cc_flags.append(_) blas_opt_info = np.__config__.blas_opt_info
for _ in np.__config__.lapack_opt_info.get('extra_compile_args', []): except:
if _ not in cc_flags: try:
cc_flags.append(_) blas_opt_info = np.__config__.blas_ilp64_opt_info
except:
blas_opt_info = None
try:
lapack_opt_info = np.__config__.lapack_opt_info
except:
try:
lapack_opt_info = np.__config__.bla_ilp64_opt_info
except:
lapack_opt_info = None
# blas extra compile args
if blas_opt_info is not None:
for _ in blas_opt_info.get('extra_compile_args', []):
if _ not in cc_flags:
cc_flags.append(_)
# lapack extra compile args
if lapack_opt_info is not None:
for _ in lapack_opt_info.get('extra_compile_args', []):
if _ not in cc_flags:
cc_flags.append(_)
# linking flags
link_flags = [] link_flags = []
for _ in np.__config__.blas_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
for _ in np.__config__.lapack_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
# blas extra linking flags
if blas_opt_info is not None:
for _ in blas_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
# lapack extra linking flags
if lapack_opt_info is not None:
for _ in lapack_opt_info.get('extra_link_args', []):
if _ not in link_flags:
link_flags.append(_)
# libs
libs = ['stdc++'] libs = ['stdc++']
# mkl ?
is_mkl = False is_mkl = False
for lib in np.__config__.blas_opt_info.get('libraries', []): if blas_opt_info is not None:
if 'mkl' in lib: for lib in blas_opt_info.get('libraries', []):
is_mkl = True if 'mkl' in lib:
break is_mkl = True
break
libdirs = np.distutils.system_info.blas_info().get_lib_dirs() libdirs = np.distutils.system_info.blas_info().get_lib_dirs()
if is_mkl: if is_mkl:
for _ in np.__config__.blas_opt_info.get('include_dirs', []): for _ in blas_opt_info.get('include_dirs', []):
if _ not in incs: if _ not in incs:
incs.append(_) incs.append(_)
for _ in np.__config__.blas_opt_info.get('library_dirs', []): for _ in blas_opt_info.get('library_dirs', []):
if _ not in libdirs: if _ not in libdirs:
libdirs.append(_) libdirs.append(_)
libs.extend(['mkl_rt']) libs.extend(['mkl_rt'])
else: else:
libs.extend(['blas', 'lapack']) libs.extend(['blas', 'lapack'])
if platform.system() != 'Darwin': # openMP
if check_openmp() == 0:
cc_flags.append('-fopenmp') cc_flags.append('-fopenmp')
link_flags.append('-fopenmp') link_flags.append('-fopenmp')
...@@ -121,37 +190,39 @@ this_directory = os.path.abspath(os.path.dirname(__file__)) ...@@ -121,37 +190,39 @@ this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f: with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read() long_description = f.read()
opts = dict(name='spams', opts = dict(
version='2.6.2.5', name='spams',
description='Python interface for SPAMS', version='2.6.3.0',
long_description=long_description, description='Python interface for SPAMS',
long_description_content_type='text/markdown', long_description=long_description,
author='Julien Mairal', long_description_content_type='text/markdown',
author_email='spams.dev@inria.fr', author='Julien Mairal',
url='http://spams-devel.gforge.inria.fr/', author_email='spams.dev@inria.fr',
license='GPLv3', url='http://spams-devel.gforge.inria.fr/',
python_requires='>=3', license='GPLv3',
setup_requires=['Cython>=0.29', 'numpy>=1.12'], python_requires='>=3',
install_requires=['Cython>=0.29', 'numpy>=1.12', setup_requires=['Cython>=0.29', 'numpy>=1.12'],
'Pillow>=6.0', 'scipy>=1.0', 'six>=1.12'], install_requires=['Cython>=0.29', 'numpy>=1.12',
packages=find_packages(), 'Pillow>=6.0', 'scipy>=1.0', 'six>=1.12'],
cmdclass={'build_ext': CustomBuildExtCommand}, packages=find_packages(),
ext_modules=get_extension(), cmdclass={'build_ext': CustomBuildExtCommand},
data_files=[('tests', ['tests/test_spams.py', ext_modules=get_extension(),
'tests/test_decomp.py', data_files=[('tests', ['tests/test_spams.py',
'tests/test_dictLearn.py', 'tests/test_decomp.py',
'tests/test_linalg.py', 'tests/test_dictLearn.py',
'tests/test_prox.py', 'tests/test_linalg.py',
'tests/test_utils.py']), 'tests/test_prox.py',
('doc', ['doc/doc_spams.pdf']), 'tests/test_utils.py']),
('doc/sphinx/_sources', ('doc', ['doc/doc_spams.pdf']),
mkhtml(d='_sources', base='doc/sphinx')), ('doc/sphinx/_sources',
('doc/sphinx/_static', mkhtml(d='_static', mkhtml(d='_sources', base='doc/sphinx')),
base='doc/sphinx')), ('doc/sphinx/_static', mkhtml(d='_static',
('doc/sphinx', mkhtml(base='doc/sphinx')), base='doc/sphinx')),
('doc/html', mkhtml(base='doc/html')), ('doc/sphinx', mkhtml(base='doc/sphinx')),
('tests', ['data/boat.png', 'data/lena.png'])], ('doc/html', mkhtml(base='doc/html')),
include_package_data=True, ('tests', ['data/boat.png', 'data/lena.png'])],
zip_safe=True) include_package_data=True,
zip_safe=True
)
setup(**opts) setup(**opts)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment