Skip to content

Commit

Permalink
Fixup: Implement suggestions by Matti
Browse files Browse the repository at this point in the history
  • Loading branch information
seberg committed Apr 29, 2020
1 parent 1400cea commit 3395802
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ def _mac_os_check():
use_hugepage = int(use_hugepage)

# Note that this will currently only make a difference on Linux
core.multiarray._multiarray_umath._set_madvise_hugepage(use_hugepage)
core.multiarray._set_madvise_hugepage(use_hugepage)
8 changes: 8 additions & 0 deletions numpy/core/_add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4391,6 +4391,14 @@
and then throwing away the ufunc.
""")

add_newdoc('numpy.core.multiarray', '_set_madvise_hugepage',
"""
_set_madvise_hugepage(enabled: bool) -> bool
Set or unset use of ``madvise (2)`` MADV_HUGEPAGE support when
allocating the array data. Returns the previously set value.
See `global_state` for more information.
""")

add_newdoc('numpy.core._multiarray_tests', 'format_float_OSprintf_g',
"""
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# _get_ndarray_c_version is semi-public, on purpose not added to __all__
from ._multiarray_umath import (
_fastCopyAndTranspose, _flagdict, _insert, _reconstruct, _vec_string,
_ARRAY_API, _monotonicity, _get_ndarray_c_version
_ARRAY_API, _monotonicity, _get_ndarray_c_version, _set_madvise_hugepage,
)

__all__ = [
Expand Down
7 changes: 7 additions & 0 deletions numpy/core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ static cache_bucket dimcache[NBUCKETS_DIM];
static int _madvise_hugepage = 1;


/*
* 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`.
*
* It is exposed to Python as `np.core.multiarray._set_madvise_hugepage`.
*/
NPY_NO_EXPORT PyObject *
_set_madvise_hugepage(PyObject *NPY_UNUSED(self), PyObject *enabled_obj)
{
Expand Down
3 changes: 1 addition & 2 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3972,7 +3972,6 @@ normalize_axis_index(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
return PyInt_FromLong(axis);
}


static struct PyMethodDef array_module_methods[] = {
{"_get_implementing_args",
(PyCFunction)array__get_implementing_args,
Expand Down Expand Up @@ -4162,7 +4161,7 @@ static struct PyMethodDef array_module_methods[] = {
{"_add_newdoc_ufunc", (PyCFunction)add_newdoc_ufunc,
METH_VARARGS, NULL},
{"_set_madvise_hugepage", (PyCFunction)_set_madvise_hugepage,
METH_O, "Toggle and return madvise hugepage (no OS support check)."},
METH_O, NULL},
{NULL, NULL, 0, NULL} /* sentinel */
};

Expand Down

0 comments on commit 3395802

Please sign in to comment.