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

Fix _util.device_from_ctx #203

Merged
merged 9 commits into from
Nov 12, 2024
5 changes: 3 additions & 2 deletions cuda_core/cuda/core/experimental/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def inner(*args, **kwargs):

def get_device_from_ctx(ctx_handle) -> int:
"""Get device ID from the given ctx."""
prev_ctx = Device().context.handle
if ctx_handle != prev_ctx:
from cuda.core.experimental._device import Device # avoid circular import
prev_ctx = Device().context._handle
if int(ctx_handle) != int(prev_ctx):
switch_context = True
else:
switch_context = False
Expand Down
10 changes: 10 additions & 0 deletions cuda_core/tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def test_stream_context():
context = stream.context
assert context is not None

def test_stream_from_foreign_stream():
device = Device()
other_stream = device.create_stream(options=StreamOptions())
stream = device.create_stream(obj=other_stream)
assert other_stream.handle == stream.handle
device = stream.device
assert isinstance(device, Device)
context = stream.context
assert context is not None

def test_stream_from_handle():
stream = Stream.from_handle(0)
assert isinstance(stream, Stream)
Expand Down