intel.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # http://developer.intel.com/software/products/compilers/flin/
  2. import sys
  3. from numpy.distutils.ccompiler import simple_version_match
  4. from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
  5. compilers = ['IntelFCompiler', 'IntelVisualFCompiler',
  6. 'IntelItaniumFCompiler', 'IntelItaniumVisualFCompiler',
  7. 'IntelEM64VisualFCompiler', 'IntelEM64TFCompiler']
  8. def intel_version_match(type):
  9. # Match against the important stuff in the version string
  10. return simple_version_match(start=r'Intel.*?Fortran.*?(?:%s).*?Version' % (type,))
  11. class BaseIntelFCompiler(FCompiler):
  12. def update_executables(self):
  13. f = dummy_fortran_file()
  14. self.executables['version_cmd'] = ['<F77>', '-FI', '-V', '-c',
  15. f + '.f', '-o', f + '.o']
  16. def runtime_library_dir_option(self, dir):
  17. # TODO: could use -Xlinker here, if it's supported
  18. assert "," not in dir
  19. return '-Wl,-rpath=%s' % dir
  20. class IntelFCompiler(BaseIntelFCompiler):
  21. compiler_type = 'intel'
  22. compiler_aliases = ('ifort',)
  23. description = 'Intel Fortran Compiler for 32-bit apps'
  24. version_match = intel_version_match('32-bit|IA-32')
  25. possible_executables = ['ifort', 'ifc']
  26. executables = {
  27. 'version_cmd' : None, # set by update_executables
  28. 'compiler_f77' : [None, "-72", "-w90", "-w95"],
  29. 'compiler_f90' : [None],
  30. 'compiler_fix' : [None, "-FI"],
  31. 'linker_so' : ["<F90>", "-shared"],
  32. 'archiver' : ["ar", "-cr"],
  33. 'ranlib' : ["ranlib"]
  34. }
  35. pic_flags = ['-fPIC']
  36. module_dir_switch = '-module ' # Don't remove ending space!
  37. module_include_switch = '-I'
  38. def get_flags_free(self):
  39. return ['-FR']
  40. def get_flags(self):
  41. return ['-fPIC']
  42. def get_flags_opt(self): # Scipy test failures with -O2
  43. v = self.get_version()
  44. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  45. return ['-fp-model', 'strict', '-O1',
  46. '-assume', 'minus0', '-{}'.format(mpopt)]
  47. def get_flags_arch(self):
  48. return []
  49. def get_flags_linker_so(self):
  50. opt = FCompiler.get_flags_linker_so(self)
  51. v = self.get_version()
  52. if v and v >= '8.0':
  53. opt.append('-nofor_main')
  54. if sys.platform == 'darwin':
  55. # Here, it's -dynamiclib
  56. try:
  57. idx = opt.index('-shared')
  58. opt.remove('-shared')
  59. except ValueError:
  60. idx = 0
  61. opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup']
  62. return opt
  63. class IntelItaniumFCompiler(IntelFCompiler):
  64. compiler_type = 'intele'
  65. compiler_aliases = ()
  66. description = 'Intel Fortran Compiler for Itanium apps'
  67. version_match = intel_version_match('Itanium|IA-64')
  68. possible_executables = ['ifort', 'efort', 'efc']
  69. executables = {
  70. 'version_cmd' : None,
  71. 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
  72. 'compiler_fix' : [None, "-FI"],
  73. 'compiler_f90' : [None],
  74. 'linker_so' : ['<F90>', "-shared"],
  75. 'archiver' : ["ar", "-cr"],
  76. 'ranlib' : ["ranlib"]
  77. }
  78. class IntelEM64TFCompiler(IntelFCompiler):
  79. compiler_type = 'intelem'
  80. compiler_aliases = ()
  81. description = 'Intel Fortran Compiler for 64-bit apps'
  82. version_match = intel_version_match('EM64T-based|Intel\\(R\\) 64|64|IA-64|64-bit')
  83. possible_executables = ['ifort', 'efort', 'efc']
  84. executables = {
  85. 'version_cmd' : None,
  86. 'compiler_f77' : [None, "-FI"],
  87. 'compiler_fix' : [None, "-FI"],
  88. 'compiler_f90' : [None],
  89. 'linker_so' : ['<F90>', "-shared"],
  90. 'archiver' : ["ar", "-cr"],
  91. 'ranlib' : ["ranlib"]
  92. }
  93. # Is there no difference in the version string between the above compilers
  94. # and the Visual compilers?
  95. class IntelVisualFCompiler(BaseIntelFCompiler):
  96. compiler_type = 'intelv'
  97. description = 'Intel Visual Fortran Compiler for 32-bit apps'
  98. version_match = intel_version_match('32-bit|IA-32')
  99. def update_executables(self):
  100. f = dummy_fortran_file()
  101. self.executables['version_cmd'] = ['<F77>', '/FI', '/c',
  102. f + '.f', '/o', f + '.o']
  103. ar_exe = 'lib.exe'
  104. possible_executables = ['ifort', 'ifl']
  105. executables = {
  106. 'version_cmd' : None,
  107. 'compiler_f77' : [None],
  108. 'compiler_fix' : [None],
  109. 'compiler_f90' : [None],
  110. 'linker_so' : [None],
  111. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  112. 'ranlib' : None
  113. }
  114. compile_switch = '/c '
  115. object_switch = '/Fo' # No space after /Fo!
  116. library_switch = '/OUT:' # No space after /OUT:!
  117. module_dir_switch = '/module:' # No space after /module:
  118. module_include_switch = '/I'
  119. def get_flags(self):
  120. opt = ['/nologo', '/MD', '/nbs', '/names:lowercase', '/assume:underscore']
  121. return opt
  122. def get_flags_free(self):
  123. return []
  124. def get_flags_debug(self):
  125. return ['/4Yb', '/d2']
  126. def get_flags_opt(self):
  127. return ['/O1', '/assume:minus0'] # Scipy test failures with /O2
  128. def get_flags_arch(self):
  129. return ["/arch:IA32", "/QaxSSE3"]
  130. def runtime_library_dir_option(self, dir):
  131. raise NotImplementedError
  132. class IntelItaniumVisualFCompiler(IntelVisualFCompiler):
  133. compiler_type = 'intelev'
  134. description = 'Intel Visual Fortran Compiler for Itanium apps'
  135. version_match = intel_version_match('Itanium')
  136. possible_executables = ['efl'] # XXX this is a wild guess
  137. ar_exe = IntelVisualFCompiler.ar_exe
  138. executables = {
  139. 'version_cmd' : None,
  140. 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
  141. 'compiler_fix' : [None, "-FI", "-4L72", "-w"],
  142. 'compiler_f90' : [None],
  143. 'linker_so' : ['<F90>', "-shared"],
  144. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  145. 'ranlib' : None
  146. }
  147. class IntelEM64VisualFCompiler(IntelVisualFCompiler):
  148. compiler_type = 'intelvem'
  149. description = 'Intel Visual Fortran Compiler for 64-bit apps'
  150. version_match = simple_version_match(start=r'Intel\(R\).*?64,')
  151. def get_flags_arch(self):
  152. return []
  153. if __name__ == '__main__':
  154. from distutils import log
  155. log.set_verbosity(2)
  156. from numpy.distutils import customized_fcompiler
  157. print(customized_fcompiler(compiler='intel').get_version())