1import sys
2
3from numpy.distutils.fcompiler import FCompiler
4
5compilers = ['NVHPCFCompiler']
6
7class NVHPCFCompiler(FCompiler):
8    """ NVIDIA High Performance Computing (HPC) SDK Fortran Compiler
9
10    https://developer.nvidia.com/hpc-sdk
11
12    Since august 2020 the NVIDIA HPC SDK includes the compilers formerly known as The Portland Group compilers,
13    https://www.pgroup.com/index.htm.
14    See also `numpy.distutils.fcompiler.pg`.
15    """
16
17    compiler_type = 'nv'
18    description = 'NVIDIA HPC SDK'
19    version_pattern = r'\s*(nvfortran|(pg(f77|f90|fortran)) \(aka nvfortran\)) (?P<version>[\d.-]+).*'
20
21    executables = {
22        'version_cmd': ["<F90>", "-V"],
23        'compiler_f77': ["nvfortran"],
24        'compiler_fix': ["nvfortran", "-Mfixed"],
25        'compiler_f90': ["nvfortran"],
26        'linker_so': ["<F90>"],
27        'archiver': ["ar", "-cr"],
28        'ranlib': ["ranlib"]
29    }
30    pic_flags = ['-fpic']
31
32    module_dir_switch = '-module '
33    module_include_switch = '-I'
34
35    def get_flags(self):
36        opt = ['-Minform=inform', '-Mnosecond_underscore']
37        return self.pic_flags + opt
38
39    def get_flags_opt(self):
40        return ['-fast']
41
42    def get_flags_debug(self):
43        return ['-g']
44
45    def get_flags_linker_so(self):
46        return ["-shared", '-fpic']
47
48    def runtime_library_dir_option(self, dir):
49        return '-R%s' % dir
50
51if __name__ == '__main__':
52    from distutils import log
53    log.set_verbosity(2)
54    from numpy.distutils import customized_fcompiler
55    print(customized_fcompiler(compiler='nv').get_version())
56