Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a26c130

Browse files
committed
MAINT: Remove distutils CPU dispatcher compatibility code
Since distutils is no longer enabled and NumPy now fully uses Meson for CPU dispatching, we can remove the compatibility layer between the two systems. This simplifies the codebase and removes unnecessary code paths that are no longer needed.
1 parent 9ead596 commit a26c130

30 files changed

Lines changed: 81 additions & 404 deletions

meson_cpu/main_config.h.in

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
*/
1212
#ifndef @P@_CPU_DISPATCHER_CONF_H_
1313
#define @P@_CPU_DISPATCHER_CONF_H_
14-
/// This definition is required to provide compatibility with NumPy distutils
15-
#define @P@_CPU_MESON_BUILD
1614
/**
1715
* @def @P@WITH_CPU_BASELINE
1816
* Enabled baseline features names as a single string where each is separated by a single space.
@@ -79,20 +77,12 @@
7977
* Defines the default behavior for the configurable macros derived from the configuration header
8078
* that is generated by the meson function `mod_features.multi_targets()`.
8179
*
82-
* Note: Providing fallback in case of optimization disabled is no longer needed for meson
83-
* since we always guarantee having configuration headers.
84-
*
85-
* However, it is still needed for compatibility with Numpy distutils.
80+
* These macros are replaced by disapatch config headers once its included.
8681
*/
87-
#ifndef @P@DISABLE_OPTIMIZATION
88-
#define @P@MTARGETS_CONF_BASELINE(CB, ...) \
89-
&&"Expected config header that generated by mod_features.multi_targets()";
90-
#define @P@MTARGETS_CONF_DISPATCH(TEST_FEATURE_CB, CB, ...) \
91-
&&"Expected config header that generated by mod_features.multi_targets()";
92-
#else
93-
#define @P@MTARGETS_CONF_BASELINE(CB, ...) @P@_CPU_EXPAND(CB(__VA_ARGS__))
94-
#define @P@MTARGETS_CONF_DISPATCH(CHK, CB, ...)
95-
#endif
82+
#define @P@MTARGETS_CONF_BASELINE(CB, ...) \
83+
&&"Expected config header that generated by mod_features.multi_targets()";
84+
#define @P@MTARGETS_CONF_DISPATCH(TEST_FEATURE_CB, CB, ...) \
85+
&&"Expected config header that generated by mod_features.multi_targets()";
9686
/**
9787
* @def @P@CPU_DISPATCH_CURFX(NAME)
9888
*
@@ -374,13 +364,33 @@
374364
#include <x86intrin.h>
375365
#endif
376366

367+
#if (defined(@P@HAVE_VSX) || defined(@P@HAVE_VX)) && !defined(__cplusplus) && defined(bool)
368+
/*
369+
* "altivec.h" header contains the definitions(bool, vector, pixel),
370+
* usually in c++ we undefine them after including the header.
371+
* It's better anyway to take them off and use built-in types(__vector, __pixel, __bool) instead,
372+
* since c99 supports bool variables which may lead to ambiguous errors.
373+
*/
374+
// backup 'bool' before including 'npy_cpu_dispatch_config.h', since it may not defined as a compiler token.
375+
#define NPY__CPU_DISPATCH_GUARD_BOOL
376+
typedef bool npy__cpu_dispatch_guard_bool;
377+
#endif
377378
#ifdef @P@HAVE_VSX
378379
#include <altivec.h>
379380
#endif
380-
381381
#ifdef @P@HAVE_VX
382382
#include <vecintrin.h>
383383
#endif
384+
#if (defined(@P@HAVE_VSX) || defined(@P@HAVE_VX))
385+
#undef bool
386+
#undef vector
387+
#undef pixel
388+
#ifdef NPY__CPU_DISPATCH_GUARD_BOOL
389+
#define bool npy__cpu_dispatch_guard_bool
390+
#undef NPY__CPU_DISPATCH_GUARD_BOOL
391+
#endif
392+
#endif
393+
384394

385395
#ifdef @P@HAVE_NEON
386396
#include <arm_neon.h>

numpy/_core/code_generators/generate_umath.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,7 @@ def make_arrays(funcdict):
14791479

14801480
for dname, funcs in dispdict.items():
14811481
code2list.append(textwrap.dedent(f"""
1482-
#ifndef NPY_DISABLE_OPTIMIZATION
14831482
#include "{dname}.dispatch.h"
1484-
#endif
14851483
"""))
14861484
for (ufunc_name, func_idx, cfunc_name, inout) in funcs:
14871485
code2list.append(textwrap.dedent(f"""\

numpy/_core/src/_simd/_simd.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,8 @@ PyMODINIT_FUNC PyInit__simd(void)
8585
goto err; \
8686
} \
8787
}
88-
#ifdef NPY__CPU_MESON_BUILD
89-
NPY_MTARGETS_CONF_DISPATCH(NPY_CPU_HAVE, ATTACH_MODULE, MAKE_MSVC_HAPPY)
90-
NPY_MTARGETS_CONF_BASELINE(ATTACH_BASELINE_MODULE, MAKE_MSVC_HAPPY)
91-
#else
92-
NPY__CPU_DISPATCH_CALL(NPY_CPU_HAVE, ATTACH_MODULE, MAKE_MSVC_HAPPY)
93-
NPY__CPU_DISPATCH_BASELINE_CALL(ATTACH_BASELINE_MODULE, MAKE_MSVC_HAPPY)
94-
#endif
88+
NPY_MTARGETS_CONF_DISPATCH(NPY_CPU_HAVE, ATTACH_MODULE, MAKE_MSVC_HAPPY)
89+
NPY_MTARGETS_CONF_BASELINE(ATTACH_BASELINE_MODULE, MAKE_MSVC_HAPPY)
9590

9691
#if Py_GIL_DISABLED
9792
// signal this module supports running with the GIL disabled

numpy/_core/src/_simd/_simd.dispatch.c.src

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*@targets #simd_test*/
21
#include "_simd.h"
32
#include "_simd_inc.h"
43

numpy/_core/src/_simd/_simd.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
#include "npy_cpu_dispatch.h"
1919
#include "numpy/npy_cpu.h"
2020

21-
#ifndef NPY_DISABLE_OPTIMIZATION
2221
// autogenerated, required for CPU dispatch macros
2322
#include "_simd.dispatch.h"
24-
#endif
2523
/**
2624
* Create a new module for each required optimization which contains all NPYV intrinsics,
2725
*

numpy/_core/src/common/npy_cpu_dispatch.h

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,19 @@
77
* To get a better understanding of the mechanism behind it.
88
*/
99
#include "npy_cpu_features.h" // NPY_CPU_HAVE
10-
#if (defined(__s390x__) || defined(__powerpc64__)) && !defined(__cplusplus) && defined(bool)
11-
/*
12-
* "altivec.h" header contains the definitions(bool, vector, pixel),
13-
* usually in c++ we undefine them after including the header.
14-
* It's better anyway to take them off and use built-in types(__vector, __pixel, __bool) instead,
15-
* since c99 supports bool variables which may lead to ambiguous errors.
16-
*/
17-
// backup 'bool' before including 'npy_cpu_dispatch_config.h', since it may not defined as a compiler token.
18-
#define NPY__CPU_DISPATCH_GUARD_BOOL
19-
typedef bool npy__cpu_dispatch_guard_bool;
20-
#endif
2110
/**
22-
* Including the main configuration header 'npy_cpu_dispatch_config.h'.
23-
* This header is generated by the 'ccompiler_opt' distutils module and the Meson build system.
11+
* This header genereated by the build system and contains:
2412
*
25-
* For the distutils-generated version, it contains:
26-
* - Headers for platform-specific instruction sets.
27-
* - Feature #definitions, e.g. NPY_HAVE_AVX2.
28-
* - Helper macros that encapsulate enabled features through user-defined build options
29-
* '--cpu-baseline' and '--cpu-dispatch'. These options are essential for implementing
30-
* attributes like `__cpu_baseline__` and `__cpu_dispatch__` in the NumPy module.
31-
*
32-
* For the Meson-generated version, it contains:
3313
* - Headers for platform-specific instruction sets.
3414
* - Helper macros that encapsulate enabled features through user-defined build options
3515
* '--cpu-baseline' and '--cpu-dispatch'. These options remain crucial for implementing
3616
* attributes like `__cpu_baseline__` and `__cpu_dispatch__` in the NumPy module.
3717
* - Additional helper macros necessary for runtime dispatching.
3818
*
39-
* Note: In the Meson build, features #definitions are conveyed via compiler arguments.
19+
* Note: features #definitions are conveyed via compiler arguments.
4020
*/
4121
#include "npy_cpu_dispatch_config.h"
42-
#ifndef NPY__CPU_MESON_BUILD
43-
// Define helper macros necessary for runtime dispatching for distutils.
44-
#include "npy_cpu_dispatch_distutils.h"
45-
#endif
46-
#if defined(NPY_HAVE_VSX) || defined(NPY_HAVE_VX)
47-
#undef bool
48-
#undef vector
49-
#undef pixel
50-
#ifdef NPY__CPU_DISPATCH_GUARD_BOOL
51-
#define bool npy__cpu_dispatch_guard_bool
52-
#undef NPY__CPU_DISPATCH_GUARD_BOOL
53-
#endif
54-
#endif
22+
5523
/**
5624
* Initialize the CPU dispatch tracer.
5725
*

numpy/_core/src/common/npy_cpu_dispatch_distutils.h

Lines changed: 0 additions & 116 deletions
This file was deleted.

numpy/_core/src/multiarray/argfunc.dispatch.c.src

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
/* -*- c -*- */
2-
/*@targets
3-
** $maxopt baseline
4-
** sse2 sse42 xop avx2 avx512_skx
5-
** vsx2
6-
** neon asimd
7-
** vx vxe
8-
**/
9-
102
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
113

124
#include "simd/simd.h"

numpy/_core/src/multiarray/arraytypes.c.src

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,9 +4337,7 @@ set_typeinfo(PyObject *dict)
43374337
PyObject *cobj, *key;
43384338

43394339
// SIMD runtime dispatching
4340-
#ifndef NPY_DISABLE_OPTIMIZATION
4341-
#include "argfunc.dispatch.h"
4342-
#endif
4340+
#include "argfunc.dispatch.h"
43434341
/**begin repeat
43444342
* #FROM = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
43454343
* LONG, ULONG, LONGLONG, ULONGLONG,

numpy/_core/src/multiarray/arraytypes.h.src

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ NPY_NO_EXPORT int
4545
/**end repeat**/
4646

4747

48-
#ifndef NPY_DISABLE_OPTIMIZATION
49-
#include "argfunc.dispatch.h"
50-
#endif
48+
#include "argfunc.dispatch.h"
5149
/**begin repeat
5250
* #TYPE = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
5351
* LONG, ULONG, LONGLONG, ULONGLONG,

0 commit comments

Comments
 (0)