ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthCUDA
AthCUDAServices
src
AthCUDA/AthCUDAServices/src/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).
9
#include "
CxxUtils/checker_macros.h
"
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
26
namespace
AthCUDA::Details
{
27
28
Stream::Stream
() {
29
CUDA_ERROR_CHECK
(cudaStreamCreate(&
m_stream
));
30
}
31
34
Stream::~Stream
() {
35
cudaStreamDestroy(
m_stream
);
36
}
37
38
cudaStream_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
48
std::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
CUDA_ERROR_CHECK
#define CUDA_ERROR_CHECK(EXP)
Helper macro used for checking cudaError_t type return values.
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:16
Stream.h
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
AthCUDA::Details::Stream::m_stream
cudaStream_t m_stream
The CUDA stream to use for asynchronous copies.
Definition
AthCUDA/AthCUDAServices/src/Stream.h:32
AthCUDA::Details::Stream::Stream
Stream()
Constructor, creating the CUDA stream.
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:28
AthCUDA::Details::Stream::name
std::string name() const
Get the name of the device associated with the stream.
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:48
AthCUDA::Details::Stream::stream
cudaStream_t stream() const
Get the CUDA stream.
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:38
AthCUDA::Details::Stream::~Stream
~Stream()
Destructor, destroying the CUDA stream.
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:34
AthCUDA::Details
Definition
AthCUDA/AthCUDAServices/src/Stream.cxx:26
Generated on
for ATLAS Offline Software by
1.17.0