ATLAS Offline Software
Loading...
Searching...
No Matches
AthCUDA::Details::Stream Class Reference

Helper class for managing a CUDA stream in memory. More...

#include <Stream.h>

Collaboration diagram for AthCUDA::Details::Stream:

Public Member Functions

 Stream ()
 Constructor, creating the CUDA stream.
 ~Stream ()
 Destructor, destroying the CUDA stream.
cudaStream_t stream () const
 Get the CUDA stream.
std::string name () const
 Get the name of the device associated with the stream.

Private Attributes

cudaStream_t m_stream {nullptr}
 The CUDA stream to use for asynchronous copies.

Detailed Description

Helper class for managing a CUDA stream in memory.

Definition at line 16 of file Stream.h.

Constructor & Destructor Documentation

◆ Stream()

AthCUDA::Details::Stream::Stream ( )

Constructor, creating the CUDA stream.

Definition at line 28 of file Stream.cxx.

28 {
29 CUDA_ERROR_CHECK(cudaStreamCreate(&m_stream));
30}
#define CUDA_ERROR_CHECK(EXP)
Helper macro used for checking cudaError_t type return values.
Definition Stream.cxx:16
cudaStream_t m_stream
The CUDA stream to use for asynchronous copies.
Definition Stream.h:32

◆ ~Stream()

AthCUDA::Details::Stream::~Stream ( )

Destructor, destroying the CUDA stream.

Let's not check for errors here.

Since that would introduce a struct that may throw in its destructor. Which we don't want.

Definition at line 34 of file Stream.cxx.

34 {
35 cudaStreamDestroy(m_stream);
36}

Member Function Documentation

◆ name()

std::string AthCUDA::Details::Stream::name ( ) const

Get the name of the device associated with the stream.

Definition at line 48 of file Stream.cxx.

48 {
49
50 // Get the device's properties.
51 int device = -1;
52 CUDA_ERROR_CHECK(cudaStreamGetDevice(stream(), &device));
53 cudaDeviceProp props;
54 CUDA_ERROR_CHECK(cudaGetDeviceProperties(&props, device));
55
56 // Construct a unique name out of those properties.
57 return std::format("{} [id: {}, bus: {}, device: {}]", props.name, device,
58 props.pciBusID, props.pciDeviceID);
59}
cudaStream_t stream() const
Get the CUDA stream.
Definition Stream.cxx:38

◆ stream()

cudaStream_t AthCUDA::Details::Stream::stream ( ) const

Get the CUDA stream.

Definition at line 38 of file Stream.cxx.

38 {
39
40 // The CUDA runtime promises thread safety for handling streams in parallel
41 // from different CPU threads. Returning a non-const pointer of course allows
42 // us to cause harm. But as long as user code is not trying to actively break
43 // things, we should be fine.
44 cudaStream_t result ATLAS_THREAD_SAFE = m_stream;
45 return result;
46}
#define ATLAS_THREAD_SAFE

Member Data Documentation

◆ m_stream

cudaStream_t AthCUDA::Details::Stream::m_stream {nullptr}
private

The CUDA stream to use for asynchronous copies.

Definition at line 32 of file Stream.h.

32{nullptr};

The documentation for this class was generated from the following files: