Uh oh!
There was an error while loading. Please reload this page.
Add MKLMemory class to expose MKL allocated memory via Python buffer protocol - #182
Add MKLMemory class to expose MKL allocated memory via Python buffer protocol#182ndgrigorian wants to merge 12 commits into
MKLMemory class to expose MKL allocated memory via Python buffer protocol#182Conversation
aed1ff6 to
a99e626Compareb2cc6fc to
00fea26Compareexposes Python buffer protocol
as atomics are a c11+ feature, specific flags are needed to enable on window
00fea26 to
c764a81CompareThere was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new MKLMemory Cython extension type backed by MKL’s allocator, exposes it from the top-level mkl package, and introduces tests/build changes to support C11 atomics and nogil MKL calls.
Changes:
- Introduce
mkl._mkl_memorywithMKLMemory(allocation, buffer protocol, pickling, realloc). - Add pytest coverage for allocation, buffer protocol, and pickling behavior.
- Update MKL C-API declarations/build to support
nogilcalls and C11 atomics (plus MSVC flag).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| mkl/tests/test_mkl_memory.py | Adds tests for MKLMemory creation, buffer protocol, and pickling behavior. |
| mkl/_py_mkl_service.pyx | Releases the GIL around MKL buffer-free calls. |
| mkl/_mkl_service.pxd | Marks MKL externs as nogil and adds malloc/calloc/realloc/free declarations. |
| mkl/_mkl_memory.pyx | Adds the new MKLMemory Cython extension implementing allocation + buffer protocol + pickling. |
| mkl/init.py | Exposes MKLMemory at the package top level. |
| meson.build | Enables C11, adds MSVC atomics flag, and builds the new _mkl_memory extension. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
also address issues with undeclared variables and rename MKLMemory class members
This PR proposes the introduction of
_mkl_memory.pyx, which implements anMKLMemoryclass that exposes memory allocated viamkl_mallocandmkl_callocto Python via the buffer protocolThe class uses an atomic counter incremented as
__getbuffer__and__releasebuffer__are called to track the views on the buffer to permit use ofmkl_reallocin the object (viareallocmethod). This concept was adapted from the PEP which revised the buffer protocol which proposed this kind of approach to tracking views on a bufferCloses#18