ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthHIP
AthHIPComps
src
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.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 "
DeviceMemoryResourceTool.h
"
7
8
// HIP include(s).
9
#include <hip/hip_runtime_api.h>
10
11
// System include(s).
12
#include <cassert>
13
14
namespace
AthHIP
{
15
16
StatusCode
DeviceMemoryResourceTool::initialize
() {
17
18
// Construct the appropriate memory resource.
19
m_mr
= std::make_unique<vecmem::hip::device_memory_resource>(
m_deviceID
);
20
21
// Figure out which device the memory resource was created for. Unfortunately
22
// vecmem doesn't advertise this in a convenient way at the moment. :( So we
23
// have to re-create its logic here.
24
int
deviceID =
m_deviceID
;
25
if
(deviceID == vecmem::hip::device_memory_resource::INVALID_DEVICE) {
26
// The default device was requested. We have to query for the current
27
// device.
28
hipError_t err = hipGetDevice(&deviceID);
29
if
(err != hipSuccess) {
30
ATH_MSG_ERROR
(
31
"Failed to query the current HIP device: "
<< hipGetErrorString(err));
32
return
StatusCode::FAILURE;
33
}
34
}
35
36
// Get the device's properties.
37
hipDeviceProp_t props;
38
hipError_t err = hipGetDeviceProperties(&props, deviceID);
39
if
(err != hipSuccess) {
40
ATH_MSG_ERROR
(
41
"Failed to get the HIP device properties: "
<< hipGetErrorString(err));
42
return
StatusCode::FAILURE;
43
}
44
45
// Construct a unique name out of those properties.
46
std::ostringstream
deviceName
;
47
deviceName
<< props.name <<
" [id: "
<< deviceID
48
<<
", bus: "
<< props.pciBusID <<
", device: "
<< props.pciDeviceID
49
<<
"]"
;
50
m_deviceName
=
deviceName
.str();
51
52
// Return gracefully.
53
return
StatusCode::SUCCESS;
54
}
55
56
std::pmr::memory_resource&
DeviceMemoryResourceTool::mr
()
const
{
57
58
assert(
m_mr
);
59
return
*
m_mr
;
60
}
61
62
std::string_view
DeviceMemoryResourceTool::deviceName
()
const
{
63
64
return
m_deviceName
;
65
}
66
67
}
// namespace AthHIP
DeviceMemoryResourceTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
AthHIP::DeviceMemoryResourceTool::mr
virtual std::pmr::memory_resource & mr() const override
Get the provided std::pmr::memory_resource object.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx:56
AthHIP::DeviceMemoryResourceTool::initialize
virtual StatusCode initialize() override
Initialize the tool.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx:16
AthHIP::DeviceMemoryResourceTool::m_deviceName
std::string m_deviceName
Name of the device for which the memory resource is provided.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h:52
AthHIP::DeviceMemoryResourceTool::m_deviceID
Gaudi::Property< int > m_deviceID
Device to allocate memory on.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h:58
AthHIP::DeviceMemoryResourceTool::deviceName
virtual std::string_view deviceName() const override
The name of the device for which the memory resource is provided.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx:62
AthHIP::DeviceMemoryResourceTool::m_mr
std::unique_ptr< std::pmr::memory_resource > m_mr
The memory resource that this tool uses.
Definition
AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h:50
AthHIP
Definition
AthHIP/AthHIPComps/src/AsyncCopyTool.cxx:11
Generated on
for ATLAS Offline Software by
1.17.0