intelccompiler.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import platform
  2. from distutils.unixccompiler import UnixCCompiler
  3. from numpy.distutils.exec_command import find_executable
  4. from numpy.distutils.ccompiler import simple_version_match
  5. if platform.system() == 'Windows':
  6. from numpy.distutils.msvc9compiler import MSVCCompiler
  7. class IntelCCompiler(UnixCCompiler):
  8. """A modified Intel compiler compatible with a GCC-built Python."""
  9. compiler_type = 'intel'
  10. cc_exe = 'icc'
  11. cc_args = 'fPIC'
  12. def __init__(self, verbose=0, dry_run=0, force=0):
  13. UnixCCompiler.__init__(self, verbose, dry_run, force)
  14. v = self.get_version()
  15. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  16. self.cc_exe = ('icc -fPIC -fp-model strict -O3 '
  17. '-fomit-frame-pointer -{}').format(mpopt)
  18. compiler = self.cc_exe
  19. if platform.system() == 'Darwin':
  20. shared_flag = '-Wl,-undefined,dynamic_lookup'
  21. else:
  22. shared_flag = '-shared'
  23. self.set_executables(compiler=compiler,
  24. compiler_so=compiler,
  25. compiler_cxx=compiler,
  26. archiver='xiar' + ' cru',
  27. linker_exe=compiler + ' -shared-intel',
  28. linker_so=compiler + ' ' + shared_flag +
  29. ' -shared-intel')
  30. class IntelItaniumCCompiler(IntelCCompiler):
  31. compiler_type = 'intele'
  32. # On Itanium, the Intel Compiler used to be called ecc, let's search for
  33. # it (now it's also icc, so ecc is last in the search).
  34. for cc_exe in map(find_executable, ['icc', 'ecc']):
  35. if cc_exe:
  36. break
  37. class IntelEM64TCCompiler(UnixCCompiler):
  38. """
  39. A modified Intel x86_64 compiler compatible with a 64bit GCC-built Python.
  40. """
  41. compiler_type = 'intelem'
  42. cc_exe = 'icc -m64'
  43. cc_args = '-fPIC'
  44. def __init__(self, verbose=0, dry_run=0, force=0):
  45. UnixCCompiler.__init__(self, verbose, dry_run, force)
  46. v = self.get_version()
  47. mpopt = 'openmp' if v and v < '15' else 'qopenmp'
  48. self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
  49. '-fomit-frame-pointer -{}').format(mpopt)
  50. compiler = self.cc_exe
  51. if platform.system() == 'Darwin':
  52. shared_flag = '-Wl,-undefined,dynamic_lookup'
  53. else:
  54. shared_flag = '-shared'
  55. self.set_executables(compiler=compiler,
  56. compiler_so=compiler,
  57. compiler_cxx=compiler,
  58. archiver='xiar' + ' cru',
  59. linker_exe=compiler + ' -shared-intel',
  60. linker_so=compiler + ' ' + shared_flag +
  61. ' -shared-intel')
  62. if platform.system() == 'Windows':
  63. class IntelCCompilerW(MSVCCompiler):
  64. """
  65. A modified Intel compiler compatible with an MSVC-built Python.
  66. """
  67. compiler_type = 'intelw'
  68. compiler_cxx = 'icl'
  69. def __init__(self, verbose=0, dry_run=0, force=0):
  70. MSVCCompiler.__init__(self, verbose, dry_run, force)
  71. version_match = simple_version_match(start=r'Intel\(R\).*?32,')
  72. self.__version = version_match
  73. def initialize(self, plat_name=None):
  74. MSVCCompiler.initialize(self, plat_name)
  75. self.cc = self.find_exe('icl.exe')
  76. self.lib = self.find_exe('xilib')
  77. self.linker = self.find_exe('xilink')
  78. self.compile_options = ['/nologo', '/O3', '/MD', '/W3',
  79. '/Qstd=c99']
  80. self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
  81. '/Qstd=c99', '/Z7', '/D_DEBUG']
  82. class IntelEM64TCCompilerW(IntelCCompilerW):
  83. """
  84. A modified Intel x86_64 compiler compatible with
  85. a 64bit MSVC-built Python.
  86. """
  87. compiler_type = 'intelemw'
  88. def __init__(self, verbose=0, dry_run=0, force=0):
  89. MSVCCompiler.__init__(self, verbose, dry_run, force)
  90. version_match = simple_version_match(start=r'Intel\(R\).*?64,')
  91. self.__version = version_match