dmlc / dlpack

common in-memory tensor structure
https://dmlc.github.io/dlpack/latest
Apache License 2.0
911 stars 133 forks source link

Add view/copy informational flag #134

Closed seberg closed 9 months ago

seberg commented 10 months ago

There is a discussion in the array api about adding a nocopy request to the Python API. While it might be nice to solve such requests at a lower level in C, it isn't vital where the request happens.

However, there is a point that often the user doesn't care, but still would like to know if they got a copy (own the data effectively) or not (a view).

So if we go through the trouble of having a request flag, I think we must also add this informational flag in the struct (probably 1 being set meaning that a copy is returned for whatever reason: the consumer is the sole user of the data).

Yes, this isn't what DLPack had in mind when designed, but it seems like it is a natural extension of an exchange protocol.

(The request API still is useful with this, since it allows the consumer to say that they require a view, allowing to fail early.)

seberg commented 10 months ago

Just to note: I don't want to discuss the merits of pushing these types of request into a lower level and not doing them in Python. I always thought that would be preferable, but we are doing things in Python right now and for better or worse, I think we might as well continue to do so until someone cares enough to extend the C exchange part.