Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions torch/cuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def __init__(self, idx):
def __enter__(self):
if self.idx is -1:
return
_lazy_init()
self.prev_idx = torch._C._cuda_getDevice()
if self.prev_idx != self.idx:
torch._C._cuda_setDevice(self.idx)
_lazy_init()

This comment was marked as off-topic.

This comment was marked as off-topic.


def __exit__(self, *args):
if self.prev_idx != self.idx:
Expand Down Expand Up @@ -291,7 +291,6 @@ def stream(stream):
def device_count():
"""Returns the number of GPUs available."""
if is_available():
_lazy_init()

This comment was marked as off-topic.

This comment was marked as off-topic.

return torch._C._cuda_getDeviceCount()
else:
return 0
Expand Down