diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-01-03 09:22:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-03 09:22:18 +0200 |
commit | 555b3d8e10745bed72e25e70465ac447009fa8d2 (patch) | |
tree | feffae5d3635d9414aea67315f4ad2298be98782 | |
parent | d4f7d9e215773e979eb43a1e5a3cbb51f96bd09d (diff) | |
parent | ce6cd579d4accd81edfd96fd8b7923455d5a9e61 (diff) | |
download | numpy-555b3d8e10745bed72e25e70465ac447009fa8d2.tar.gz |
Merge pull request #18100 from seiko2plus/issue_18092
BUG, BLD: Generate the main dispatcher config header into the build dir
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | numpy/core/src/common/npy_cpu_dispatch.h | 6 | ||||
-rw-r--r-- | numpy/distutils/ccompiler_opt.py | 36 | ||||
-rw-r--r-- | numpy/distutils/command/build_clib.py | 18 | ||||
-rw-r--r-- | numpy/distutils/command/build_ext.py | 22 |
5 files changed, 51 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore index 5a5e464cc..b1a8db5c3 100644 --- a/.gitignore +++ b/.gitignore @@ -204,9 +204,6 @@ tools/swig/test/Array.py # SIMD generated files # ################################### -# the main config header, contains all the definitions and -# headers of instruction-sets -numpy/core/src/common/_cpu_dispatch.h # config headers of dispatchable sources *.dispatch.h # wrapped sources of dispatched targets, e.g. *.dispatch.avx2.c diff --git a/numpy/core/src/common/npy_cpu_dispatch.h b/numpy/core/src/common/npy_cpu_dispatch.h index a0f82fa3d..c8411104a 100644 --- a/numpy/core/src/common/npy_cpu_dispatch.h +++ b/numpy/core/src/common/npy_cpu_dispatch.h @@ -7,10 +7,10 @@ #include "npy_cpu_features.h" // NPY_CPU_HAVE #include "numpy/utils.h" // NPY_EXPAND, NPY_CAT /** - * Bringing the main configration header '_cpu_dispatch.h'. + * Including the main configuration header 'npy_cpu_dispatch_config.h'. * * This header is generated by the distutils module 'ccompiler_opt', - * and contains all the #definitions and headers of instruction-sets, + * and contains all the #definitions and headers for platform-specific instruction-sets * that had been configured through command arguments '--cpu-baseline' and '--cpu-dispatch'. * * It also contains extra C #definitions and macros that are used for implementing @@ -33,7 +33,7 @@ #define NPY__DISPATCH_DEFBOOL typedef bool npy__dispatch_bkbool; #endif - #include "_cpu_dispatch.h" + #include "npy_cpu_dispatch_config.h" #ifdef NPY_HAVE_VSX #undef bool #undef vector diff --git a/numpy/distutils/ccompiler_opt.py b/numpy/distutils/ccompiler_opt.py index ecf5172cc..5fa17b2ee 100644 --- a/numpy/distutils/ccompiler_opt.py +++ b/numpy/distutils/ccompiler_opt.py @@ -2225,8 +2225,8 @@ class CCompilerOpt(_Config, _Distutils, _Cache, _CCompiler, _Feature, _Parse): def generate_dispatch_header(self, header_path): """ - Generate the dispatch header which containing all definitions - and headers of instruction-sets for the enabled CPU baseline and + Generate the dispatch header which contains the #definitions and headers + for platform-specific instruction-sets for the enabled CPU baseline and dispatch-able features. Its highly recommended to take a look at the generated header @@ -2240,6 +2240,14 @@ class CCompilerOpt(_Config, _Distutils, _Cache, _CCompiler, _Feature, _Parse): baseline_len = len(baseline_names) dispatch_len = len(dispatch_names) + header_dir = os.path.dirname(header_path) + if not os.path.exists(header_dir): + self.dist_log( + f"dispatch header dir {header_dir} does not exist, creating it", + stderr=True + ) + os.makedirs(header_dir) + with open(header_path, 'w') as f: baseline_calls = ' \\\n'.join([ ( @@ -2504,30 +2512,24 @@ class CCompilerOpt(_Config, _Distutils, _Cache, _CCompiler, _Feature, _Parse): )) return False -def new_ccompiler_opt(compiler, **kwargs): +def new_ccompiler_opt(compiler, dispatch_hpath, **kwargs): """ Create a new instance of 'CCompilerOpt' and generate the dispatch header - inside NumPy source dir. + which contains the #definitions and headers of platform-specific instruction-sets for + the enabled CPU baseline and dispatch-able features. Parameters ---------- - 'compiler' : CCompiler instance - '**kwargs': passed as-is to `CCompilerOpt(...)` + compiler : CCompiler instance + dispatch_hpath : str + path of the dispatch header + **kwargs: passed as-is to `CCompilerOpt(...)` Returns ------- new instance of CCompilerOpt """ opt = CCompilerOpt(compiler, **kwargs) - npy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) - header_dir = os.path.join(npy_path, *("core/src/common".split("/"))) - header_path = os.path.join(header_dir, "_cpu_dispatch.h") - if not os.path.exists(header_path) or not opt.is_cached(): - if not os.path.exists(header_dir): - opt.dist_log( - "dispatch header dir '%s' isn't exist, creating it" % header_dir, - stderr=True - ) - os.makedirs(header_dir) - opt.generate_dispatch_header(header_path) + if not os.path.exists(dispatch_hpath) or not opt.is_cached(): + opt.generate_dispatch_header(dispatch_hpath) return opt diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py index a0db6f31f..1b3004c2f 100644 --- a/numpy/distutils/command/build_clib.py +++ b/numpy/distutils/command/build_clib.py @@ -118,12 +118,15 @@ class build_clib(old_build_clib): self.compiler.show_customization() if not self.disable_optimization: + dispatch_hpath = os.path.join("numpy", "distutils", "include", "npy_cpu_dispatch_config.h") + dispatch_hpath = os.path.join(self.get_finalized_command("build_src").build_src, dispatch_hpath) opt_cache_path = os.path.abspath( - os.path.join(self.build_temp, 'ccompiler_opt_cache_clib.py' - )) + os.path.join(self.build_temp, 'ccompiler_opt_cache_clib.py') + ) self.compiler_opt = new_ccompiler_opt( - compiler=self.compiler, cpu_baseline=self.cpu_baseline, - cpu_dispatch=self.cpu_dispatch, cache_path=opt_cache_path + compiler=self.compiler, dispatch_hpath=dispatch_hpath, + cpu_baseline=self.cpu_baseline, cpu_dispatch=self.cpu_dispatch, + cache_path=opt_cache_path ) if not self.compiler_opt.is_cached(): log.info("Detected changes on compiler optimizations, force rebuilding") @@ -271,7 +274,12 @@ class build_clib(old_build_clib): copt_baseline_flags = [] copt_macros = [] if not self.disable_optimization: - copt_build_src = None if self.inplace else self.get_finalized_command("build_src").build_src + bsrc_dir = self.get_finalized_command("build_src").build_src + dispatch_hpath = os.path.join("numpy", "distutils", "include") + dispatch_hpath = os.path.join(bsrc_dir, dispatch_hpath) + include_dirs.append(dispatch_hpath) + + copt_build_src = None if self.inplace else bsrc_dir copt_c_sources = [ c_sources.pop(c_sources.index(src)) for src in c_sources[:] if src.endswith(".dispatch.c") diff --git a/numpy/distutils/command/build_ext.py b/numpy/distutils/command/build_ext.py index ca6f8bcd2..448f7941c 100644 --- a/numpy/distutils/command/build_ext.py +++ b/numpy/distutils/command/build_ext.py @@ -146,11 +146,16 @@ class build_ext (old_build_ext): self.compiler.show_customization() if not self.disable_optimization: - opt_cache_path = os.path.abspath(os.path.join(self.build_temp, 'ccompiler_opt_cache_ext.py')) - self.compiler_opt = new_ccompiler_opt(compiler=self.compiler, - cpu_baseline=self.cpu_baseline, - cpu_dispatch=self.cpu_dispatch, - cache_path=opt_cache_path) + dispatch_hpath = os.path.join("numpy", "distutils", "include", "npy_cpu_dispatch_config.h") + dispatch_hpath = os.path.join(self.get_finalized_command("build_src").build_src, dispatch_hpath) + opt_cache_path = os.path.abspath( + os.path.join(self.build_temp, 'ccompiler_opt_cache_ext.py') + ) + self.compiler_opt = new_ccompiler_opt( + compiler=self.compiler, dispatch_hpath=dispatch_hpath, + cpu_baseline=self.cpu_baseline, cpu_dispatch=self.cpu_dispatch, + cache_path=opt_cache_path + ) if not self.compiler_opt.is_cached(): log.info("Detected changes on compiler optimizations, force rebuilding") self.force = True @@ -416,7 +421,12 @@ class build_ext (old_build_ext): copt_baseline_flags = [] copt_macros = [] if not self.disable_optimization: - copt_build_src = None if self.inplace else self.get_finalized_command("build_src").build_src + bsrc_dir = self.get_finalized_command("build_src").build_src + dispatch_hpath = os.path.join("numpy", "distutils", "include") + dispatch_hpath = os.path.join(bsrc_dir, dispatch_hpath) + include_dirs.append(dispatch_hpath) + + copt_build_src = None if self.inplace else bsrc_dir copt_c_sources = [ c_sources.pop(c_sources.index(src)) for src in c_sources[:] if src.endswith(".dispatch.c") |