8000 Merge pull request #20682 from charris/backport-20416 · numpy/numpy@c283859 · GitHub
[go: up one dir, main page]

Skip to content

Commit c283859

Browse files
authored
Merge pull request #20682 from charris/backport-20416
ENH: Add ARM Compiler with ARM Performance Library support
2 parents 5399c03 + 794b36f commit c283859

File tree

6 files changed

+165
-5
lines changed

6 files changed

+165
-5
lines changed

numpy/distutils/armccompiler.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import division, absolute_import, print_function
2+
3+
from distutils.unixccompiler import UnixCCompiler
4+
5+
class ArmCCompiler(UnixCCompiler):
6+
7+
"""
8+
Arm compiler.
9+
"""
10+
11+
compiler_type = 'arm'
12+
cc_exe = 'armclang'
13+
cxx_exe = 'armclang++'
14+
15+
def __init__(self, verbose=0, dry_run=0, force=0):
16+
UnixCCompiler.__init__(self, verbose, dry_run, force)
17+
cc_compiler = self.cc_exe
18+
cxx_compiler = self.cxx_exe
19+
self.set_executables(compiler=cc_compiler +
20+
' -O3 -fPIC',
21+
compiler_so=cc_compiler +
22+
' -O3 -fPIC',
23+
compiler_cxx=cxx_compiler +
24+
' -O3 -fPIC',
25+
linker_exe=cc_compiler +
26+
' -lamath',
27+
linker_so=cc_compiler +
28+
' -lamath -shared')

