Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions spec/draft/design_topics/data_interchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ page gives a high-level specification for data exchange in Python using DLPack.
below. They are not required to return an array object from ``from_dlpack``
which conforms to this standard.


DLPack C Exchange API
---------------------

DLPack 1.3 introduces a C-level exchange API that can be used to speed up
data exchange between arrays at the C-extension level. This API is available via
the ``type(array_instance).__dlpack_c_exchange_api__`` attribute on the array type object.
For more details, see the `Python specification of DLPack <https://dmlc.github.io/dlpack/latest/python_spec.html>`__
We recommend consumer libraries to start first using the python level ``__dlpack__`` first which will covers
most cases, then start to use the C-level ``__dlpack_c_exchange_api__`` for performance critical cases.


Non-supported use cases
-----------------------

Expand Down
12 changes: 12 additions & 0 deletions src/array_api_stubs/_draft/array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@


class _array:
"""
Attributes
----------
__dlpack_c_exchange_api__: PyCapsule
An optional static array type attribute store in ``type(array_instance).__dlpack_c_exchange_api__``
that can be used to retrieve the DLPack C-API exchange API struct in DLPack 1.3 or later to speed up
exchange of array data at the C extension level without going through Python-level exchange.
See :ref:`data-interchange` section for more details.
"""
# use None for placeholder
__dlpack_c_exchange_api__: PyCapsule = None

def __init__(self: array) -> None:
"""Initialize the attributes for the array object class."""

Expand Down