intelccompiler.py 4.2 KB

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