-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathMemoryInfos.cpp
More file actions
79 lines (73 loc) · 2.63 KB
/
MemoryInfos.cpp
File metadata and controls
79 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2024 TotalEnergies
* Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2023-2024 Chevron
* Copyright (c) 2019- GEOS/GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/
#include "MemoryInfos.hpp"
namespace geos
{
MemoryInfos::MemoryInfos( umpire::MemoryResourceTraits::resource_type resourceType ):
m_totalMemory( 0 ),
m_availableMemory( 0 ),
m_physicalMemoryHandled( 1 )
{
switch( resourceType )
{
case umpire::MemoryResourceTraits::resource_type::host:
case umpire::MemoryResourceTraits::resource_type::pinned:
#if defined( _SC_PHYS_PAGES ) && defined( _SC_PAGESIZE )
m_totalMemory = sysconf( _SC_PHYS_PAGES ) * sysconf( _SC_PAGESIZE );
#if defined(_SC_AVPHYS_PAGES)
m_availableMemory = sysconf( _SC_AVPHYS_PAGES ) * sysconf( _SC_PAGESIZE );
#else
GEOS_WARNING( "Unknown device avaialable memory size getter for this system." );
m_availableMemory = 0;
#endif
#else
GEOS_WARNING( "Unknown device physical memory size getter for this compiler." );
m_physicalMemoryHandled = 0;
#endif
break;
case umpire::MemoryResourceTraits::resource_type::device:
case umpire::MemoryResourceTraits::resource_type::device_const:
case umpire::MemoryResourceTraits::resource_type::um:
#if defined( GEOS_USE_CUDA )
cudaMemGetInfo( &m_availableMemory, &m_totalMemory );
#elif defined( GEOS_USE_HIP )
{
hipError_t const err = hipMemGetInfo( &m_availableMemory, &m_totalMemory );
GEOS_WARNING_IF( err != hipSuccess, GEOS_FMT( "HIP error found: {} at {}:{}", hipGetErrorString( err ), __FILE__, __LINE__ ) );
}
#else
GEOS_WARNING( "Unknown device physical memory size getter for this compiler." );
m_physicalMemoryHandled = 0;
#endif
break;
default:
GEOS_WARNING( "Physical memory lookup not implemented" );
m_physicalMemoryHandled = 0;
break;
}
}
size_t MemoryInfos::getTotalMemory() const
{
return m_totalMemory;
}
size_t MemoryInfos::getAvailableMemory() const
{
return m_availableMemory;
}
bool MemoryInfos::isPhysicalMemoryHandled() const
{
return m_physicalMemoryHandled;
}
}