build.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. import sys
  3. from distutils.command.build import build as old_build
  4. from distutils.util import get_platform
  5. from numpy.distutils.command.config_compiler import show_fortran_compilers
  6. class build(old_build):
  7. sub_commands = [('config_cc', lambda *args: True),
  8. ('config_fc', lambda *args: True),
  9. ('build_src', old_build.has_ext_modules),
  10. ] + old_build.sub_commands
  11. user_options = old_build.user_options + [
  12. ('fcompiler=', None,
  13. "specify the Fortran compiler type"),
  14. ('warn-error', None,
  15. "turn all warnings into errors (-Werror)"),
  16. ('cpu-baseline=', None,
  17. "specify a list of enabled baseline CPU optimizations"),
  18. ('cpu-dispatch=', None,
  19. "specify a list of dispatched CPU optimizations"),
  20. ('disable-optimization', None,
  21. "disable CPU optimized code(dispatch,simd,fast...)"),
  22. ('simd-test=', None,
  23. "specify a list of CPU optimizations to be tested against NumPy SIMD interface"),
  24. ]
  25. help_options = old_build.help_options + [
  26. ('help-fcompiler', None, "list available Fortran compilers",
  27. show_fortran_compilers),
  28. ]
  29. def initialize_options(self):
  30. old_build.initialize_options(self)
  31. self.fcompiler = None
  32. self.warn_error = False
  33. self.cpu_baseline = "min"
  34. self.cpu_dispatch = "max -xop -fma4" # drop AMD legacy features by default
  35. self.disable_optimization = False
  36. """
  37. the '_simd' module is a very large. Adding more dispatched features
  38. will increase binary size and compile time. By default we minimize
  39. the targeted features to those most commonly used by the NumPy SIMD interface(NPYV),
  40. NOTE: any specified features will be ignored if they're:
  41. - part of the baseline(--cpu-baseline)
  42. - not part of dispatch-able features(--cpu-dispatch)
  43. - not supported by compiler or platform
  44. """
  45. self.simd_test = "BASELINE SSE2 SSE42 XOP FMA4 (FMA3 AVX2) AVX512F AVX512_SKX VSX VSX2 VSX3 NEON ASIMD"
  46. def finalize_options(self):
  47. build_scripts = self.build_scripts
  48. old_build.finalize_options(self)
  49. plat_specifier = ".{}-{}.{}".format(get_platform(), *sys.version_info[:2])
  50. if build_scripts is None:
  51. self.build_scripts = os.path.join(self.build_base,
  52. 'scripts' + plat_specifier)
  53. def run(self):
  54. old_build.run(self)