Skip to content

Commit d3790f3

Browse files
authored
Merge branch 'develop' into task/2025_03_expand_hdf5_libver_bounds
2 parents 44eb195 + a3869e6 commit d3790f3

8 files changed

Lines changed: 451 additions & 223 deletions

File tree

.vscode/settings_common.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
77
## Unreleased
88

99
### Added
10+
#### Conduit
11+
- Added `conduit::utils::memory_usage` helper.
1012

1113
#### Blueprint
1214
- Added `conduit::blueprint::<mpi>::mesh::state()`, `conduit::blueprint::<mpi>::mesh::cycle()`, and `conduit::blueprint::<mpi>::mesh::time()`, utilities for getting state information from meshes.
1315

1416
#### Relay
1517
- Added h5z-zfp compression support to relay io hdf5 methods.
1618
- Added `conduit::relay::<mpi>::io::blueprint::generate_root_filename()`, which takes the same arguments as `save_mesh` or `write_mesh` and produces the name of the root file that would be generated by a call to `save_mesh` or `write_mesh`.
19+
- Added `conduit::relay::mpi::memory_usage` and `conduit::relay::mpi::memory_stats` helpers.
1720
- Added `v1120` and `v1140` options to hdf5 libver settings to support 1.12 and 1.14 libver upper range.
1821

22+
1923
### Changed
2024
#### Conduit
2125
- Changed Conduit memory handler callbacks from function pointers to `std::function` objects, allowing users more flexibility in dealing with different memory spaces.

src/libs/conduit/conduit_utils.cpp

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// -- standard lib includes --
1515
//-----------------------------------------------------------------------------
1616

17-
// for sleep funcs
17+
// for sleep and mem usage funcs
1818
#if defined(CONDUIT_PLATFORM_WINDOWS)
1919
#define NOMINMAX
2020
#include <windows.h>
@@ -24,11 +24,19 @@
2424
#endif
2525
#undef min
2626
#undef max
27-
#else
27+
// mem usage api
28+
#include <psapi.h>
29+
30+
#else // not windows
2831
#include <dirent.h>
2932
#include <time.h>
3033
#endif
3134

