Skip to content

Investigate eliminating _CXX_API capsule for resource handle functions #1452

@Andy-Jost

Description

@Andy-Jost

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 cdef functions (non-inline) in _resource_handles.pyx, can other modules cimport and call them directly?
  • Would this approach correctly share static state through _resource_handles.so?
  • Are there performance implications for nogil code 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

Goal

Simplify the architecture by removing the capsule indirection if it's not required, reducing complexity while preserving correct behavior.

Metadata

Metadata

Assignees

Labels

cuda.coreEverything related to the cuda.core moduleenhancementAny code-related improvements

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions