3131#include < functional>
3232#include < string>
3333#include < vector>
34+
3435#if __cplusplus >= 202002L
3536#include < span>
3637#endif
4243 do { \
4344 realm_status_t _status = (call); \
4445 if (_status != REALM_SUCCESS) { \
45- throw std::runtime_error (" Realm C API call failed: " #call); \
46+ throw std::runtime_error (" Realm C API call failed with status " + \
47+ std::to_string (_status) + " : " + #call); \
4648 } \
4749 } while (0 )
4850
@@ -1376,15 +1378,25 @@ namespace REALM_NAMESPACE {
13761378 class Machine {
13771379 private:
13781380 // Templated callback for collecting handles (Processor/Memory) into a std::set
1381+ // CHandleType is the C handle type (e.g., realm_processor_t)
1382+ // HandleType is the C++ wrapper type (e.g., Processor)
13791383 template <typename HandleType, typename CHandleType>
1380- static realm_status_t collect_handle_cb (CHandleType handle, void *user_data)
1384+ static realm_status_t collect_handle_into_set_cb (CHandleType handle, void *user_data)
13811385 {
13821386 std::set<HandleType> &set = *static_cast <std::set<HandleType> *>(user_data);
13831387 set.insert (HandleType (handle));
13841388 return REALM_SUCCESS;
13851389 }
13861390
1387- private:
1391+ template <typename HandleType, typename CHandleType>
1392+ static realm_status_t collect_handle_into_vector_cb (CHandleType handle,
1393+ void *user_data)
1394+ {
1395+ std::vector<HandleType> &vec = *static_cast <std::vector<HandleType> *>(user_data);
1396+ vec.push_back (HandleType (handle));
1397+ return REALM_SUCCESS;
1398+ }
1399+
13881400 realm_runtime_t impl;
13891401
13901402 protected:
@@ -1404,7 +1416,12 @@ namespace REALM_NAMESPACE {
14041416 }
14051417 ~Machine (void ) {}
14061418
1407- static Machine get_machine (void ) { throw std::logic_error (" Not implemented" ); }
1419+ static Machine get_machine (void )
1420+ {
1421+ realm_runtime_t runtime;
1422+ REALM_CHECK (realm_runtime_get_runtime (&runtime));
1423+ return Machine (runtime);
1424+ }
14081425
14091426 class ProcessorQuery ;
14101427 class MemoryQuery ;
@@ -1452,7 +1469,8 @@ namespace REALM_NAMESPACE {
14521469 REALM_CHECK (realm_memory_query_create (runtime, &query));
14531470
14541471 REALM_CHECK (realm_memory_query_iter (
1455- query, &Machine::collect_handle_cb<Memory, realm_memory_t >, &mset, SIZE_MAX));
1472+ query, &Machine::collect_handle_into_set_cb<Memory, realm_memory_t >, &mset,
1473+ SIZE_MAX));
14561474 REALM_CHECK (realm_memory_query_destroy (query));
14571475 }
14581476
@@ -1468,8 +1486,8 @@ namespace REALM_NAMESPACE {
14681486 REALM_CHECK (realm_processor_query_create (runtime, &query));
14691487
14701488 REALM_CHECK (realm_processor_query_iter (
1471- query, &Machine::collect_handle_cb <Processor, realm_processor_t >, &pset ,
1472- SIZE_MAX));
1489+ query, &Machine::collect_handle_into_set_cb <Processor, realm_processor_t >,
1490+ &pset, SIZE_MAX));
14731491 REALM_CHECK (realm_processor_query_destroy (query));
14741492 }
14751493
@@ -1495,8 +1513,8 @@ namespace REALM_NAMESPACE {
14951513 REALM_CHECK (realm_processor_query_restrict_to_address_space (query, runtime_space));
14961514
14971515 REALM_CHECK (realm_processor_query_iter (
1498- query, &Machine::collect_handle_cb <Processor, realm_processor_t >, &pset ,
1499- SIZE_MAX));
1516+ query, &Machine::collect_handle_into_set_cb <Processor, realm_processor_t >,
1517+ &pset, SIZE_MAX));
15001518 REALM_CHECK (realm_processor_query_destroy (query));
15011519 }
15021520
@@ -1526,8 +1544,8 @@ namespace REALM_NAMESPACE {
15261544 REALM_CHECK (realm_processor_query_restrict_to_address_space (query, runtime_space));
15271545
15281546 REALM_CHECK (realm_processor_query_iter (
1529- query, &Machine::collect_handle_cb <Processor, realm_processor_t >, &pset ,
1530- SIZE_MAX));
1547+ query, &Machine::collect_handle_into_set_cb <Processor, realm_processor_t >,
1548+ &pset, SIZE_MAX));
15311549 REALM_CHECK (realm_processor_query_destroy (query));
15321550 }
15331551
@@ -1560,7 +1578,8 @@ namespace REALM_NAMESPACE {
15601578 // For now, just get all memories
15611579
15621580 REALM_CHECK(realm_memory_query_iter(
1563- query, &Machine::collect_handle_cb<Memory, realm_memory_t>, &mset, SIZE_MAX));
1581+ query, &Machine::collect_handle_into_set_cb<Memory, realm_memory_t>, &mset,
1582+ SIZE_MAX));
15641583 REALM_CHECK(realm_memory_query_destroy(query));
15651584#endif
15661585 }
@@ -1594,7 +1613,8 @@ namespace REALM_NAMESPACE {
15941613 // For now, just get all memories
15951614
15961615 REALM_CHECK(realm_memory_query_iter(
1597- query, &Machine::collect_handle_cb<Memory, realm_memory_t>, &mset, SIZE_MAX));
1616+ query, &Machine::collect_handle_into_set_cb<Memory, realm_memory_t>, &mset,
1617+ SIZE_MAX));
15981618 REALM_CHECK(realm_memory_query_destroy(query));
15991619#endif
16001620 }
@@ -1629,7 +1649,7 @@ namespace REALM_NAMESPACE {
16291649 // For now, just get all processors
16301650
16311651 REALM_CHECK(realm_processor_query_iter(
1632- query, &Machine::collect_handle_cb <Processor, realm_processor_t>, &pset,
1652+ query, &Machine::collect_handle_into_set_cb <Processor, realm_processor_t>, &pset,
16331653 SIZE_MAX));
16341654 REALM_CHECK(realm_processor_query_destroy(query));
16351655#endif
@@ -1651,7 +1671,8 @@ namespace REALM_NAMESPACE {
16511671 REALM_CHECK (realm_memory_query_restrict_by_capacity (query, min_capacity));
16521672
16531673 REALM_CHECK (realm_memory_query_iter (
1654- query, &Machine::collect_handle_cb<Memory, realm_memory_t >, &mset, SIZE_MAX));
1674+ query, &Machine::collect_handle_into_set_cb<Memory, realm_memory_t >, &mset,
1675+ SIZE_MAX));
16551676 REALM_CHECK (realm_memory_query_destroy (query));
16561677 }
16571678
@@ -1688,7 +1709,6 @@ namespace REALM_NAMESPACE {
16881709 throw std::logic_error (" Not implemented" );
16891710 }
16901711
1691- public:
16921712 /* *
16931713 * \brief Processor-Memory affinity information.
16941714 */
0 commit comments