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

Additional compilers #28

Merged
merged 9 commits into from
Nov 11, 2024
19 changes: 13 additions & 6 deletions source/fab/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

from fab.tools.ar import Ar
from fab.tools.category import Category
from fab.tools.compiler import (CCompiler, Compiler, FortranCompiler, Gcc,
Gfortran, GnuVersionHandling, Icc, Ifort,
IntelVersionHandling)
from fab.tools.compiler_wrapper import CompilerWrapper, Mpicc, Mpif90
from fab.tools.compiler import (CCompiler, Compiler, Craycc, Crayftn,
FortranCompiler, Gcc, Gfortran, Icc,
Icx, Ifort, Ifx, Nvc, Nvfortran)
from fab.tools.compiler_wrapper import (CompilerWrapper, CrayCcWrapper,
CrayFtnWrapper, Mpicc, Mpif90)
from fab.tools.flags import Flags
from fab.tools.linker import Linker
from fab.tools.psyclone import Psyclone
Expand All @@ -32,20 +33,26 @@
"CompilerWrapper",
"Cpp",
"CppFortran",
"Craycc",
"CrayCcWrapper",
"Crayftn",
"CrayFtnWrapper",
"Fcm",
"Flags",
"FortranCompiler",
"Fpp",
"Gcc",
"Gfortran",
"Git",
"GnuVersionHandling",
"Icc",
"Icx",
"Ifort",
"IntelVersionHandling",
"Ifx",
"Linker",
"Mpif90",
"Mpicc",
"Nvc",
"Nvfortran",
"Preprocessor",
"Psyclone",
"Rsync",
Expand Down
270 changes: 181 additions & 89 deletions source/fab/tools/compiler.py

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions source/fab/tools/compiler_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ def __init__(self, name: str, exec_name: str,
name=name, exec_name=exec_name,
category=self._compiler.category,
suite=self._compiler.suite,
version_regex=self._compiler._version_regex,
mpi=mpi,
availability_option=self._compiler.availability_option)
# We need to have the right version to parse the version output
# So we set this function based on the function that the
# wrapped compiler uses:
setattr(self, "parse_version_output", compiler.parse_version_output)

def __str__(self):
return f"{type(self).__name__}({self._compiler.name})"
Expand Down Expand Up @@ -196,3 +193,29 @@ class Mpicc(CompilerWrapper):
def __init__(self, compiler: Compiler):
super().__init__(name=f"mpicc-{compiler.name}",
exec_name="mpicc", compiler=compiler, mpi=True)


# ============================================================================
class CrayFtnWrapper(CompilerWrapper):
'''Class for the Cray Fortran compiler wrapper. We add 'wrapper' to the
class name to make this class distinct from the Crayftn compiler class.

:param compiler: the compiler that the ftn wrapper will use.
'''

def __init__(self, compiler: Compiler):
super().__init__(name=f"crayftn-{compiler.name}",
exec_name="ftn", compiler=compiler, mpi=True)


# ============================================================================
class CrayCcWrapper(CompilerWrapper):
'''Class for the Cray C compiler wrapper. We add 'wrapper' to the class
name to make this class distinct from the Craycc compiler class

:param compiler: the compiler that the mpicc wrapper will use.
'''

def __init__(self, compiler: Compiler):
super().__init__(name=f"craycc-{compiler.name}",
exec_name="cc", compiler=compiler, mpi=True)
33 changes: 24 additions & 9 deletions source/fab/tools/tool_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
from fab.tools.tool import Tool
from fab.tools.category import Category
from fab.tools.compiler import Compiler
from fab.tools.compiler_wrapper import (CrayCcWrapper, CrayFtnWrapper,
Mpif90, Mpicc)
from fab.tools.linker import Linker
from fab.tools.versioning import Fcm, Git, Subversion
from fab.tools import (Ar, Cpp, CppFortran, Craycc, Crayftn,
Gcc, Gfortran, Icc, Icx, Ifort, Ifx,
Nvc, Nvfortran, Psyclone, Rsync)


class ToolRepository(dict):
Expand Down Expand Up @@ -57,26 +62,36 @@ def __init__(self):

# Add the FAB default tools:
# TODO: sort the defaults so that they actually work (since not all
# tools FAB knows about are available). For now, disable Fpp:
# We get circular dependencies if imported at top of the file:
# pylint: disable=import-outside-toplevel
from fab.tools import (Ar, Cpp, CppFortran, Gcc, Gfortran,
Icc, Ifort, Psyclone, Rsync)

for cls in [Gcc, Icc, Gfortran, Ifort, Cpp, CppFortran,
Fcm, Git, Subversion, Ar, Psyclone, Rsync]:
# tools FAB knows about are available). For now, disable Fpp (by not
# adding it). IF someone actually uses it it can added.
for cls in [Craycc, Crayftn,
Gcc, Gfortran,
Icc, Icx, Ifort, Ifx,
Nvc, Nvfortran,
Cpp, CppFortran,
Ar, Fcm, Git, Psyclone, Rsync, Subversion]:
self.add_tool(cls())

from fab.tools.compiler_wrapper import Mpif90, Mpicc
# Now create the potential mpif90 and Cray ftn wrapper
all_fc = self[Category.FORTRAN_COMPILER][:]
for fc in all_fc:
mpif90 = Mpif90(fc)
self.add_tool(mpif90)
# I assume cray has (besides cray) only support for Intel and GNU
if fc.name in ["gfortran", "ifort"]:
crayftn = CrayFtnWrapper(fc)
print("NEW NAME", crayftn, crayftn.name)
self.add_tool(crayftn)

# Now create the potential mpicc and Cray cc wrapper
all_cc = self[Category.C_COMPILER][:]
for cc in all_cc:
mpicc = Mpicc(cc)
self.add_tool(mpicc)
# I assume cray has (besides cray) only support for Intel and GNU
if cc.name in ["gcc", "icc"]:
craycc = CrayCcWrapper(cc)
self.add_tool(craycc)

def add_tool(self, tool: Tool):
'''Creates an instance of the specified class and adds it
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
@pytest.fixture(name="mock_c_compiler")
def fixture_mock_c_compiler():
'''Provides a mock C-compiler.'''
mock_compiler = CCompiler("mock_c_compiler", "mock_exec", "suite")
mock_compiler = CCompiler("mock_c_compiler", "mock_exec", "suite",
version_regex="something")
mock_compiler.run = mock.Mock()
mock_compiler._version = (1, 2, 3)
mock_compiler._name = "mock_c_compiler"
Expand All @@ -32,6 +33,7 @@ def fixture_mock_fortran_compiler():
'''Provides a mock Fortran-compiler.'''
mock_compiler = FortranCompiler("mock_fortran_compiler", "mock_exec",
"suite", module_folder_flag="",
version_regex="something",
syntax_only_flag=None, compile_flag=None,
output_flag=None, openmp_flag=None)
mock_compiler.run = mock.Mock()
Expand Down
Loading