Skip to content

Commit c5e3b46

Browse files
committed
Make stream printing symmetric
1 parent c7fb22b commit c5e3b46

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/corecel/sys/Stream.cu

+29-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@
1818

1919
namespace celeritas
2020
{
21+
namespace
22+
{
23+
//---------------------------------------------------------------------------//
24+
//! Safely print a stream's ID (if possible) or
25+
struct StreamableStream
26+
{
27+
detail::DeviceStream_t s;
28+
};
29+
30+
#if !CELER_DEVICE_COMPILE
31+
std::ostream& operator<<(std::ostream& os, StreamableStream const& sds)
32+
{
33+
# if CUDART_VERSION >= 12000
34+
unsigned long long stream_id = -1;
35+
CELER_DEVICE_API_CALL(StreamGetId(sds.s, &stream_id));
36+
os << "id=" << stream_id;
37+
# else
38+
os << '@' << static_cast<void*>(sds.s);
39+
# endif
40+
return os;
41+
}
42+
#endif
43+
44+
//---------------------------------------------------------------------------//
45+
} // namespace
46+
2147
//---------------------------------------------------------------------------//
2248
// PIMPL class
2349
struct Stream::Impl
@@ -34,9 +60,9 @@ void Stream::ImplDeleter::operator()(Impl* impl) noexcept
3460
{
3561
try
3662
{
37-
CELER_DEVICE_API_CALL(StreamDestroy(impl->stream));
3863
CELER_LOG_LOCAL(debug)
39-
<< "Destroyed stream " << static_cast<void*>(impl->stream);
64+
<< "Destroying stream " << StreamableStream{impl->stream};
65+
CELER_DEVICE_API_CALL(StreamDestroy(impl->stream));
4066
}
4167
catch (RuntimeError const& e)
4268
{
@@ -56,13 +82,7 @@ Stream::Stream()
5682
{
5783
StreamT stream;
5884
CELER_DEVICE_API_CALL(StreamCreate(&stream));
59-
#if CUDART_VERSION >= 12000
60-
unsigned long long stream_id = -1;
61-
CELER_DEVICE_API_CALL(StreamGetId(stream, &stream_id));
62-
CELER_LOG_LOCAL(debug) << "Created stream ID " << stream_id;
63-
#else
64-
CELER_LOG_LOCAL(debug) << "Created stream " << static_cast<void*>(stream);
65-
#endif
85+
CELER_LOG_LOCAL(debug) << "Created stream " << StreamableStream{stream};
6686
impl_.reset(new Impl);
6787
impl_->stream = stream;
6888
impl_->memory_resource = ResourceT{stream};

0 commit comments

Comments
 (0)