ATLAS Offline Software
Loading...
Searching...
No Matches
Stream.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
6#include "Stream.h"
7
8// Framework include(s).
10
11// System include(s).
12#include <format>
13#include <stdexcept>
14
16#define CUDA_ERROR_CHECK(EXP) \
17 do { \
18 cudaError_t errorCode = EXP; \
19 if (errorCode != cudaSuccess) { \
20 throw std::runtime_error(std::format("{}:{} Failed to execute: {} ({})", \
21 __FILE__, __LINE__, #EXP, \
22 cudaGetErrorString(errorCode))); \
23 } \
24 } while (false)
25
27
29 CUDA_ERROR_CHECK(cudaStreamCreate(&m_stream));
30}
31
35 cudaStreamDestroy(m_stream);
36}
37
38cudaStream_t Stream::stream() const {
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}
47
48std::string Stream::name() const {
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}
60
61} // namespace AthCUDA::Details
#define CUDA_ERROR_CHECK(EXP)
Helper macro used for checking cudaError_t type return values.
Definition Stream.cxx:16
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
cudaStream_t m_stream
The CUDA stream to use for asynchronous copies.
Definition Stream.h:32
Stream()
Constructor, creating the CUDA stream.
Definition Stream.cxx:28
std::string name() const
Get the name of the device associated with the stream.
Definition Stream.cxx:48
cudaStream_t stream() const
Get the CUDA stream.
Definition Stream.cxx:38
~Stream()
Destructor, destroying the CUDA stream.
Definition Stream.cxx:34