Skip to content

Commit 4f0e70f

Browse files
authored
Merge pull request #28 from hiker/additional_compilers
Additional compilers
2 parents 282f068 + f6a70c8 commit 4f0e70f

8 files changed

+615
-132
lines changed

source/fab/tools/__init__.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99

1010
from fab.tools.ar import Ar
1111
from fab.tools.category import Category
12-
from fab.tools.compiler import (CCompiler, Compiler, FortranCompiler, Gcc,
13-
Gfortran, GnuVersionHandling, Icc, Ifort,
14-
IntelVersionHandling)
15-
from fab.tools.compiler_wrapper import CompilerWrapper, Mpicc, Mpif90
12+
from fab.tools.compiler import (CCompiler, Compiler, Craycc, Crayftn,
13+
FortranCompiler, Gcc, Gfortran, Icc,
14+
Icx, Ifort, Ifx, Nvc, Nvfortran)
15+
from fab.tools.compiler_wrapper import (CompilerWrapper, CrayCcWrapper,
16+
CrayFtnWrapper, Mpicc, Mpif90)
1617
from fab.tools.flags import Flags
1718
from fab.tools.linker import Linker
1819
from fab.tools.psyclone import Psyclone
@@ -32,20 +33,26 @@
3233
"CompilerWrapper",
3334
"Cpp",
3435
"CppFortran",
36+
"Craycc",
37+
"CrayCcWrapper",
38+
"Crayftn",
39+
"CrayFtnWrapper",
3540
"Fcm",
3641
"Flags",
3742
"FortranCompiler",
3843
"Fpp",
3944
"Gcc",
4045
"Gfortran",
4146
"Git",
42-
"GnuVersionHandling",
4347
"Icc",
48+
"Icx",
4449
"Ifort",
45-
"IntelVersionHandling",
50+
"Ifx",
4651
"Linker",
4752
"Mpif90",
4853
"Mpicc",
54+
"Nvc",
55+
"Nvfortran",
4956
"Preprocessor",
5057
"Psyclone",
5158
"Rsync",

source/fab/tools/compiler.py

+181-89
Large diffs are not rendered by default.

source/fab/tools/compiler_wrapper.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ def __init__(self, name: str, exec_name: str,
3636
name=name, exec_name=exec_name,
3737
category=self._compiler.category,
3838
suite=self._compiler.suite,
39+
version_regex=self._compiler._version_regex,
3940
mpi=mpi,
4041
availability_option=self._compiler.availability_option)
41-
# We need to have the right version to parse the version output
42-
# So we set this function based on the function that the
43-
# wrapped compiler uses:
44-
setattr(self, "parse_version_output", compiler.parse_version_output)
4542

4643
def __str__(self):
4744
return f"{type(self).__name__}({self._compiler.name})"
@@ -196,3 +193,29 @@ class Mpicc(CompilerWrapper):
196193
def __init__(self, compiler: Compiler):
197194
super().__init__(name=f"mpicc-{compiler.name}",
198195
exec_name="mpicc", compiler=compiler, mpi=True)
196+
197+
198+
# ============================================================================
199+
class CrayFtnWrapper(CompilerWrapper):
200+
'''Class for the Cray Fortran compiler wrapper. We add 'wrapper' to the
201+
class name to make this class distinct from the Crayftn compiler class.
202+
203+
:param compiler: the compiler that the ftn wrapper will use.
204+
'''
205+
206+
def __init__(self, compiler: Compiler):
207+
super().__init__(name=f"crayftn-{compiler.name}",
208+
exec_name="ftn", compiler=compiler, mpi=True)
209+
210+
211+
# ============================================================================
212+
class CrayCcWrapper(CompilerWrapper):
213+
'''Class for the Cray C compiler wrapper. We add 'wrapper' to the class
214+
name to make this class distinct from the Craycc compiler class
215+
216+
:param compiler: the compiler that the mpicc wrapper will use.
217+
'''
218+
219+
def __init__(self, compiler: Compiler):
220+
super().__init__(name=f"craycc-{compiler.name}",
221+
exec_name="cc", compiler=compiler, mpi=True)

source/fab/tools/tool_repository.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
from fab.tools.tool import Tool
1818
from fab.tools.category import Category
1919
from fab.tools.compiler import Compiler
20+
from fab.tools.compiler_wrapper import (CrayCcWrapper, CrayFtnWrapper,
21+
Mpif90, Mpicc)
2022
from fab.tools.linker import Linker
2123
from fab.tools.versioning import Fcm, Git, Subversion
24+
from fab.tools import (Ar, Cpp, CppFortran, Craycc, Crayftn,
25+
Gcc, Gfortran, Icc, Icx, Ifort, Ifx,
26+
Nvc, Nvfortran, Psyclone, Rsync)
2227

2328

2429
class ToolRepository(dict):
@@ -57,26 +62,36 @@ def __init__(self):
5762

5863
# Add the FAB default tools:
5964
# TODO: sort the defaults so that they actually work (since not all
60-
# tools FAB knows about are available). For now, disable Fpp:
61-
# We get circular dependencies if imported at top of the file:
62-
# pylint: disable=import-outside-toplevel
63-
from fab.tools import (Ar, Cpp, CppFortran, Gcc, Gfortran,
64-
Icc, Ifort, Psyclone, Rsync)
65-
66-
for cls in [Gcc, Icc, Gfortran, Ifort, Cpp, CppFortran,
67-
Fcm, Git, Subversion, Ar, Psyclone, Rsync]:
65+
# tools FAB knows about are available). For now, disable Fpp (by not
66+
# adding it). IF someone actually uses it it can added.
67+
for cls in [Craycc, Crayftn,
68+
Gcc, Gfortran,
69+
Icc, Icx, Ifort, Ifx,
70+
Nvc, Nvfortran,
71+
Cpp, CppFortran,
72+
Ar, Fcm, Git, Psyclone, Rsync, Subversion]:
6873
self.add_tool(cls())
6974

70-
from fab.tools.compiler_wrapper import Mpif90, Mpicc
75+
# Now create the potential mpif90 and Cray ftn wrapper
7176
all_fc = self[Category.FORTRAN_COMPILER][:]
7277
for fc in all_fc:
7378
mpif90 = Mpif90(fc)
7479
self.add_tool(mpif90)
80+
# I assume cray has (besides cray) only support for Intel and GNU
81+
if fc.name in ["gfortran", "ifort"]:
82+
crayftn = CrayFtnWrapper(fc)
83+
print("NEW NAME", crayftn, crayftn.name)
84+
self.add_tool(crayftn)
7585

86+
# Now create the potential mpicc and Cray cc wrapper
7687
all_cc = self[Category.C_COMPILER][:]
7788
for cc in all_cc:
7889
mpicc = Mpicc(cc)
7990
self.add_tool(mpicc)
91+
# I assume cray has (besides cray) only support for Intel and GNU
92+
if cc.name in ["gcc", "icc"]:
93+
craycc = CrayCcWrapper(cc)
94+
self.add_tool(craycc)
8095

8196
def add_tool(self, tool: Tool):
8297
'''Creates an instance of the specified class and adds it

tests/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
@pytest.fixture(name="mock_c_compiler")
1919
def fixture_mock_c_compiler():
2020
'''Provides a mock C-compiler.'''
21-
mock_compiler = CCompiler("mock_c_compiler", "mock_exec", "suite")
21+
mock_compiler = CCompiler("mock_c_compiler", "mock_exec", "suite",
22+
version_regex="something")
2223
mock_compiler.run = mock.Mock()
2324
mock_compiler._version = (1, 2, 3)
2425
mock_compiler._name = "mock_c_compiler"
@@ -32,6 +33,7 @@ def fixture_mock_fortran_compiler():
3233
'''Provides a mock Fortran-compiler.'''
3334
mock_compiler = FortranCompiler("mock_fortran_compiler", "mock_exec",
3435
"suite", module_folder_flag="",
36+
version_regex="something",
3537
syntax_only_flag=None, compile_flag=None,
3638
output_flag=None, openmp_flag=None)
3739
mock_compiler.run = mock.Mock()

0 commit comments

Comments
 (0)