ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthCUDA
AthCUDAServices
src
AthCUDA/AthCUDAServices/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
// CUDA include(s).
9
#include <cuda_runtime_api.h>
10
11
// System include(s).
12
#include <cassert>
13
14
namespace
AthCUDA
{
15
16
StatusCode
DeviceMemoryResourceTool::initialize
() {
17
18
// Construct the appropriate memory resource.
19
m_mr
= std::make_unique<vecmem::cuda::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::cuda::device_memory_resource::INVALID_DEVICE) {
26
// The default device was requested. We have to query for the current
27
// device.
28
cudaError_t err = cudaGetDevice(&deviceID);
29
if
(err != cudaSuccess) {
30
ATH_MSG_ERROR
(
"Failed to query the current CUDA device: "
31
<< cudaGetErrorString(err));
32
return
StatusCode::FAILURE;
33
}
34
}
35
36
// Get the device's properties.
37
cudaDeviceProp props;
38
cudaError_t err = cudaGetDeviceProperties(&props, deviceID);
39
if
(err != cudaSuccess) {
40
ATH_MSG_ERROR
(
"Failed to get the CUDA device properties: "
41
<< cudaGetErrorString(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 AthCUDA
DeviceMemoryResourceTool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
AthCUDA::DeviceMemoryResourceTool::m_mr
std::unique_ptr< std::pmr::memory_resource > m_mr
The memory resource that this tool uses.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.h:50
AthCUDA::DeviceMemoryResourceTool::m_deviceName
std::string m_deviceName
Name of the device for which the memory resource is provided.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.h:52
AthCUDA::DeviceMemoryResourceTool::mr
virtual std::pmr::memory_resource & mr() const override
Get the provided std::pmr::memory_resource object.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.cxx:56
AthCUDA::DeviceMemoryResourceTool::m_deviceID
Gaudi::Property< int > m_deviceID
Device to allocate memory on.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.h:58
AthCUDA::DeviceMemoryResourceTool::deviceName
virtual std::string_view deviceName() const override
The name of the device for which the memory resource is provided.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.cxx:62
AthCUDA::DeviceMemoryResourceTool::initialize
virtual StatusCode initialize() override
Initialize the tool.
Definition
AthCUDA/AthCUDAServices/src/DeviceMemoryResourceTool.cxx:16
AthCUDA
Definition
Info.h:14
Generated on
for ATLAS Offline Software by
1.17.0