Skip to content

Commit

Permalink
readers: remove subgraph feature
Browse files Browse the repository at this point in the history
Problem: adding elasicity into fluxion requires the addition of a
new feature to remove subgraphs from the resource graph.

This implementation removes nodes from the resource graph metadata
and clears the node of edges. This makes those nodes essentially
unreachable through traversal or look up from the metadata. Actually
deleting nodes from the resource graph would invalidate the
vertex descriptors and resource graph metadata. This is because
the reosurce graph is using a listS instead of a vecS.
  • Loading branch information
zekemorton committed Jul 31, 2023
1 parent 2431871 commit a6cb445
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 26 deletions.
4 changes: 4 additions & 0 deletions resource/readers/resource_reader_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class resource_reader_base_t {
virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m,
vtx_t &vtx, const std::string &str, int rank = -1) = 0;

virtual int remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path) = 0;

/*! Update resource graph g with str.
*
* \param g resource graph
Expand Down
8 changes: 8 additions & 0 deletions resource/readers/resource_reader_grug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@ int resource_reader_grug_t::unpack_at (resource_graph_t &g,
return -1;
}

int resource_reader_grug_t::remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path)
{
errno = ENOTSUP; // GRUG reader does not support remove
return -1;
}

int resource_reader_grug_t::update (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &str, int64_t jobid,
Expand Down
4 changes: 4 additions & 0 deletions resource/readers/resource_reader_grug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class resource_reader_grug_t : public resource_reader_base_t {
virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m,
vtx_t &vtx, const std::string &str, int rank = -1);

virtual int remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path);

/*! Update resource graph g with str.
*
* \param g resource graph
Expand Down
9 changes: 8 additions & 1 deletion resource/readers/resource_reader_hwloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ int resource_reader_hwloc_t::walk_hwloc (resource_graph_t &g,
rc = -1;
break;
}
if (remap_id
if (remap_id
> static_cast<uint64_t> (std::numeric_limits<int>::max ())) {
errno = EOVERFLOW;
m_err_msg += "Remapped gpu id too large; ";
Expand Down Expand Up @@ -508,6 +508,13 @@ int resource_reader_hwloc_t::unpack_at (resource_graph_t &g,
return unpack_internal (g, m, vtx, str, rank);
}

int resource_reader_hwloc_t::remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path)
{
errno = ENOTSUP; // hwloc reader does not support remove
return -1;
}
int resource_reader_hwloc_t::update (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &str, int64_t jobid,
Expand Down
4 changes: 4 additions & 0 deletions resource/readers/resource_reader_hwloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class resource_reader_hwloc_t : public resource_reader_base_t {
virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m,
vtx_t &vtx, const std::string &str, int rank = -1);

virtual int remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path);

/*! Update resource graph g with str.
*
* \param g resource graph
Expand Down
128 changes: 112 additions & 16 deletions resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <unordered_set>
#include <unistd.h>
#include <jansson.h>
#include <cstdlib>
#include "resource/readers/resource_reader_jgf.hpp"
#include "resource/store/resource_graph_store.hpp"
#include "resource/planner/planner.h"
Expand Down Expand Up @@ -282,7 +283,7 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f,
m_err_msg += std::to_string (f.rank) + ".\n";
goto error;
}
if (remap_rank
if (remap_rank
> static_cast<uint64_t> (std::numeric_limits<int64_t>::max ())) {
errno = EOVERFLOW;
m_err_msg += __FUNCTION__;
Expand All @@ -298,7 +299,7 @@ int resource_reader_jgf_t::unpack_and_remap_vtx (fetch_helper_t &f,
m_err_msg += " rank=" + std::to_string (f.rank) + ".\n";
goto error;
}
if (remap_id
if (remap_id
> static_cast<uint64_t> (std::numeric_limits<int>::max ())) {
errno = EOVERFLOW;
m_err_msg += __FUNCTION__;
Expand Down Expand Up @@ -457,7 +458,7 @@ vtx_t resource_reader_jgf_t::create_vtx (resource_graph_t &g,

vtx_t resource_reader_jgf_t::vtx_in_graph (const resource_graph_t &g,
const resource_graph_metadata_t &m,
const std::map<std::string,
const std::map<std::string,
std::string> &paths,
int rank)
{
Expand Down Expand Up @@ -528,17 +529,52 @@ int resource_reader_jgf_t::add_graph_metadata (vtx_t v,
return rc;
}

int resource_reader_jgf_t::update_vmap (std::map<std::string,
int resource_reader_jgf_t::remove_graph_metadata (vtx_t v,
resource_graph_t &g,
resource_graph_metadata_t &m)
{
int rc = -1;
for (auto kv : g[v].paths) {
m.by_path.erase(kv.second);
}

for (auto it = m.by_type[g[v].type].begin(); it != m.by_type[g[v].type].end(); ++it){
if (*it == v){
m.by_type[g[v].type].erase(it);
break;
}
}

for (auto it = m.by_name[g[v].name].begin(); it != m.by_name[g[v].name].end(); ++it){
if (*it == v){
m.by_name[g[v].name].erase(it);
break;
}
}

for (auto it = m.by_rank[g[v].rank].begin(); it != m.by_rank[g[v].rank].end(); ++it){
if (*it == v){
m.by_rank[g[v].rank].erase(it);
break;
}
}

rc = 0;

return rc;
}

int resource_reader_jgf_t::update_vmap (std::map<std::string,
vmap_val_t> &vmap,
vtx_t v,
const std::map<std::string,
vtx_t v,
const std::map<std::string,
bool> &root_checks,
const fetch_helper_t &fetcher)
{
int rc = -1;
std::pair<std::map<std::string, vmap_val_t>::iterator, bool> ptr;
ptr = vmap.emplace (std::string (fetcher.vertex_id),
vmap_val_t{v, root_checks,
ptr = vmap.emplace (std::string (fetcher.vertex_id),
vmap_val_t{v, root_checks,
static_cast<unsigned int> (fetcher.size),
static_cast<unsigned int> (fetcher.exclusive)});
if (!ptr.second) {
Expand Down Expand Up @@ -776,7 +812,7 @@ int resource_reader_jgf_t::unpack_vertices (resource_graph_t &g,
resource_graph_metadata_t &m,
std::map<std::string,
vmap_val_t> &vmap,
json_t *nodes,
json_t *nodes,
std::unordered_set<std::string>
&added_vtcs)
{
Expand Down Expand Up @@ -894,7 +930,7 @@ int resource_reader_jgf_t::unpack_edges (resource_graph_t &g,
resource_graph_metadata_t &m,
std::map<std::string,
vmap_val_t> &vmap,
json_t *edges,
json_t *edges,
const std::unordered_set
<std::string> &added_vtcs)
{
Expand All @@ -914,7 +950,7 @@ int resource_reader_jgf_t::unpack_edges (resource_graph_t &g,
if ( (unpack_edge (element, vmap, source, target, &name)) != 0)
goto done;
// We only add the edge when it connects at least one newly added vertex
if ( (added_vtcs.count (source) == 1)
if ( (added_vtcs.count (source) == 1)
|| (added_vtcs.count (target) == 1)) {
tie (e, inserted) = add_edge (vmap[source].v, vmap[target].v, g);
if (inserted == false) {
Expand Down Expand Up @@ -1053,6 +1089,35 @@ int resource_reader_jgf_t::update_edges (resource_graph_t &g,
return rc;
}

int resource_reader_jgf_t::get_subgraph_nodes (resource_graph_t &g,
vtx_t node,
std::vector<vtx_t> &node_list)
{
vtx_t next_node;
boost::graph_traits<resource_graph_t>::out_edge_iterator ei, ei_end;
boost::tie (ei, ei_end) = boost::out_edges (node, g);

for (; ei != ei_end; ++ei) {
next_node = boost::target (*ei, g);

for (auto const &paths_it : g[next_node].paths) {
// check that we don't recurse on parent edges
if (paths_it.second.find(g[node].name) != std::string::npos &&
paths_it.second.find(g[node].name) < paths_it.second.find(g[next_node].name)) {

node_list.push_back(next_node);
get_subgraph_nodes(g, next_node, node_list);
break;
}

}


}

return 0;
}


/********************************************************************************
* *
Expand Down Expand Up @@ -1099,12 +1164,12 @@ int resource_reader_jgf_t::unpack_at (resource_graph_t &g,
resource_graph_metadata_t &m, vtx_t &vtx,
const std::string &str, int rank)
{
/* This functionality is currently experimental, as resource graph
* growth causes a resize of the boost vecS vertex container type.
* Resizing the vecS results in lost job allocations and reservations
/* This functionality is currently experimental, as resource graph
* growth causes a resize of the boost vecS vertex container type.
* Resizing the vecS results in lost job allocations and reservations
* as there is no copy constructor for planner.
* vtx_t vtx is not implemented and may be used in the future
* for optimization.
* vtx_t vtx is not implemented and may be used in the future
* for optimization.
*/

