8000 ENH: improve runtime detection of CPU features by seiko2plus · Pull Request #13421 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: improve runtime detection of CPU features #13421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/release/13421.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Improve detection of CPU features
=================================

Replace ``npy_cpu_supports`` which was a gcc-specific mechanism to test support
of avx with more general functions ``npy_cpu_init`` and ``npy_cpu_have``, and
expose the results via a ``NPY_CPU_HAVE`` c-macro as well as a python-level
``__cpu_features__`` dictionary.

1 change: 1 addition & 0 deletions doc/release/upcoming_changes/template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% if definitions[category]['showcontent'] %}
{% for text, values in sections[section][category].items() %}
{{ text }}

{{ get_indent(text) }}({{values|join(', ') }})

{% endfor %}
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/code_generators/generate_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def make_arrays(funcdict):
for vt in t.simd:
code2list.append(textwrap.dedent("""\
#ifdef HAVE_ATTRIBUTE_TARGET_{ISA}
if (npy_cpu_supports("{isa}")) {{
if (NPY_CPU_HAVE({ISA})) {{
{fname}_functions[{idx}] = {type}_{fname}_{isa};
}}
#endif
Expand Down Expand Up @@ -1137,7 +1137,6 @@ def make_code(funcdict, filename):

Please make changes to the code generator program (%s)
**/
#include "cpuid.h"
#include "ufunc_object.h"
#include "ufunc_type_resolution.h"
#include "loops.h"
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ def get_mathlib_info(*args):
join('src', 'common', 'ucsnarrow.c'),
join('src', 'common', 'ufunc_override.c'),
join('src', 'common', 'numpyos.c'),
join('src', 'common', 'npy_cpu_features.c.src'),
]

if os.environ.get('NPY_USE_BLAS_ILP64', "0") != "0":
Expand Down Expand Up @@ -898,7 +899,6 @@ def generate_umath_c(ext, build_dir):
join('src', 'umath', 'clip.c.src'),
join('src', 'umath', 'ufunc_object.c'),
join('src', 'umath', 'extobj.c'),
join('src', 'umath', 'cpuid.c'),
join('src', 'umath', 'scalarmath.c.src'),
join('src', 'umath', 'ufunc_type_resolution.c'),
join('src', 'umath', 'override.c'),
Expand Down
5 changes: 0 additions & 5 deletions numpy/core/setup_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,6 @@ def check_api_version(apiversion, codegen_dir):
("__builtin_bswap64", '5u'),
("__builtin_expect", '5, 0'),
("__builtin_mul_overflow", '5, 5, (int*)5'),
# broken on OSX 10.11, make sure its not optimized away
("volatile int r = __builtin_cpu_supports", '"sse"',
"stdio.h", "__BUILTIN_CPU_SUPPORTS"),
("volatile int r = __builtin_cpu_supports", '"avx512f"',
"stdio.h", "__BUILTIN_CPU_SUPPORTS_AVX512F"),
# MMX only needed for icc, but some clangs don't have it
("_m_from_int64", '0', "emmintrin.h"),
("_mm_load_ps", '(float*)0', "xmmintrin.h"), # SSE
Expand Down
1 change: 1 addition & 0 deletions numpy/core/src/common/npy_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _NPY_NPY_CONFIG_H_

#include "config.h"
#include "npy_cpu_features.h"
#include "numpy/numpyconfig.h"
#include "numpy/npy_cpu.h"
#include "numpy/npy_os.h"
Expand Down
Loading
0