Skip to content

Add MKLMemory class to expose MKL allocated memory via Python buffer protocol - #182

Open
ndgrigorian wants to merge 12 commits into
masterfrom
feature/add-mkl-memory
Open

Add MKLMemory class to expose MKL allocated memory via Python buffer protocol#182
ndgrigorian wants to merge 12 commits into
masterfrom
feature/add-mkl-memory

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

This PR proposes the introduction of _mkl_memory.pyx, which implements an MKLMemory class that exposes memory allocated via mkl_malloc and mkl_calloc to Python via the buffer protocol

The class uses an atomic counter incremented as __getbuffer__ and __releasebuffer__ are called to track the views on the buffer to permit use of mkl_realloc in the object (via realloc method). This concept was adapted from the PEP which revised the buffer protocol which proposed this kind of approach to tracking views on a buffer

Closes #18

@ndgrigorian
ndgrigorian force-pushed the feature/add-mkl-memory branch 5 times, most recently from aed1ff6 to a99e626 Compare April 12, 2026 07:19
@ndgrigorian
ndgrigorian marked this pull request as ready for review April 12, 2026 09:03
@ndgrigorian
ndgrigorian force-pushed the feature/add-mkl-memory branch 3 times, most recently from b2cc6fc to 00fea26 Compare May 10, 2026 02:02
Base automatically changed from use-meson-build to master July 21, 2026 14:49
Copilot AI lite review requested due to automatic review settings August 6, 2026 15:58
@ndgrigorian
ndgrigorian force-pushed the feature/add-mkl-memory branch from 00fea26 to c764a81 Compare August 6, 2026 15:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_memory with MKLMemory (allocation, buffer protocol, pickling, realloc).
  • Add pytest coverage for allocation, buffer protocol, and pickling behavior.
  • Update MKL C-API declarations/build to support nogil calls 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.

Comment thread mkl/_mkl_memory.pyx Outdated
Comment thread mkl/_mkl_memory.pyx Outdated
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx Outdated
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx
Comment thread mkl/_mkl_memory.pyx Outdated
also address issues with undeclared variables and rename MKLMemory class members
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants