xref: /aosp_15_r20/external/pytorch/c10/core/Stream.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <c10/core/Stream.h>
2 #include <c10/core/impl/VirtualGuardImpl.h>
3 
4 namespace c10 {
5 
6 // Return whether all asynchronous work previously enqueued on this stream
7 // has completed running on the device.
query() const8 bool Stream::query() const {
9   impl::VirtualGuardImpl impl{device_.type()};
10   return impl.queryStream(*this);
11 }
12 
13 // Wait (by blocking the calling thread) until all asynchronous work enqueued
14 // on this stream has completed running on the device.
synchronize() const15 void Stream::synchronize() const {
16   impl::VirtualGuardImpl impl{device_.type()};
17   impl.synchronizeStream(*this);
18 }
19 
20 // Not very parsable, but I don't know a good compact syntax for streams.
21 // Feel free to change this into something more compact if needed.
operator <<(std::ostream & stream,const Stream & s)22 std::ostream& operator<<(std::ostream& stream, const Stream& s) {
23   stream << "stream " << s.id() << " on device " << s.device();
24   return stream;
25 }
26 
27 } // namespace c10
28