-
Notifications
You must be signed in to change notification settings - Fork 236
Description
Summary
PR #1368 uses a PyCapsule mechanism (_CXX_API) to share resource handle functions across Cython modules. This issue is to investigate whether this capsule can be eliminated entirely.
Current Architecture
The _CXX_API capsule exports function pointers from _resource_handles.so to other Cython modules (_buffer.pyx, _stream.pyx, _event.pyx, etc.). The stated rationale is to avoid duplicate static/thread-local state if multiple modules linked the C++ code directly.
Proposed Investigation
Investigate whether Cython modules can call directly into the resource handles code without the capsule indirection:
- If resource handle functions are regular
cdeffunctions (non-inline) in_resource_handles.pyx, can other modulescimportand call them directly? - Would this approach correctly share static state through
_resource_handles.so? - Are there performance implications for
nogilcode paths?
Background
When module A cimports a cdef function from module B, the call goes through B.so at runtime via Python's import mechanism. This should mean static state in B stays in one place, potentially making the capsule unnecessary for pure Cython-to-Cython usage.
References
- PR RAII resource handles for CUDA objects #1368 - RAII resource handles implementation
- Issue Investigate using __pyx_capi__ to simplify resource handle architecture #1450 - Related investigation for cuda.bindings driver API capsule
Goal
Simplify the architecture by removing the capsule indirection if it's not required, reducing complexity while preserving correct behavior.