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

expose cuda stream to users #35813

Merged
merged 2 commits into from
Sep 17, 2021
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
22 changes: 22 additions & 0 deletions paddle/fluid/pybind/cuda_streams_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@ void BindCudaStream(py::module *m_ptr) {

)DOC",
py::arg("event") = nullptr)
.def_property_readonly(
"cuda_stream",
[](paddle::platform::stream::CUDAStream &self) {
VLOG(10) << self.raw_stream();
return reinterpret_cast<std::uintptr_t>(self.raw_stream());
},
R"DOC(
retrun the raw cuda stream of type cudaStream_t as type int.

Examples:
.. code-block:: python

# required: gpu
import paddle
import ctypes
cuda_stream = paddle.device.cuda.current_stream().cuda_stream
print(cuda_stream)

ptr = ctypes.c_void_p(cuda_stream) # convert back to void*
print(ptr)

)DOC")
#endif
.def("__init__",
[](paddle::platform::stream::CUDAStream &self,
Expand Down
10 changes: 10 additions & 0 deletions python/paddle/fluid/tests/unittests/test_cuda_stream_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from paddle.device import cuda
import paddle
import ctypes

import unittest
import numpy as np
Expand Down Expand Up @@ -156,5 +157,14 @@ def test_set_current_stream_raise_error(self):
None)


class TestRawStream(unittest.TestCase):
def test_cuda_stream(self):
if paddle.is_compiled_with_cuda():
cuda_stream = paddle.device.cuda.current_stream().cuda_stream
print(cuda_stream)
self.assertTrue(type(cuda_stream) is int)
ptr = ctypes.c_void_p(cuda_stream)


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