intel.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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', '-{}'.format(mpopt)]
  46. def get_flags_arch(self):
  47. return []
  48. def get_flags_linker_so(self):
  49. opt = FCompiler.get_flags_linker_so(self)
  50. v = self.get_version()
  51. if v and v >= '8.0':
  52. opt.append('-nofor_main')
  53. if sys.platform == 'darwin':
  54. # Here, it's -dynamiclib
  55. try:
  56. idx = opt.index('-shared')
  57. opt.remove('-shared')
  58. except ValueError:
  59. idx = 0
  60. opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup']
  61. return opt
  62. class IntelItaniumFCompiler(IntelFCompiler):
  63. compiler_type = 'intele'
  64. compiler_aliases = ()
  65. description = 'Intel Fortran Compiler for Itanium apps'
  66. version_match = intel_version_match('Itanium|IA-64')
  67. possible_executables = ['ifort', 'efort', 'efc']
  68. executables = {
  69. 'version_cmd' : None,
  70. 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
  71. 'compiler_fix' : [None, "-FI"],
  72. 'compiler_f90' : [None],
  73. 'linker_so' : ['<F90>', "-shared"],
  74. 'archiver' : ["ar", "-cr"],
  75. 'ranlib' : ["ranlib"]
  76. }
  77. class IntelEM64TFCompiler(IntelFCompiler):
  78. compiler_type = 'intelem'
  79. compiler_aliases = ()
  80. description = 'Intel Fortran Compiler for 64-bit apps'
  81. version_match = intel_version_match('EM64T-based|Intel\\(R\\) 64|64|IA-64|64-bit')
  82. possible_executables = ['ifort', 'efort', 'efc']
  83. executables = {
  84. 'version_cmd' : None,
  85. 'compiler_f77' : [None, "-FI"],
  86. 'compiler_fix' : [None, "-FI"],
  87. 'compiler_f90' : [None],
  88. 'linker_so' : ['<F90>', "-shared"],
  89. 'archiver' : ["ar", "-cr"],
  90. 'ranlib' : ["ranlib"]
  91. }
  92. def get_flags(self):
  93. return ['-fPIC']
  94. def get_flags_opt(self): # Scipy test failures with -O2
  95. v = self.get_version()
  96. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  97. return ['-fp-model', 'strict', '-O1', '-{}'.format(mpopt)]
  98. def get_flags_arch(self):
  99. return []
  100. # Is there no difference in the version string between the above compilers
  101. # and the Visual compilers?
  102. class IntelVisualFCompiler(BaseIntelFCompiler):
  103. compiler_type = 'intelv'
  104. description = 'Intel Visual Fortran Compiler for 32-bit apps'
  105. version_match = intel_version_match('32-bit|IA-32')
  106. def update_executables(self):
  107. f = dummy_fortran_file()
  108. self.executables['version_cmd'] = ['<F77>', '/FI', '/c',
  109. f + '.f', '/o', f + '.o']
  110. ar_exe = 'lib.exe'
  111. possible_executables = ['ifort', 'ifl']
  112. executables = {
  113. 'version_cmd' : None,
  114. 'compiler_f77' : [None],
  115. 'compiler_fix' : [None],
  116. 'compiler_f90' : [None],
  117. 'linker_so' : [None],
  118. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  119. 'ranlib' : None
  120. }
  121. compile_switch = '/c '
  122. object_switch = '/Fo' # No space after /Fo!
  123. library_switch = '/OUT:' # No space after /OUT:!
  124. module_dir_switch = '/module:' # No space after /module:
  125. module_include_switch = '/I'
  126. def get_flags(self):
  127. opt = ['/nologo', '/MD', '/nbs', '/names:lowercase', '/assume:underscore']
  128. return opt
  129. def get_flags_free(self):
  130. return []
  131. def get_flags_debug(self):
  132. return ['/4Yb', '/d2']
  133. def get_flags_opt(self):
  134. return ['/O1'] # Scipy test failures with /O2
  135. def get_flags_arch(self):
  136. return ["/arch:IA32", "/QaxSSE3"]
  137. def runtime_library_dir_option(self, dir):
  138. raise NotImplementedError
  139. class IntelItaniumVisualFCompiler(IntelVisualFCompiler):
  140. compiler_type = 'intelev'
  141. description = 'Intel Visual Fortran Compiler for Itanium apps'
  142. version_match = intel_version_match('Itanium')
  143. possible_executables = ['efl'] # XXX this is a wild guess
  144. ar_exe = IntelVisualFCompiler.ar_exe
  145. executables = {
  146. 'version_cmd' : None,
  147. 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
  148. 'compiler_fix' : [None, "-FI", "-4L72", "-w"],
  149. 'compiler_f90' : [None],
  150. 'linker_so' : ['<F90>', "-shared"],
  151. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  152. 'ranlib' : None
  153. }
  154. class IntelEM64VisualFCompiler(IntelVisualFCompiler):
  155. compiler_type = 'intelvem'
  156. description = 'Intel Visual Fortran Compiler for 64-bit apps'
  157. version_match = simple_version_match(start=r'Intel\(R\).*?64,')
  158. def get_flags_arch(self):
  159. return []
  160. if __name__ == '__main__':
  161. from distutils import log
  162. log.set_verbosity(2)
  163. from numpy.distutils import customized_fcompiler
  164. print(customized_fcompiler(compiler='intel').get_version())