35+
// for macos memory usage functions
36+
#if defined(CONDUIT_PLATFORM_APPLE) && defined(__MACH__)
37+
#include <mach/mach.h>
38+
#endif
39+
3240
// file system funcs
3341
#include <sys/stat.h>
3442
#include <sys/types.h>
@@ -113,13 +121,13 @@ namespace detail
113121
//
114122
//
115123
// NOTE: THE SINGLETON INSTANCE IS INTENTIONALLY LEAKED!
116-
//
124+
//
117125
// These maps are used by Node instances to alloc and free
118126
// memory, they need to exist as long as any Node object exists!
119127
//
120128
// We are doing static init correctly here, so we
121129
// avoid the C++ static obj init fiasco:
122-
// https://isocpp.org/wiki/faq/ctors#static-init-order
130+
// https://isocpp.org/wiki/faq/ctors#static-init-order
123131
//
124132
// However, we still can't apply fine grained control
125133
// to when these objects are cleaned up. This means
@@ -131,10 +139,10 @@ namespace detail
131139
// into the same compilation unit. We tried this
132140
// but we still hit an on exit cleanup where
133141
// the alloc maps were destructed, but a static Node
134-
// object still needed to cleanup.
142+
// object still needed to cleanup.
135143
//
136144
// If leaking this singleton offends your sensibilities,
137-
// I am sorry. Ideally, these would be cleaned up on
145+
// I am sorry. Ideally, these would be cleaned up on
138146
// exit absolutely last - meaning you could never use
139147
// those few precious bytes for anything else.
140148
//
@@ -956,7 +964,7 @@ strip_quoted_strings(const std::string &input, const std::string &quote_char)
956964
for(size_t i = 0; i < input.size(); ++i)
957965
{
958966
emit = true;
959-
// emit a character when not in a string, including the opening and
967+
// emit a character when not in a string, including the opening and
960968
// closing quote.
961969
//
962970
// check for a quote + start & end of a string
@@ -1665,29 +1673,29 @@ format(const std::string &pattern,
16651673
{
16661674
if(map_index >= curr.number_of_children())
16671675
{
1668-
CONDUIT_ERROR("conduit::utils::format map_index "
1676+
CONDUIT_ERROR("conduit::utils::format map_index "
16691677
<< "(value = " << map_index << ")"
16701678
<< " for '" << itr.name() << "'"
16711679
<< " list map entry "
16721680
<< " is out of bounds."
1673-
<< " Number of children = "
1681+
<< " Number of children = "
16741682
<< curr.number_of_children()
1675-
<< ". Valid range is [0,"
1683+
<< ". Valid range is [0,"
16761684
<< curr.number_of_children() << ").");
16771685
}
16781686
}
16791687
else if(curr.dtype().is_number())
1680-
{
1688+
{
16811689
if(map_index >= curr.dtype().number_of_elements())
16821690
{
1683-
CONDUIT_ERROR("conduit::utils::format map_index "
1691+
CONDUIT_ERROR("conduit::utils::format map_index "
16841692
<< "(value = " << map_index << ")"
16851693
<< " for '" << itr.name() << "'"
16861694
<< " array map entry "
16871695
<< " is out of bounds."
1688-
<< " Number of elements = "
1696+
<< " Number of elements = "
16891697
<< curr.dtype().number_of_elements()
1690-
<< ". Valid range is [0,"
1698+
<< ". Valid range is [0,"
16911699
<< curr.dtype().number_of_elements() << ").");
16921700
}
16931701
}
@@ -1837,7 +1845,7 @@ format(const std::string &pattern,
18371845
}
18381846
break;
18391847
}
1840-
// support lists of strings ONLY ...
1848+
// support lists of strings ONLY ...
18411849
case conduit::DataType::LIST_ID:
18421850
{
18431851
const Node &lst_ent = curr[map_index];
@@ -1860,7 +1868,7 @@ format(const std::string &pattern,
18601868
{
18611869
store.push_back(val);
18621870
}
1863-
1871+
18641872
break;
18651873
}
18661874
default:
@@ -1891,6 +1899,44 @@ format(const std::string &pattern,
18911899
return res;
18921900
}
18931901

1902+
//-----------------------------------------------------------------------------
1903+
uint64
1904+
memory_usage()
1905+
{
1906+
1907+
#if defined(CONDUIT_PLATFORM_WINDOWS)
1908+
PROCESS_MEMORY_COUNTERS pmc;
1909+
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
1910+
{
1911+
return static_cast<uint64>(pmc.WorkingSetSize / 1024);
1912+
}
1913+
#elif defined(CONDUIT_PLATFORM_APPLE)
1914+
mach_task_basic_info_data_t info;
1915+
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
1916+
kern_return_t ret = task_info(mach_task_self(),
1917+
MACH_TASK_BASIC_INFO,
1918+
(task_info_t)&info, &count);
1919+
1920+
if (ret == KERN_SUCCESS)
1921+
{
1922+
return static_cast<uint64>(info.resident_size / 1024);
1923+
}
1924+
1925+
#else //linux, unix, etc
1926+
std::ifstream file("/proc/self/status");
1927+
std::string line;
1928+
while (std::getline(file, line))
1929+
{
1930+
if (line.find("VmRSS") != std::string::npos)
1931+
{
1932+
size_t pos = line.find(":");
1933+
return static_cast<uint64>(std::stoll(line.substr(pos + 1)));
1934+
}
1935+
}
1936+
#endif
1937+
1938+
return 0;
1939+
}
18941940

18951941
//-----------------------------------------------------------------------------
18961942
// String hash functions

src/libs/conduit/conduit_utils.hpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ namespace utils
299299
const void *source,
300300
size_t num);
301301

302-
// general memcpy interface used by conduit
302+
// general memcpy interface used by conduit
303303
void CONDUIT_API conduit_memcpy(void *destination,
304304
const void *source,
305305
size_t num);
@@ -537,7 +537,7 @@ namespace utils
537537
}
538538

539539
//-----------------------------------------------------------------------------
540-
// Helpers to identify value cast consequences
540+
// Helpers to identify value cast consequences
541541
//-----------------------------------------------------------------------------
542542
// adapted from: https://stackoverflow.com/a/17225324/203071
543543
template< typename T_SRC, typename T_DEST>
@@ -547,8 +547,8 @@ namespace utils
547547
{
548548
return true;
549549
}
550-
551-
return ( (value > static_cast<T_SRC>(0) ) ==
550+
551+
return ( (value > static_cast<T_SRC>(0) ) ==
552552
(static_cast<T_DEST>(value) > static_cast<T_DEST>(0))
553553
) && static_cast<T_SRC>(static_cast<T_DEST>(value)) == value;
554554

@@ -599,19 +599,18 @@ namespace utils
599599
std::string CONDUIT_API float64_to_string(float64 value);
600600

601601
//-----------------------------------------------------------------------------
602-
void CONDUIT_API indent(std::ostream &os,
603-
index_t indent,
604-
index_t depth,
605-
const std::string &pad);
602+
void CONDUIT_API indent(std::ostream &os,
603+
index_t indent,
604+
index_t depth,
605+
const std::string &pad);
606606

607607
//-----------------------------------------------------------------------------
608-
void CONDUIT_API sleep(index_t milliseconds);
609-
608+
void CONDUIT_API sleep(index_t milliseconds);
610609

611610
//-----------------------------------------------------------------------------
612611
/// Simple timer class
613612
//-----------------------------------------------------------------------------
614-
class CONDUIT_API Timer
613+
class CONDUIT_API Timer
615614
{
616615
typedef std::chrono::high_resolution_clock high_resolution_clock;
617616
typedef std::chrono::duration<float> fsec;
@@ -660,6 +659,12 @@ namespace utils
660659
*/
661660
std::vector<conduit::index_t> CONDUIT_API factor(conduit::index_t num);
662661

662+
//-----------------------------------------------------------------------------
663+
// Memory usage helper
664+
//-----------------------------------------------------------------------------
665+
/// returns process memory usage in kB, or zero if unable to read usage
666+
uint64 CONDUIT_API memory_usage();
667+
663668
}
664669
//-----------------------------------------------------------------------------
665670
// -- end conduit::utils --

0 commit comments

Comments
 (0)