Allow core sets to be built from a bitset.

This commit is contained in:
Michael Mueller
2024-07-30 16:03:11 +02:00
parent f366ff7d11
commit c36d2f101e
2 changed files with 18 additions and 0 deletions

View File

@@ -43,6 +43,21 @@ core_set core_set::build(std::uint16_t cores, const Order order)
return core_set;
}
core_set core_set::build(std::uint64_t *core_mask, std::uint16_t count)
{
core_set core_set;
for (int c = 0; c < count; ++count)
{
std::bitset<tasking::config::max_cores()> mask{core_mask[c]};
long core = 0;
while ((core = util::bit_scan_forward(mask.to_ulong())) != -1) {
mask.reset(core);
core_set.emplace_back(core);
}
}
}
namespace mx::util {
std::ostream &operator<<(std::ostream &stream, const core_set &core_set)
{

View File

@@ -8,6 +8,7 @@
#include <mx/system/topology.h>
#include <mx/tasking/config.h>
#include <ostream>
#include <mx/util/bits.h>
namespace mx::util {
/**
@@ -91,6 +92,8 @@ public:
*/
static core_set build(std::uint16_t cores, Order order = Ascending);
static core_set build(std::uint64_t *core_mask, std::uint16_t count);
bool operator==(const core_set &other) const noexcept
{
return _core_identifier == other._core_identifier && _size == other._size && _numa_nodes == other._numa_nodes;