Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG, ENH: np._from_dlpack: export correct device information #21138

Merged
merged 1 commit into from Mar 3, 2022

Conversation

charris
Copy link
Member

@charris charris commented Mar 2, 2022

Backport of #21119.

fixes gh-20340

It is possible to export incorrect device information if a new view has been created from an imported array:

import numpy as np
from torch

x = torch.arange(10).pin_memory()
y = np._from_dlpack(x)
y.base  # PyCapsule named 'numpy_dltensor' (contains device information)
z = y[::2]
z.base  # y (doesn't contain original device information)
z.__dlpack_device__()  # (1, 0) --> wrong (should be (3, 0) for pinned memory)

This PR fixes this behavior by walking the bases (if they are ndarray) as suggested in #20340 (comment). The test just coves the new changes but doesn't really test against an array from a different device.

cc @seberg @mattip

@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Mar 2, 2022
@charris charris added this to the 1.22.3 release milestone Mar 2, 2022
@charris charris merged commit 3b31cdc into numpy:maintenance/1.22.x Mar 3, 2022
@charris charris deleted the backport-21119 branch March 3, 2022 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants