Zero-copy DLPack interop

I’d like to support zero-copy data exchange for device buffers originally allocated in code written in C++ and Python and passed to Mojo. It looks like the best way to do this is by Mojo supporting the DLPack interop standard ( Python Specification for DLPack — DLPack 0.6.0 documentation ).

However, it’s unclear under what circumstances external device allocations are properly supported by the Mojo runtime. I couldn’t find any documentation on this, but please point me to it if I missed it.

Is zero-copy read/write access to device allocations passed from external code something that can be supported in general in Mojo?

It looks like a PyCapsule can be used. In marrow we are exchanging memory between Mojo and Pyarrow using a similar mechanism here: marrow/marrow/c_data.mojo at 0b85eb2f001dbe5f27dff177678c0c3295f3014a · kszucs/marrow · GitHub

1 Like