Skip to content

Commit

Permalink
Cleanup mapping types.
Browse files Browse the repository at this point in the history
From and To IDs in mapping are always positive values, so use uint_t.

Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez committed Apr 26, 2024
1 parent 3baaa05 commit 4586709
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
40 changes: 26 additions & 14 deletions src/qvi-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
static int
k_set_intersection(
const qvi_map_shaffinity_t &smap,
std::set<int> &result
std::set<uint_t> &result
) {
result.clear();
// Nothing to do.
Expand Down Expand Up @@ -51,7 +51,7 @@ k_set_intersection(
static int
make_shared_affinity_map_disjoint(
qvi_map_shaffinity_t &samap,
const std::set<int> &interids
const std::set<uint_t> &interids
) {
// Number of intersecting consumer IDs.
const uint_t ninter = interids.size();
Expand All @@ -63,7 +63,7 @@ make_shared_affinity_map_disjoint(
qvi_map_shaffinity_t dmap;
// First remove all IDs that intersect from the provided set map.
for (const auto &mi: samap) {
const int rid = mi.first;
const uint_t rid = mi.first;
std::set_difference(
mi.second.cbegin(),
mi.second.cend(),
Expand All @@ -73,10 +73,10 @@ make_shared_affinity_map_disjoint(
);
}
// Copy IDs into a set we can modify.
std::set<int> coii(interids);
std::set<uint_t> coii(interids);
// Assign disjoint IDs to relevant resources.
for (const auto &mi: samap) {
const int rid = mi.first;
const uint_t rid = mi.first;
uint_t nids = 0;
for (const auto &cid : mi.second) {
if (coii.find(cid) == coii.end()) continue;
Expand Down Expand Up @@ -120,7 +120,7 @@ qvi_map_nfids_mapped(
bool
qvi_map_fid_mapped(
const qvi_map_t &map,
int cid
uint_t cid
) {
return map.find(cid) != map.end();
}
Expand All @@ -142,20 +142,22 @@ qvi_map_colors(
// color_set = {3, 4, 5}, color_vec = {3, 4, 5}
// color_set_index (csi) = {0, 1, 2}, since we have three distinct colors.
// color2csi = {3:0, 4:1, 5:2}.
qvi_map_t color2csi;
std::map<int, uint_t> color2csi;
for (uint_t i = 0; i < color_vec.size(); ++i) {
color2csi.insert({color_vec[i], i});
}
// Create a mapping of color_set indices to cpuset indices.
qvi_map_t csi2cpui;
// We map packed here because we are assuming that like or near colors
// should be mapped close together.
int rc = qvi_map_packed(csi2cpui, nfrom, tres);
if (rc != QV_SUCCESS) return rc;
// Now map the task colors to their respective cpusets.
for (uint_t fid = 0; fid < fcolors.size(); ++fid) {
// Already mapped (potentially by some other mapper).
if (qvi_map_fid_mapped(map, fid)) continue;
const int csi = color2csi.at(fcolors[fid]);
const int tid = csi2cpui.at(csi);
const uint_t csi = color2csi.at(fcolors[fid]);
const uint_t tid = csi2cpui.at(csi);
map.insert({fid, tid});
}
return rc;
Expand Down Expand Up @@ -255,14 +257,13 @@ qvi_map_affinity_preserving(
const qvi_hwloc_cpusets_t &faffs,
const qvi_hwloc_cpusets_t &tores
) {

int rc = QV_SUCCESS;
// Number of consumers.
const uint_t ncon = faffs.size();
// Maps resource IDs to consumer IDs with shared affinity.
qvi_map_shaffinity_t res_affinity_map;
// Stores the consumer IDs that all share affinity with a split resource.
std::set<int> affinity_intersection;
std::set<uint_t> affinity_intersection;
// Determine the consumer IDs that have shared affinity with the resources.
rc = qvi_map_calc_shaffinity(faffs, tores, res_affinity_map);
if (rc != QV_SUCCESS) goto out;
Expand Down Expand Up @@ -303,22 +304,33 @@ hwloc_const_cpuset_t
qvi_map_cpuset_at(
const qvi_map_t &map,
const qvi_hwloc_cpusets_t &cpusets,
int fid
uint_t fid
) {
return cpusets.at(map.at(fid)).data;
}

std::vector<int>
std::vector<uint_t>
qvi_map_flatten(
const qvi_map_t &map
) {
std::vector<int> result(map.size());
std::vector<uint_t> result(map.size());
for (const auto &mi : map) {
result[mi.first] = mi.second;
}
return result;
}

std::vector<int>
qvi_map_flatten_to_colors(
const qvi_map_t &map
) {
std::vector<int> result(map.size());
for (const auto &mi : map) {
result[mi.first] = (int)mi.second;
}
return result;
}

void
qvi_map_debug_dump(
const qvi_map_t &map
Expand Down
15 changes: 10 additions & 5 deletions src/qvi-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ qvi_map_maxiperk(
);

/** Maintains a mapping between 'From IDs' to 'To IDs'. */
using qvi_map_t = std::map<int, int>;
using qvi_map_t = std::map<uint_t, uint_t>;

/**
* Defines a function pointer to a desired mapping function.
Expand All @@ -49,7 +49,7 @@ using qvi_map_fn_t = std::function<
* Maintains a mapping between resource IDs to a set of
* consumer IDs that have shared affinity with a given resource.
*/
using qvi_map_shaffinity_t = std::map<int, std::set<int>>;
using qvi_map_shaffinity_t = std::map<uint_t, std::set<uint_t>>;

/**
* Prints debug output.
Expand All @@ -73,7 +73,7 @@ qvi_map_nfids_mapped(
bool
qvi_map_fid_mapped(
const qvi_map_t &map,
int cid
uint_t cid
);

/**
Expand Down Expand Up @@ -143,14 +143,19 @@ hwloc_const_cpuset_t
qvi_map_cpuset_at(
const qvi_map_t &map,
const qvi_hwloc_cpusets_t &cpusets,
int fid
uint_t fid
);

std::vector<int>
std::vector<uint_t>
qvi_map_flatten(
const qvi_map_t &map
);

std::vector<int>
qvi_map_flatten_to_colors(
const qvi_map_t &map
);

#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion src/qvi-rsmi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#ifdef ROCmSMI_FOUND
#include "rocm_smi/rocm_smi.h"
#include "hwloc/rsmi.h"
#include "hwloc/rsmi.h" // IWYU pragma: keep
#endif

int
Expand Down
16 changes: 9 additions & 7 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ apply_cpuset_mapping(
colors.clear();
}
else {
colors = qvi_map_flatten(map);
colors = qvi_map_flatten_to_colors(map);
}
return rc;
}
Expand Down Expand Up @@ -799,8 +799,8 @@ agg_split_devices_affinity_preserving(
// Now that we have the mapping, assign
// devices to the associated hardware pools.
for (const auto &mi : map) {
const int devid = mi.first;
const int pooli = mi.second;
const uint_t devid = mi.first;
const uint_t pooli = mi.second;
rc = qvi_hwpool_add_device(
splitagg.hwpools[pooli],
devs[devid]->type,
Expand Down Expand Up @@ -883,11 +883,13 @@ agg_split_get_new_osdev_cpusets(
const qvi_scope_split_agg_s &splitagg,
qvi_hwloc_cpusets_t &result
) {
int rc = QV_SUCCESS, nobj = 0;
// The target object type.
const qv_hw_obj_type_t obj_type = splitagg.split_at_type;
// Get the number of devices we have available in the provided scope.
rc = get_nobjs_in_hwpool(splitagg.rmi, splitagg.base_hwpool, obj_type, &nobj);
int nobj = 0;
int rc = get_nobjs_in_hwpool(
splitagg.rmi, splitagg.base_hwpool, obj_type, &nobj
);
if (rc != QV_SUCCESS) return rc;
// Holds the device affinities used for the split.
result.resize(nobj);
Expand Down Expand Up @@ -1236,10 +1238,10 @@ qvi_scope_split_at(
int color,
qv_scope_t **child
) {
int rc = QV_SUCCESS, nobj = 0;
qv_scope_t *ichild = nullptr;

rc = qvi_scope_nobjs(parent, type, &nobj);
int nobj = 0;
int rc = qvi_scope_nobjs(parent, type, &nobj);
if (rc != QV_SUCCESS) goto out;

rc = qvi_scope_split(parent, nobj, color, type, &ichild);
Expand Down

0 comments on commit 4586709

Please sign in to comment.