From 4586709ec915b2bd715ec1792537450ee4cfcab2 Mon Sep 17 00:00:00 2001 From: "Samuel K. Gutierrez" Date: Fri, 26 Apr 2024 12:25:46 -0600 Subject: [PATCH] Cleanup mapping types. From and To IDs in mapping are always positive values, so use uint_t. Signed-off-by: Samuel K. Gutierrez --- src/qvi-map.cc | 40 ++++++++++++++++++++++++++-------------- src/qvi-map.h | 15 ++++++++++----- src/qvi-rsmi.cc | 2 +- src/qvi-scope.cc | 16 +++++++++------- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/qvi-map.cc b/src/qvi-map.cc index 06a0d3c1..de15615a 100644 --- a/src/qvi-map.cc +++ b/src/qvi-map.cc @@ -19,7 +19,7 @@ static int k_set_intersection( const qvi_map_shaffinity_t &smap, - std::set &result + std::set &result ) { result.clear(); // Nothing to do. @@ -51,7 +51,7 @@ k_set_intersection( static int make_shared_affinity_map_disjoint( qvi_map_shaffinity_t &samap, - const std::set &interids + const std::set &interids ) { // Number of intersecting consumer IDs. const uint_t ninter = interids.size(); @@ -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(), @@ -73,10 +73,10 @@ make_shared_affinity_map_disjoint( ); } // Copy IDs into a set we can modify. - std::set coii(interids); + std::set 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; @@ -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(); } @@ -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 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; @@ -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 affinity_intersection; + std::set 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; @@ -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 +std::vector qvi_map_flatten( const qvi_map_t &map ) { - std::vector result(map.size()); + std::vector result(map.size()); for (const auto &mi : map) { result[mi.first] = mi.second; } return result; } +std::vector +qvi_map_flatten_to_colors( + const qvi_map_t &map +) { + std::vector 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 diff --git a/src/qvi-map.h b/src/qvi-map.h index 570e5319..e4944582 100644 --- a/src/qvi-map.h +++ b/src/qvi-map.h @@ -36,7 +36,7 @@ qvi_map_maxiperk( ); /** Maintains a mapping between 'From IDs' to 'To IDs'. */ -using qvi_map_t = std::map; +using qvi_map_t = std::map; /** * Defines a function pointer to a desired mapping function. @@ -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>; +using qvi_map_shaffinity_t = std::map>; /** * Prints debug output. @@ -73,7 +73,7 @@ qvi_map_nfids_mapped( bool qvi_map_fid_mapped( const qvi_map_t &map, - int cid + uint_t cid ); /** @@ -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 +std::vector qvi_map_flatten( const qvi_map_t &map ); +std::vector +qvi_map_flatten_to_colors( + const qvi_map_t &map +); + #endif /* diff --git a/src/qvi-rsmi.cc b/src/qvi-rsmi.cc index 4c88c119..632c0ee2 100644 --- a/src/qvi-rsmi.cc +++ b/src/qvi-rsmi.cc @@ -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 diff --git a/src/qvi-scope.cc b/src/qvi-scope.cc index 2ad44716..7860f9b4 100644 --- a/src/qvi-scope.cc +++ b/src/qvi-scope.cc @@ -646,7 +646,7 @@ apply_cpuset_mapping( colors.clear(); } else { - colors = qvi_map_flatten(map); + colors = qvi_map_flatten_to_colors(map); } return rc; } @@ -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, @@ -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); @@ -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);