ATLAS Offline Software
Loading...
Searching...
No Matches
AthHIP::DeviceMemoryResourceTool Class Reference

Tool providing memory resource for device memory. More...

#include <DeviceMemoryResourceTool.h>

Inheritance diagram for AthHIP::DeviceMemoryResourceTool:
Collaboration diagram for AthHIP::DeviceMemoryResourceTool:

Public Member Functions

Function(s) inherited from @c AthAlgTool
virtual StatusCode initialize () override
 Initialize the tool.
Function(s) inherited from @c AthDevice::IMemoryResourceTool
virtual std::pmr::memory_resource & mr () const override
 Get the provided std::pmr::memory_resource object.
virtual std::string_view deviceName () const override
 The name of the device for which the memory resource is provided.

Private Attributes

std::unique_ptr< std::pmr::memory_resource > m_mr
 The memory resource that this tool uses.
std::string m_deviceName
 Name of the device for which the memory resource is provided.
Tool properties
Gaudi::Property< int > m_deviceID
 Device to allocate memory on.

Detailed Description

Tool providing memory resource for device memory.

Making use of vecmem::hip::device_memory_resource.

Definition at line 22 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h.

Member Function Documentation

◆ deviceName()

std::string_view AthHIP::DeviceMemoryResourceTool::deviceName ( ) const
overridevirtual

The name of the device for which the memory resource is provided.

Definition at line 62 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx.

62 {
63
64 return m_deviceName;
65}
std::string m_deviceName
Name of the device for which the memory resource is provided.

◆ initialize()

StatusCode AthHIP::DeviceMemoryResourceTool::initialize ( )
overridevirtual

Initialize the tool.

Definition at line 16 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx.

16 {
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) {
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) {
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 << "]";
51
52 // Return gracefully.
53 return StatusCode::SUCCESS;
54}
#define ATH_MSG_ERROR(x,...)
Gaudi::Property< int > m_deviceID
Device to allocate memory on.
virtual std::string_view deviceName() const override
The name of the device for which the memory resource is provided.
std::unique_ptr< std::pmr::memory_resource > m_mr
The memory resource that this tool uses.

◆ mr()

std::pmr::memory_resource & AthHIP::DeviceMemoryResourceTool::mr ( ) const
overridevirtual

Get the provided std::pmr::memory_resource object.

Definition at line 56 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.cxx.

56 {
57
58 assert(m_mr);
59 return *m_mr;
60}

Member Data Documentation

◆ m_deviceID

Gaudi::Property<int> AthHIP::DeviceMemoryResourceTool::m_deviceID
private
Initial value:
{
this, "DeviceID", vecmem::hip::device_memory_resource::INVALID_DEVICE,
"ID of the device to allocate memory on (-1 to use the default device)"}

Device to allocate memory on.

Definition at line 58 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h.

58 {
59 this, "DeviceID", vecmem::hip::device_memory_resource::INVALID_DEVICE,
60 "ID of the device to allocate memory on (-1 to use the default device)"};

◆ m_deviceName

std::string AthHIP::DeviceMemoryResourceTool::m_deviceName
private

Name of the device for which the memory resource is provided.

Definition at line 52 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h.

◆ m_mr

std::unique_ptr<std::pmr::memory_resource> AthHIP::DeviceMemoryResourceTool::m_mr
private

The memory resource that this tool uses.

Definition at line 50 of file AthHIP/AthHIPComps/src/DeviceMemoryResourceTool.h.


The documentation for this class was generated from the following files: