Skip to content

xp.from_dlpack to move data to a preallocated array on the target device  #750

Closed
@ogrisel

Description

@ogrisel

Since #741 was merged, it should now be possible to perform data transfers across devices and namespaces in a standard, namespace agnostic way (as long as both namespace have a shared understanding of a common device type, such as the CPU/host).

However, such transfers cannot reuse pre-allocated buffers in the target namespace/device.

Would it be possible to add an out argument to from_dlpack?

def move(x, y):
    xp_x = x.__array_namespace__()
    xp_y = y.__array_namespace__()
    if not xp_x == xp_y:
        xp_x.from_dlpack(y, copy=True, out=x)  # device=x.device is implicit in this case.
    else:
        x[:] = y

This API might be a bit too weird. I am open a to better suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions