18
18
19
19
namespace celeritas
20
20
{
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
+
21
47
// ---------------------------------------------------------------------------//
22
48
// PIMPL class
23
49
struct Stream ::Impl
@@ -34,9 +60,9 @@ void Stream::ImplDeleter::operator()(Impl* impl) noexcept
34
60
{
35
61
try
36
62
{
37
- CELER_DEVICE_API_CALL (StreamDestroy (impl->stream ));
38
63
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 ));
40
66
}
41
67
catch (RuntimeError const & e)
42
68
{
@@ -56,13 +82,7 @@ Stream::Stream()
56
82
{
57
83
StreamT stream;
58
84
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};
66
86
impl_.reset (new Impl);
67
87
impl_->stream = stream;
68
88
impl_->memory_resource = ResourceT{stream};
0 commit comments