Skip to content

Revert cupy.cuda.Device behavior to v9 - #7427

Merged
emcastillo merged 1 commit into
cupy:masterfrom
kmaehashi:fix-device-behavior
Feb 28, 2023
Merged

emcastillo merged 1 commit into
cupy:masterfrom
kmaehashi:fix-device-behavior

Conversation

@kmaehashi

@kmaehashi kmaehashi commented Feb 27, 2023 •

Copy link
Copy Markdown
Member

This reverts #5853 as discussed in #6965.

Closes #6965 and #7315.

I've tested interoperability with PyTorch and looks working as expected:

# Note: requires 3 GPUs

import cupy
import torch


dev1 = cupy.cuda.Device(1)

with dev1:
    t1 = torch.arange(10, device='cuda')
    assert 'cuda:1' == str(t1.device)
    assert ((t1 - torch.from_dlpack(cupy.arange(10))).sum() == 0).item() is True
    with torch.cuda.device(2):
        t2 = torch.arange(10).cuda()
        assert 'cuda:2' == str(t2.device)
        assert cupy.cuda.Device().id == 2
        with dev1:
            assert 1 == torch.cuda.current_device()
    assert cupy.cuda.Device().id == 1
assert 0 == torch.cuda.current_device()

cc/ @leofang

@kmaehashi

Copy link
Copy Markdown
Member Author

/test mini

@kmaehashi kmaehashi added no-compat Disrupts backward compatibility blocking Issue/pull-request is mandatory for the upcoming release prio:high cat:enhancement Improvements to existing features labels Feb 27, 2023
@emcastillo emcastillo self-assigned this Feb 28, 2023

@emcastillo emcastillo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@emcastillo
emcastillo merged commit 882ddf6 into cupy:master Feb 28, 2023
@kmaehashi
kmaehashi deleted the fix-device-behavior branch February 28, 2023 01:21
@emcastillo emcastillo added this to the v12.0.0rc1 milestone Feb 28, 2023
@leofang

leofang commented Mar 1, 2023

Copy link
Copy Markdown
Member

Thanks for doing me the favor, @kmaehashi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocking Issue/pull-request is mandatory for the upcoming release cat:enhancement Improvements to existing features no-compat Disrupts backward compatibility prio:high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discussion: Restore (or document how to restore) the old Device context manager behavior (pre-v10)?

3 participants