intel.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # http://developer.intel.com/software/products/compilers/flin/
  2. from __future__ import division, absolute_import, print_function
  3. import sys
  4. from numpy.distutils.ccompiler import simple_version_match
  5. from numpy.distutils.fcompiler import FCompiler, dummy_fortran_file
  6. compilers = ['IntelFCompiler', 'IntelVisualFCompiler',
  7. 'IntelItaniumFCompiler', 'IntelItaniumVisualFCompiler',
  8. 'IntelEM64VisualFCompiler', 'IntelEM64TFCompiler']
  9. def intel_version_match(type):
  10. # Match against the important stuff in the version string
  11. return simple_version_match(start=r'Intel.*?Fortran.*?(?:%s).*?Version' % (type,))
  12. class BaseIntelFCompiler(FCompiler):
  13. def update_executables(self):
  14. f = dummy_fortran_file()
  15. self.executables['version_cmd'] = ['<F77>', '-FI', '-V', '-c',
  16. f + '.f', '-o', f + '.o']
  17. def runtime_library_dir_option(self, dir):
  18. # TODO: could use -Xlinker here, if it's supported
  19. assert "," not in dir
  20. return '-Wl,-rpath=%s' % dir
  21. class IntelFCompiler(BaseIntelFCompiler):
  22. compiler_type = 'intel'
  23. compiler_aliases = ('ifort',)
  24. description = 'Intel Fortran Compiler for 32-bit apps'
  25. version_match = intel_version_match('32-bit|IA-32')
  26. possible_executables = ['ifort', 'ifc']
  27. executables = {
  28. 'version_cmd' : None, # set by update_executables
  29. 'compiler_f77' : [None, "-72", "-w90", "-w95"],
  30. 'compiler_f90' : [None],
  31. 'compiler_fix' : [None, "-FI"],
  32. 'linker_so' : ["<F90>", "-shared"],
  33. 'archiver' : ["ar", "-cr"],
  34. 'ranlib' : ["ranlib"]
  35. }
  36. pic_flags = ['-fPIC']
  37. module_dir_switch = '-module ' # Don't remove ending space!
  38. module_include_switch = '-I'
  39. def get_flags_free(self):
  40. return ['-FR']
  41. def get_flags(self):
  42. return ['-fPIC']
  43. def get_flags_opt(self): # Scipy test failures with -O2
  44. v = self.get_version()
  45. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  46. return ['-fp-model strict -O1 -{}'.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. def get_flags(self):
  94. return ['-fPIC']
  95. def get_flags_opt(self): # Scipy test failures with -O2
  96. v = self.get_version()
  97. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  98. return ['-fp-model strict -O1 -{}'.format(mpopt)]
  99. def get_flags_arch(self):
  100. return ['']
  101. # Is there no difference in the version string between the above compilers
  102. # and the Visual compilers?
  103. class IntelVisualFCompiler(BaseIntelFCompiler):
  104. compiler_type = 'intelv'
  105. description = 'Intel Visual Fortran Compiler for 32-bit apps'
  106. version_match = intel_version_match('32-bit|IA-32')
  107. def update_executables(self):
  108. f = dummy_fortran_file()
  109. self.executables['version_cmd'] = ['<F77>', '/FI', '/c',
  110. f + '.f', '/o', f + '.o']
  111. ar_exe = 'lib.exe'
  112. possible_executables = ['ifort', 'ifl']
  113. executables = {
  114. 'version_cmd' : None,
  115. 'compiler_f77' : [None],
  116. 'compiler_fix' : [None],
  117. 'compiler_f90' : [None],
  118. 'linker_so' : [None],
  119. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  120. 'ranlib' : None
  121. }
  122. compile_switch = '/c '
  123. object_switch = '/Fo' # No space after /Fo!
  124. library_switch = '/OUT:' # No space after /OUT:!
  125. module_dir_switch = '/module:' # No space after /module:
  126. module_include_switch = '/I'
  127. def get_flags(self):
  128. opt = ['/nologo', '/MD', '/nbs', '/names:lowercase', '/assume:underscore']
  129. return opt
  130. def get_flags_free(self):
  131. return []
  132. def get_flags_debug(self):
  133. return ['/4Yb', '/d2']
  134. def get_flags_opt(self):
  135. return ['/O1'] # Scipy test failures with /O2
  136. def get_flags_arch(self):
  137. return ["/arch:IA32", "/QaxSSE3"]
  138. def runtime_library_dir_option(self, dir):
  139. raise NotImplementedError
  140. class IntelItaniumVisualFCompiler(IntelVisualFCompiler):
  141. compiler_type = 'intelev'
  142. description = 'Intel Visual Fortran Compiler for Itanium apps'
  143. version_match = intel_version_match('Itanium')
  144. possible_executables = ['efl'] # XXX this is a wild guess
  145. ar_exe = IntelVisualFCompiler.ar_exe
  146. executables = {
  147. 'version_cmd' : None,
  148. 'compiler_f77' : [None, "-FI", "-w90", "-w95"],
  149. 'compiler_fix' : [None, "-FI", "-4L72", "-w"],
  150. 'compiler_f90' : [None],
  151. 'linker_so' : ['<F90>', "-shared"],
  152. 'archiver' : [ar_exe, "/verbose", "/OUT:"],
  153. 'ranlib' : None
  154. }
  155. class IntelEM64VisualFCompiler(IntelVisualFCompiler):
  156. compiler_type = 'intelvem'
  157. description = 'Intel Visual Fortran Compiler for 64-bit apps'
  158. version_match = simple_version_match(start=r'Intel\(R\).*?64,')
  159. def get_flags_arch(self):
  160. return ['']
  161. if __name__ == '__main__':
  162. from distutils import log
  163. log.set_verbosity(2)
  164. from numpy.distutils import customized_fcompiler
  165. print(customized_fcompiler(compiler='intel').get_version())