Skip to content

Commit bd7467b

Browse files
first draft
1 parent 023c4bf commit bd7467b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

cuda_bindings/docs/source/tips_and_tricks.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ Getting the address of underlying C objects from the low-level bindings
77
All CUDA C types are exposed to Python as Python classes. For example, the :class:`~cuda.bindings.driver.CUstream` type is exposed as a class with methods :meth:`~cuda.bindings.driver.CUstream.getPtr()` and :meth:`~cuda.bindings.driver.CUstream.__int__()` implemented.
88

99
There is an important distinction between the ``getPtr()`` method and the behaviour of ``__int__()``. If you need to get the pointer address *of* the underlying ``CUstream`` C object wrapped in the Python class, you can do so by calling ``int(instance_of_CUstream)``, which returns the address as a Python `int`, while calling ``instance_of_CUstream.getPtr()`` returns the pointer *to* the ``CUstream`` C object (that is, ``&CUstream``) as a Python `int`.
10+
11+
12+
Getting and setting attributes of extension types
13+
=================================================
14+
15+
While the bindings outwardly presents the attributes of extension types in a Pythonic way, they can't always be interacted
16+
with in a Pythonic style. Often the getters/setters (__getitem__(), __setitem__()) are actually a translation step to convert values between
17+
Python and C. For example, in some cases, attempting to modify an attribute in place, will lead to unexpected behavior due to the constraints
18+
of the underlying implementation. For this reason, users should use the getters and setters directly when interacting with extension types.

0 commit comments

Comments
 (0)