Skip to content

RFC: Change __cuda_stream__ from class attribute to method #348

Closed
@leofang

Description

@leofang

One of the reasons that people complain about CUDA Array Interface (CAI) being slow is because it has side effects. Consider this example:

>>> class KKK:
...     @property
...     def __proppp__(self):
...             print("I am called")
... 
>>> 
>>> type(KKK.__proppp__)
<class 'property'>
>>> k = KKK()
>>> hasattr(k, "__proppp__")
I am called
True

One can see that the hasattr call on any class attribute/property would actually execute the attribute implementation, but not if it is a method:

>>> class KKK:
...     def __proppp__(self):
...             print("I am called")
... 
>>> 
>>> type(KKK.__proppp__)
<class 'function'>
>>> k = KKK()
>>> hasattr(k, "__proppp__")
True

I realized I had forgotten about this during the design stage until now. This fact has also been pointed out by @gmarkall (back in the days of designing CAI, IIRC).

I propose to change __cuda_stream__ and any future protocols to a callable class method from a class property/attribute so as to avoid side effects (thereby reducing overhead) and establish a future-proof convention, following DLPack and other protocols.

Metadata

Metadata

Assignees

Labels

P0High priority - Must do!RFCPlans and announcementsbreakingBreaking changes are introducedcuda.coreEverything related to the cuda.core module

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions