Skip to content

Commit e605ff2

Browse files
committed
[DLPack] Update to include DLPack C Exchange API
This PR updates to include dlpack C exchange api for fast exchange at c-extension level without going through python.
1 parent 6fd5129 commit e605ff2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

spec/draft/design_topics/data_interchange.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ page gives a high-level specification for data exchange in Python using DLPack.
8585
below. They are not required to return an array object from ``from_dlpack``
8686
which conforms to this standard.
8787

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

src/array_api_stubs/_draft/array_object.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818

1919
class _array:
20+
"""
21+
Attributes
22+
----------
23+
__dlpack_c_exchange_api__: PyCapsule
24+
An optional static array type attribute store in ``type(array_instance).__dlpack_c_exchange_api__``
25+
that can be used to retrieve the DLPack C-API exchange API struct in DLPack 1.3 or later to speed up
26+
exchange of array data at the C extension level without going through Python-level exchange.
27+
See :ref:`data-interchange` section for more details.
28+
"""
29+
# use None for placeholder
30+
__dlpack_c_exchange_api__: PyCapsule = None
31+
2032
def __init__(self: array) -> None:
2133
"""Initialize the attributes for the array object class."""
2234

0 commit comments

Comments
 (0)