8000 ENH, TST: Bring the NumPy C SIMD vectorization interface "NPYV" to Python by seiko2plus · Pull Request #16782 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH, TST: Bring the NumPy C SIMD vectorization interface "NPYV" to Python #16782

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 11 commits into from
Oct 29, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ doc/release/*.rst merge=union
# Highlight our custom templating language as C, since it's hopefully better
# than nothing. This also affects repo statistics.
*.c.src linguist-language=C
*.inc.src linguist-language=C
*.h.src linguist-language=C

# Mark some files as vendored
Expand Down
23 changes: 23 additions & 0 deletions numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def generate_api(ext, build_dir):
config.add_include_dirs(join('src', 'multiarray'))
config.add_include_dirs(join('src', 'umath'))
config.add_include_dirs(join('src', 'npysort'))
config.add_include_dirs(join('src', '_simd'))

config.add_define_macros([("NPY_INTERNAL_BUILD", "1")]) # this macro indicates that Numpy build is in process
config.add_define_macros([("HAVE_NPY_CONFIG_H", "1")])
Expand Down Expand Up @@ -974,6 +975,28 @@ def generate_umath_c(ext, build_dir):
config.add_extension('_operand_flag_tests',
sources=[join('src', 'umath', '_operand_flag_tests.c.src')])

#######################################################################
# SIMD module #
#######################################################################

config.add_extension('_simd', sources=[
join('src', 'common', 'npy_cpu_features.c.src'),
join('src', '_simd', '_simd.c'),
join('src', '_simd', '_simd_inc.h.src'),
join('src', '_simd', '_simd_data.inc.src'),
join('src', '_simd', '_simd.dispatch.c.src'),
], depends=[
join('src', 'common', 'npy_cpu_dispatch.h'),
join('src', 'common', 'simd', 'simd.h'),
join('src', '_simd', '_simd.h'),
join('src', '_simd', '_simd_inc.h.src'),
join('src', '_simd', '_simd_data.inc.src'),
join('src', '_simd', '_simd_arg.inc'),
join('src', '_simd', '_simd_convert.inc'),
join('src', '_simd', '_simd_easyintrin.inc'),
join('src', '_simd', '_simd_vector.inc'),
])

config.add_subpackage('tests')
config.add_data_dir('tests/data')
config.add_data_dir('tests/examples')
Expand Down
73 changes: 73 additions & 0 deletions numpy/core/src/_simd/_simd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "_simd.h"

PyMODINIT_FUNC PyInit__simd(void)
{
static struct PyModuleDef defs = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "numpy.core._simd",
.m_size = -1
};
if (npy_cpu_init() < 0) {
return NULL;
}
PyObject *m = PyModule_Create(&defs);
if (m == NULL) {
return NULL;
}
PyObject *targets = PyDict_New();
if (targets == NULL) {
goto err;
}
if (PyModule_AddObject(m, "targets", targets) < 0) {
Py_DECREF(targets);
goto err;
}
// add keys for non-supported optimizations with None value
#define ATTACH_MODULE(TESTED_FEATURES, TARGET_NAME, MAKE_MSVC_HAPPY) \
{ \
PyObject *simd_mod; \
if (!TESTED_FEATURES) { \
Py_INCREF(Py_None); \
simd_mod = Py_None; \
} else { \
simd_mod = NPY_CAT(simd_create_module_, TARGET_NAME)(); \
if (simd_mod == NULL) { \
goto err; \
} \
} \
const char *target_name = NPY_TOSTRING(TARGET_NAME); \
if (PyDict_SetItemString(targets, target_name, simd_mod) < 0) { \
Py_DECREF(simd_mod); \
goto err; \
} 8A66 \
Py_INCREF(simd_mod); \
if (PyModule_AddObject(m, target_name, simd_mod) < 0) { \
Py_DECREF(simd_mod); \
goto err; \
} \
}

#define ATTACH_BASELINE_MODULE(MAKE_MSVC_HAPPY) \
{ \
PyObject *simd_mod = simd_create_module(); \
if (simd_mod == NULL) { \
goto err; \
} \
if (PyDict_SetItemString(targets, "baseline", simd_mod) < 0) { \
Py_DECREF(simd_mod); \
goto err; \
} \
Py_INCREF(simd_mod); \
if (PyModule_AddObject(m, "baseline", simd_mod) < 0) { \
Py_DECREF(simd_mod); \
goto err; \
} \
}

NPY__CPU_DISPATCH_CALL(NPY_CPU_HAVE, ATTACH_MODULE, MAKE_MSVC_HAPPY)
NPY__CPU_DISPATCH_BASELINE_CALL(ATTACH_BASELINE_MODULE, MAKE_MSVC_HAPPY)
return m;
err:
Py_DECREF(m);
return NULL;
}
Loading
0