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

mock torch_npu current_stram #39

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions ditorch/torch_npu_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2024, DeepLink.
import torch
import torch_npu # noqa: F401
from torch_npu.contrib import transfer_to_npu # noqa: F401


def current_stream(device=None):
old_device = torch.cuda.current_device()
if device is None:
device = old_device
torch.cuda.set_device(device)
stream = torch_npu.npu.current_stream(device)
torch.cuda.set_device(old_device)
return stream


torch.cuda.current_stream = current_stream
18 changes: 18 additions & 0 deletions op_tools/test/test_current_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ditorch
import torch
import unittest


class TestCurrentStream(unittest.TestCase):
def test_current_stream(self):
stream = torch.cuda.current_stream()
self.assertIsInstance(stream, torch.cuda.Stream)

def test_current_stream_device(self):
for device in range(torch.cuda.device_count()):
stream = torch.cuda.current_stream(device)
self.assertIsInstance(stream, torch.cuda.Stream)


if __name__ == "__main__":
unittest.main()