Skip to content
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
7 changes: 7 additions & 0 deletions python/paddle/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,13 @@ def _as_parameter_(self):
else:
return ctypes.c_void_p(self.stream_base.raw_stream)

@property
def cuda_stream(self) -> int:
assert isinstance(self.stream_base, core.CUDAStream), (
"cuda_stream is only available for CUDA streams"
)
return self.stream_base.cuda_stream

def __cuda_stream__(self):
"""
CUDA Stream protocol described at
Expand Down
11 changes: 11 additions & 0 deletions test/legacy_test/test_cuda_stream_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def test_cuda_stream(self):
self.assertTrue(type(cuda_stream) is int)
ptr = ctypes.c_void_p(cuda_stream)

def test_paddle_cuda_current_stream_cuda_stream(self):
if paddle.is_compiled_with_cuda() and paddle.cuda.is_available():
stream = paddle.cuda.current_stream()
cuda_stream = stream.cuda_stream
ptr = ctypes.c_void_p(cuda_stream)

self.assertTrue(type(cuda_stream) is int)
self.assertTrue(cuda_stream >= 0 or ptr.value is not None)
self.assertEqual(cuda_stream, stream.stream_base.cuda_stream)
self.assertEqual(cuda_stream, stream.stream_base.raw_stream)


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