numpy/distutils/ccompiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ def CCompiler_cxx_compiler(self):
708708
"Intel C Compiler for 64-bit applications on Windows")
709709
compiler_class['pathcc'] = ('pathccompiler', 'PathScaleCCompiler',
710710
"PathScale Compiler for SiCortex-based applications")
711+
compiler_class['arm'] = ('armccompiler', 'ArmCCompiler',
712+
"Arm C Compiler")
713+
711714
ccompiler._default_compilers += (('linux.*', 'intel'),
712715
('linux.*', 'intele'),
713716
('linux.*', 'intelem'),

numpy/distutils/fcompiler/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,9 @@ def wrap_unlinkable_objects(self, objects, output_dir, extra_dll_dir):
743743
('win32', ('gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95',
744744
'intelvem', 'intelem', 'flang')),
745745
('cygwin.*', ('gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95')),
746-
('linux.*', ('gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag', 'vast', 'compaq',
747-
'intele', 'intelem', 'gnu', 'g95', 'pathf95', 'nagfor', 'fujitsu')),
746+
('linux.*', ('arm', 'gnu95', 'intel', 'lahey', 'pg', 'nv', 'absoft', 'nag',
747+
'vast', 'compaq', 'intele', 'intelem', 'gnu', 'g95',
748+
'pathf95', 'nagfor', 'fujitsu')),
748749
('darwin.*', ('gnu95', 'nag', 'nagfor', 'absoft', 'ibm', 'intel', 'gnu',
749750
'g95', 'pg')),
750751
('sunos.*', ('sun', 'gnu', 'gnu95', 'g95')),

numpy/distutils/fcompiler/arm.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import division, absolute_import, print_function
2+
3+
import sys
4+
5+
from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
6+
from sys import platform
7+
from os.path import join, dirname, normpath
8+
9+
compilers = ['ArmFlangCompiler']
10+
11+
import functools
12+
13+
class ArmFlangCompiler(FCompiler):
14+
compiler_type = 'arm'
15+
description = 'Arm Compiler'
16+
version_pattern = r'\s*Arm.*version (?P<version>[\d.-]+).*'
17+
18+
ar_exe = 'lib.exe'
19+
possible_executables = ['armflang']
20+
21+
executables = {
22+
'version_cmd': ["", "--version"],
23+
'compiler_f77': ["armflang", "-fPIC"],
24+
'compiler_fix': ["armflang", "-fPIC", "-ffixed-form"],
25+
'compiler_f90': ["armflang", "-fPIC"],
26+
'linker_so': ["armflang", "-fPIC", "-shared"],
27+
'archiver': ["ar", "-cr"],
28+
'ranlib': None
29+
}
30+
31+
pic_flags = ["-fPIC", "-DPIC"]
32+
c_compiler = 'arm'
33+
module_dir_switch = '-module ' # Don't remove ending space!
34+
35+
def get_libraries(self):
36+
opt = FCompiler.get_libraries(self)
37+
opt.extend(['flang', 'flangrti', 'ompstub'])
38+
return opt
39+
40+
@functools.lru_cache(maxsize=128)
41+
def get_library_dirs(self):
42+
"""List of compiler library directories."""
43+
opt = FCompiler.get_library_dirs(self)
44+
flang_dir = dirname(self.executables['compiler_f77'][0])
45+
opt.append(normpath(join(flang_dir, '..', 'lib')))
46+
47+
return opt
48+
49+
def get_flags(self):
50+
return []
51+
52+
def get_flags_free(self):
53+
return []
54+
55+
def get_flags_debug(self):
56+
return ['-g']
57+
58+
def get_flags_opt(self):
59+
return ['-O3']
60+
61+
def get_flags_arch(self):
62+
return []
63+
64+
def runtime_library_dir_option(self, dir):
65+
return '-Wl,-rpath=%s' % dir
66+
67+
68+
if __name__ == '__main__':
69+
from distutils import log
70+
log.set_verbosity(2)
71+
from numpy.distutils import customized_fcompiler
72+
print(customized_fcompiler(compiler='armflang').get_version())
73+

numpy/distutils/system_info.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,11 @@ def get_info(name, notfound_action=0):
501501
1 - display warning message
502502
2 - raise error
503503
"""
504-
cl = {'atlas': atlas_info, # use lapack_opt or blas_opt instead
504+
cl = {'armpl': armpl_info,
505+
'blas_armpl': blas_armpl_info,
506+
'lapack_armpl': lapack_armpl_info,
507+
'fftw3_armpl': fftw3_armpl_info,
508+
'atlas': atlas_info, # use lapack_opt or blas_opt instead
505509
'atlas_threads': atlas_threads_info, # ditto
506510
'atlas_blas': atlas_blas_info,
507511
'atlas_blas_threads': atlas_blas_threads_info,
@@ -1152,6 +1156,16 @@ class fftw3_info(fftw_info):
11521156
'macros':[('SCIPY_FFTW3_H', None)]},
11531157
]
11541158

1159+
1160+
class fftw3_armpl_info(fftw_info):
1161+
section = 'fftw3'
1162+
dir_env_var = 'ARMPL_DIR'
1163+
notfounderror = FFTWNotFoundError
1164+
ver_info = [{'name': 'fftw3',
1165+
'libs': ['armpl_lp64_mp'],
1166+
'includes': ['fftw3.h'],
1167+
'macros': [('SCIPY_FFTW3_H', None)]}]
1168+
11551169

11561170
class dfftw_info(fftw_info):
11571171
section = 'fftw'
@@ -1311,6 +1325,31 @@ class blas_mkl_info(mkl_info):
13111325
pass
13121326

13131327

1328+
class armpl_info(system_info):
1329+
section = 'armpl'
1330+
dir_env_var = 'ARMPL_DIR'
1331+
_lib_armpl = ['armpl_lp64_mp']
1332+
1333+
def calc_info(self):
1334+
lib_dirs = self.get_lib_dirs()
1335+
incl_dirs = self.get_include_dirs()
1336+
armpl_libs = self.get_libs('armpl_libs', self._lib_armpl)
1337+
info = self.check_libs2(lib_dirs, armpl_libs)
1338+
if info is None:
1339+
return
1340+
dict_append(info,
1341+
define_macros=[('SCIPY_MKL_H', None),
1342+
('HAVE_CBLAS', None)],
1343+
include_dirs=incl_dirs)
1344+
self.set_info(**info)
1345+
1346+
class lapack_armpl_info(armpl_info):
1347+
pass
1348+
1349+
class blas_armpl_info(armpl_info):
1350+
pass
1351+
1352+
13141353
class atlas_info(system_info):
13151354
section = 'atlas'
13161355
dir_env_var = 'ATLAS'
@@ -1748,9 +1787,16 @@ class lapack_opt_info(system_info):
17481787
notfounderror = LapackNotFoundError
17491788

17501789
# List of all known LAPACK libraries, in the default order
1751-
lapack_order = ['mkl', 'openblas', 'flame',
1790+
lapack_order = ['armpl', 'mkl', 'openblas', 'flame',
17521791
'accelerate', 'atlas', 'lapack']
17531792
order_env_var_name = 'NPY_LAPACK_ORDER'
1793+
1794+
def _calc_info_armpl(self):
1795+
info = get_info('lapack_armpl')
1796+
if info:
1797+
self.set_info(**info)
1798+
return True
1799+
return False
17541800

17551801
def _calc_info_mkl(self):
17561802
info = get_info('lapack_mkl')
@@ -1925,9 +1971,16 @@ class blas_opt_info(system_info):
19251971
notfounderror = BlasNotFoundError
19261972
# List of all known BLAS libraries, in the default order
19271973

1928-
blas_order = ['mkl', 'blis', 'openblas',
1974+
blas_order = ['armpl', 'mkl', 'blis', 'openblas',
19291975
'accelerate', 'atlas', 'blas']
19301976
order_env_var_name = 'NPY_BLAS_ORDER'
1977+
1978+
def _calc_info_armpl(self):
1979+
info = get_info('blas_armpl')
1980+
if info:
1981+
self.set_info(**info)
1982+
return True
1983+
return False
19311984

19321985
def _calc_info_mkl(self):
19331986
info = get_info('blas_mkl')

numpy/tests/test_public_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_NPY_NO_EXPORT():
189189
"core.shape_base",
190190
"core.umath",
191191
"core.umath_tests",
192+
"distutils.armccompiler",
192193
"distutils.ccompiler",
193194
'distutils.ccompiler_opt',
194195
"distutils.command",
@@ -214,6 +215,7 @@ def test_NPY_NO_EXPORT():
214215
"distutils.extension",
215216
"distutils.fcompiler",
216217
"distutils.fcompiler.absoft",
218+
"distutils.fcompiler.arm",
217219
"distutils.fcompiler.compaq",
218220
"distutils.fcompiler.environment",
219221
"distutils.fcompiler.g95",

0 commit comments

Comments
 (0)
0