return unpack (g, m, str, rank);
Expand Down Expand Up @@ -1144,6 +1209,37 @@ int resource_reader_jgf_t::update (resource_graph_t &g,
return rc;
}

int resource_reader_jgf_t::remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path)
{
vtx_t my_vtx = boost::graph_traits<resource_graph_t>::null_vertex ();
std::vector<vtx_t> node_list;

auto iter = m.by_path.find (path);
if (iter == m.by_path.end ()) {
return -1;
}

for (auto &v : iter->second) {
my_vtx = v;
}

node_list.push_back(my_vtx);

get_subgraph_nodes(g, my_vtx, node_list);

for (auto & node : node_list)
{
// clear vertex edges but don't delete vertex
boost::clear_vertex(node, g);
remove_graph_metadata(node, g, m);
}

return 0;

}

bool resource_reader_jgf_t::is_allowlist_supported ()
{
return false;
Expand Down
24 changes: 17 additions & 7 deletions resource/readers/resource_reader_jgf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class resource_reader_jgf_t : public resource_reader_base_t {
const std::string &str, int64_t jobid, int64_t at,
uint64_t dur, bool rsv, uint64_t trav_token);

virtual int remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path);


/*! Is the selected reader format support allowlist
*
* \return false
Expand All @@ -100,7 +105,9 @@ class resource_reader_jgf_t : public resource_reader_base_t {
std::map<std::string, bool> &is_roots);
int add_graph_metadata (vtx_t v, resource_graph_t &g,
resource_graph_metadata_t &m);
int update_vmap (std::map<std::string, vmap_val_t> &vmap, vtx_t v,
int remove_graph_metadata (vtx_t v, resource_graph_t &g,
resource_graph_metadata_t &m);
int update_vmap (std::map<std::string, vmap_val_t> &vmap, vtx_t v,
const std::map<std::string, bool> &root_checks,
const fetch_helper_t &fetcher);
int add_vtx (resource_graph_t &g, resource_graph_metadata_t &m,
Expand All @@ -121,19 +128,19 @@ class resource_reader_jgf_t : public resource_reader_base_t {
const fetch_helper_t &fetcher, uint64_t jobid, int64_t at,
uint64_t dur, bool rsv);
int unpack_vertices (resource_graph_t &g, resource_graph_metadata_t &m,
std::map<std::string, vmap_val_t> &vmap,
std::map<std::string, vmap_val_t> &vmap,
json_t *nodes,
std::unordered_set<std::string> &added_vtcs);
int undo_vertices (resource_graph_t &g,
std::map<std::string, vmap_val_t> &vmap,
uint64_t jobid, bool rsv);
int update_vertices (resource_graph_t &g, resource_graph_metadata_t &m,
std::map<std::string, vmap_val_t> &vmap,
json_t *nodes, int64_t jobid, int64_t at,
std::map<std::string, vmap_val_t> &vmap,
json_t *nodes, int64_t jobid, int64_t at,
uint64_t dur, bool rsv);
int update_vertices (resource_graph_t &g, resource_graph_metadata_t &m,
std::map<std::string, vmap_val_t> &vmap,
json_t *nodes, int64_t jobid, int64_t at,
std::map<std::string, vmap_val_t> &vmap,
json_t *nodes, int64_t jobid, int64_t at,
uint64_t dur);
int unpack_edge (json_t *element, std::map<std::string, vmap_val_t> &vmap,
std::string &source, std::string &target, json_t **name);
Expand All @@ -145,12 +152,15 @@ class resource_reader_jgf_t : public resource_reader_base_t {
std::string &source, std::string &target,
uint64_t token);
int unpack_edges (resource_graph_t &g, resource_graph_metadata_t &m,
std::map<std::string, vmap_val_t> &vmap,
std::map<std::string, vmap_val_t> &vmap,
json_t *edges,
const std::unordered_set<std::string> &added_vtcs);
int update_edges (resource_graph_t &g, resource_graph_metadata_t &m,
std::map<std::string, vmap_val_t> &vmap,
json_t *edges, uint64_t token);
int get_subgraph_nodes (resource_graph_t &g,
vtx_t node,
std::vector<vtx_t> &node_list);
};

} // namespace resource_model
Expand Down
12 changes: 10 additions & 2 deletions resource/readers/resource_reader_rv1exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ int resource_reader_rv1exec_t::unpack_children (resource_graph_t &g,
const char *ids_str = json_string_value (res_ids);
if (unpack_child (g, m, parent, res_type, ids_str, rank, pmap) < 0)
goto error;
}
}
return 0;

error:
Expand Down Expand Up @@ -571,7 +571,7 @@ int resource_reader_rv1exec_t::unpack_internal (resource_graph_t &g,
json_t *nodelist = nullptr;
json_t *properties = nullptr;
struct hostlist *hlist = nullptr;
std::map<unsigned, unsigned> rmap;
std::map<unsigned, unsigned> rmap;
std::map<unsigned, properties_t> pmap;

if (json_unpack (rv1, "{s:i s:{s:o s:o s?o}}",
Expand Down Expand Up @@ -669,6 +669,14 @@ int resource_reader_rv1exec_t::unpack_at (resource_graph_t &g,
return -1;
}

int resource_reader_rv1exec_t::remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path)
{
errno = ENOTSUP; // RV1Exec reader does not support remove
return -1;
}

int resource_reader_rv1exec_t::update (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &str, int64_t jobid,
Expand Down
4 changes: 4 additions & 0 deletions resource/readers/resource_reader_rv1exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class resource_reader_rv1exec_t : public resource_reader_base_t {
virtual int unpack_at (resource_graph_t &g, resource_graph_metadata_t &m,
vtx_t &vtx, const std::string &str, int rank = -1);

virtual int remove_subgraph (resource_graph_t &g,
resource_graph_metadata_t &m,
const std::string &path);

/*! Update resource graph g with str.
*
* \param g resource graph
Expand Down

0 comments on commit a6cb445

Please sign in to comment.