diff options
| author | Sebastian Berg <sebastian@sipsolutions.net> | 2022-05-14 11:25:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-14 11:25:20 +0200 |
| commit | c93faa47504c8dc1cc59d60212a537395f946a7c (patch) | |
| tree | 952ef86a9c481e4e76af5117ceb006346aa91767 /numpy | |
| parent | 20150294b80222601ddac21b7b739394039293c4 (diff) | |
| parent | 8a519d4227f9ffbb86ad6bce58b580ec3c97d146 (diff) | |
| download | numpy-c93faa47504c8dc1cc59d60212a537395f946a7c.tar.gz | |
Merge pull request #21498 from jakirkham/add_get_madv_hp
ENH: Add `_get_madvise_hugepage` function
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/_add_newdocs.py | 9 | ||||
| -rw-r--r-- | numpy/core/multiarray.py | 2 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/alloc.c | 19 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/alloc.h | 3 | ||||
| -rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 2 |
5 files changed, 34 insertions, 1 deletions
diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py index baafc9127..304c3a61b 100644 --- a/numpy/core/_add_newdocs.py +++ b/numpy/core/_add_newdocs.py @@ -4865,6 +4865,15 @@ add_newdoc('numpy.core.multiarray', 'get_handler_version', its memory, in which case you can traverse ``a.base`` for a memory handler. """) +add_newdoc('numpy.core.multiarray', '_get_madvise_hugepage', + """ + _get_madvise_hugepage() -> bool + + Get use of ``madvise (2)`` MADV_HUGEPAGE support when + allocating the array data. Returns the currently set value. + See `global_state` for more information. + """) + add_newdoc('numpy.core.multiarray', '_set_madvise_hugepage', """ _set_madvise_hugepage(enabled: bool) -> bool diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py index 1a37ed3e1..ee88ce30b 100644 --- a/numpy/core/multiarray.py +++ b/numpy/core/multiarray.py @@ -16,7 +16,7 @@ from ._multiarray_umath import * # noqa: F403 from ._multiarray_umath import ( _fastCopyAndTranspose, _flagdict, from_dlpack, _insert, _reconstruct, _vec_string, _ARRAY_API, _monotonicity, _get_ndarray_c_version, - _set_madvise_hugepage, + _get_madvise_hugepage, _set_madvise_hugepage, ) __all__ = [ diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c index 759a02aeb..6f18054ff 100644 --- a/numpy/core/src/multiarray/alloc.c +++ b/numpy/core/src/multiarray/alloc.c @@ -39,6 +39,25 @@ static int _madvise_hugepage = 1; /* + * This function tells whether NumPy attempts to call `madvise` with + * `MADV_HUGEPAGE`. `madvise` is only ever used on linux, so the value + * of `_madvise_hugepage` may be ignored. + * + * It is exposed to Python as `np.core.multiarray._get_madvise_hugepage`. + */ +NPY_NO_EXPORT PyObject * +_get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args)) +{ +#ifdef NPY_OS_LINUX + if (_madvise_hugepage) { + Py_RETURN_TRUE; + } +#endif + Py_RETURN_FALSE; +} + + +/* * This function enables or disables the use of `MADV_HUGEPAGE` on Linux * by modifying the global static `_madvise_hugepage`. * It returns the previous value of `_madvise_hugepage`. diff --git a/numpy/core/src/multiarray/alloc.h b/numpy/core/src/multiarray/alloc.h index 13c828458..e82f2d947 100644 --- a/numpy/core/src/multiarray/alloc.h +++ b/numpy/core/src/multiarray/alloc.h @@ -8,6 +8,9 @@ #define NPY_TRACE_DOMAIN 389047 NPY_NO_EXPORT PyObject * +_get_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args)); + +NPY_NO_EXPORT PyObject * _set_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *enabled_obj); NPY_NO_EXPORT void * diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 5e51bcaa6..ce47276db 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -4488,6 +4488,8 @@ static struct PyMethodDef array_module_methods[] = { METH_VARARGS, NULL}, {"_get_sfloat_dtype", get_sfloat_dtype, METH_NOARGS, NULL}, + {"_get_madvise_hugepage", (PyCFunction)_get_madvise_hugepage, + METH_NOARGS, NULL}, {"_set_madvise_hugepage", (PyCFunction)_set_madvise_hugepage, METH_O, NULL}, {"_reload_guard", (PyCFunction)_reload_guard, |
