Skip to content

Commit

Permalink
mock torch_npu current_stram (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoguochun1995 authored Sep 19, 2024
1 parent 838483c commit 245e25e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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()

0 comments on commit 245e25e

Please sign in to comment.