ATLAS Offline Software
Loading...
Searching...
No Matches
AthHIP/AthHIPComps/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).
10
11// System include(s).
12#include <format>
13#include <stdexcept>
14
16#define HIP_ERROR_CHECK(EXP) \
17 do { \
18 hipError_t errorCode = EXP; \
19 if (errorCode != hipSuccess) { \
20 throw std::runtime_error(std::format("{}:{} Failed to execute: {} ({})", \
21 __FILE__, __LINE__, #EXP, \
22 hipGetErrorString(errorCode))); \
23 } \
24 } while (false)
25
26namespace AthHIP::Details {
27
29 HIP_ERROR_CHECK(hipStreamCreate(&m_stream));
30}
31
35 [[maybe_unused]] hipError_t error = hipStreamDestroy(m_stream);
36}
37
38hipStream_t Stream::stream() const {
39
40 // The HIP 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 hipStream_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 HIP_ERROR_CHECK(hipStreamGetDevice(stream(), &device));
53 hipDeviceProp_t props;
54 HIP_ERROR_CHECK(hipGetDeviceProperties(&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 AthHIP::Details
#define HIP_ERROR_CHECK(EXP)
Helper macro used for checking hipError_t type return values.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
hipStream_t m_stream
The HIP stream to use for asynchronous copies.
std::string name() const
Get the name of the device associated with the stream.
hipStream_t stream() const
Get the HIP stream.
~Stream()
Destructor, destroying the HIP stream.
Stream()
Constructor, creating the HIP stream.