From 4c97add06371bf80f3bc02e0cfb0ee83737b909c Mon Sep 17 00:00:00 2001 From: Sayed Adel Date: Sat, 13 Jun 2020 18:15:41 +0200 Subject: ENH: [3/7] enable multi-platform SIMD compiler optimizations - Put `CCompilerOpt` in action through add two command line arguments that passed directly to `CCompilerOpt`'s parameters which explained as follows: * `--cpu-baseline` minimal set of required optimizations, default is 'min' which provides the minimum CPU features that can safely run on a wide range of users platforms. * `--cpu-dispatch` dispatched set of additional optimizations, default is 'max-xop-fma4' which enables all CPU features, except for AMD legacy features. the new arguments can be reached from `build`, `build_clib`, `build_ext`, if `build_clib` or `build_ext` are not specified by the user the arguments of `build` will be used, which also hold the default values. - Activate the new compiler dispatcher that comes with `CCompilerOpt`, through adding a hock inside `build_clib` and `build_ext` that works as a filter taking any C source files ends with `.dispatch.c` and pass it directly to `CCompilerOpt` and then take returned objects and linked to the final C lib. - Add a third command-line argument `--disable-optimization` which explicitly disable the whole new infrastructure, also It adds a new compiler definition called `NPY_DISABLE_OPTIMIZATION`. when `--disable-optimization` is enabled the dispatch-able sources that end with `.dispatch.c` will be treated as a normal C sources, also due to this disabling any C headers that generated by `CCompilerOpt` must guard it with `NPY_DISABLE_OPTIMIZATION`, otherwise, it will definitely break the build. - New auto-generated C header located at `core/include/numpy/_cpu_dispatch.h`, the new header contains all definitions and headers of CPU features that enabled according to specified configuration in `--cpu-baseline` and `--cpu-dispatch`. --- numpy/distutils/command/build.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'numpy/distutils/command/build.py') diff --git a/numpy/distutils/command/build.py b/numpy/distutils/command/build.py index a156a7c6e..60ba4c917 100644 --- a/numpy/distutils/command/build.py +++ b/numpy/distutils/command/build.py @@ -16,6 +16,12 @@ class build(old_build): "specify the Fortran compiler type"), ('warn-error', None, "turn all warnings into errors (-Werror)"), + ('cpu-baseline=', None, + "specify a list of enabled baseline CPU optimizations"), + ('cpu-dispatch=', None, + "specify a list of dispatched CPU optimizations"), + ('disable-optimization', None, + "disable CPU optimized code(dispatch,simd,fast...)"), ] help_options = old_build.help_options + [ @@ -27,6 +33,9 @@ class build(old_build): old_build.initialize_options(self) self.fcompiler = None self.warn_error = False + self.cpu_baseline = "min" + self.cpu_dispatch = "max -xop -fma4" # drop AMD legacy features by default + self.disable_optimization = False def finalize_options(self): build_scripts = self.build_scripts -- cgit v1.2.1