-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
ENH: allow using aligned memory allocation, or exposing an API for memory management #17467
Description
Submitting this here since it is easier to link to all the issues and PRs dealing with memory management. Will submit it to the mailing list after a first-discussion here if needed.
There are three allocation to instantiate a PyArrayObject: the python allocation of the PyObject, the use of PyArray_malloc/PyArray_realloc/PyArray_free to allocate array dims and strides, and the PyDataMem_NEW/PyDataMem_NEWZEROED/PyDataMem_FREE calls for the array data.
I would like to make the case for an API for overloading internal use of PyDataMem_NEW, PyDataMem_NEWZEROED and PyDataMem_FREE. Work on this was begun in gh-5470, and referred to in issues gh-5312 (asking for an aligned allocator). In addition there is PR gh-5457, to provide a global interface for specifying aligned allocations.
As mentioned in the issue, alignment can be crucial for some applications, but in general is just extra overhead, so it should be configurable by the user/app.
I think I would prefer providing an API hook as in gh-5470. That PR actually had two parts: a configurable PyDataMem* overrides and a hook mechanism. The hook mechanism was merged (does anyone use that?) but the part I am interested in would requre an API change.
A fallback proposal would be to allow specifying a default allocation alignment aka gh-5457, perhaps using PyArray_malloc_aligned and friends as part of NumPy with the random API refactor.