forked from hpc-gridware/clusterscheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hpc-gridware:master' into master
- Loading branch information
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/*___INFO__MARK_BEGIN_NEW__*/ | ||
/*************************************************************************** | ||
* | ||
* Copyright 2024 HPC-Gridware GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
***************************************************************************/ | ||
/*___INFO__MARK_END_NEW__*/ | ||
|
||
#include <ranges> | ||
#include <string> | ||
|
||
#include "ocs_HostTopology.h" | ||
|
||
ocs::HostTopology::HostTopology(std::string &topo_mask) : topo_mask(topo_mask) { | ||
parseTopoMask(topo_mask); | ||
numberTopoNodes(sockets); | ||
sortNodes(sockets); | ||
} | ||
|
||
/** @brief Parses the topology mask and builds the topology tree. | ||
* | ||
* EBNF format of a well-formed topology mask: | ||
* topo_mask := socket_mask+ | ||
* socket_mask := socket_char core_mask+ | ||
* core_mask := core_char thread_mask+ | ||
* thread_mask := thread_char | ||
* socket_char := 'S' | 's' | ||
* core_char := 'C' | 'c' | 'E' | 'e' | ||
* thread_char := 'T' | 't' | ||
* | ||
* @param topo_mask | ||
*/ | ||
void | ||
ocs::HostTopology::parseTopoMask(std::string &topo_mask){ | ||
std::vector<Node> cores; | ||
std::vector<Node> threads; | ||
|
||
// We reverse the topo_mask to simplify the parsing! | ||
for (char &it : std::ranges::reverse_view(topo_mask)) { | ||
if (it == 'S' || it == 's') { | ||
// put collected cores into a socket | ||
// std::reverse is not available at su0-0-lx-riscv64. Why? | ||
//std::reverse(cores.begin(), cores.end()); | ||
Node socket(it, std::move(cores)); | ||
cores = std::vector<Node>(); | ||
|
||
// collect all sockets | ||
this->sockets.push_back(std::move(socket)); | ||
} else if (it == 'C' || it == 'c' || it == 'E' || it == 'e') { | ||
// put collected threads into a core | ||
//std::reverse(threads.begin(), threads.end()); | ||
Node core(it, std::move(threads)); | ||
threads = std::vector<Node>(); | ||
|
||
// collect all cores | ||
cores.push_back(std::move(core)); | ||
} else if (it == 'T' || it == 't') { | ||
Node thread(it); | ||
|
||
// collect all threads | ||
threads.push_back(std::move(thread)); | ||
} | ||
} | ||
//std::reverse(sockets.begin(), sockets.end()); | ||
|
||
// We did not strictly parse the EBNF syntax of the topology mask. But need to ensure that it is really well-formed. | ||
// Therefor, we compare the parsed topology mask with the original one. | ||
if (topo_mask != getTopoMask()) { | ||
throw std::runtime_error("Invalid topology mask"); | ||
} | ||
} | ||
|
||
void | ||
ocs::HostTopology::buildTopoMask(const Node& node, std::ostringstream& oss) const { | ||
oss << node.c; | ||
for (const auto& child : node.nodes) { | ||
buildTopoMask(child, oss); | ||
} | ||
} | ||
|
||
void | ||
ocs::HostTopology::buildFullTopoMask(const Node& node, std::ostringstream& oss) const { | ||
oss << node.c << node.id; | ||
for (const auto& child : node.nodes) { | ||
buildFullTopoMask(child, oss); | ||
} | ||
} | ||
|
||
std::string | ||
ocs::HostTopology::getTopoMask() const { | ||
std::ostringstream oss; | ||
for (const auto& socket : sockets) { | ||
buildTopoMask(socket, oss); | ||
} | ||
return oss.str(); | ||
} | ||
|
||
std::string | ||
ocs::HostTopology::getFullTopoMask() const { | ||
std::ostringstream oss; | ||
for (const auto& socket : sockets) { | ||
buildFullTopoMask(socket, oss); | ||
} | ||
return oss.str(); | ||
} | ||
|
||
void | ||
ocs::HostTopology::numberTopoNodes(std::vector<Node> &nodes) { | ||
size_t id = 0; | ||
for (auto &node : nodes) { | ||
node.id = id++; | ||
numberTopoNodes(node.nodes); | ||
} | ||
} | ||
|
||
void | ||
ocs::HostTopology::sortNodes(std::vector<Node>& nodes) { | ||
// also not available on su0-0-lx-riscv64 ? | ||
//std::sort(nodes.begin(), nodes.end(), [](const Node& a, const Node& b) { | ||
// return a.c < b.c; | ||
//}); | ||
for (auto& node : nodes) { | ||
sortNodes(node.nodes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
|
||
/*___INFO__MARK_BEGIN_NEW__*/ | ||
/*************************************************************************** | ||
* | ||
* Copyright 2024 HPC-Gridware GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
***************************************************************************/ | ||
/*___INFO__MARK_END_NEW__*/ | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace ocs { | ||
class HostTopology { | ||
class Node { | ||
public: | ||
char c; | ||
size_t id; | ||
std::vector<Node> nodes; | ||
|
||
explicit Node(char c, std::vector<Node> nodes) : c(c), id(0), nodes(std::move(nodes)) {} | ||
explicit Node(char c) : c(c), id(0), nodes() {} | ||
~Node() = default; | ||
}; | ||
|
||
std::string topo_mask; | ||
std::vector<Node> sockets; | ||
|
||
void parseTopoMask(std::string &topo_mask); | ||
void buildTopoMask(const Node& node, std::ostringstream& oss) const; | ||
void buildFullTopoMask(const Node& node, std::ostringstream& oss) const; | ||
void numberTopoNodes(std::vector<Node> &nodes); | ||
void sortNodes(std::vector<Node>& nodes); | ||
|
||
public: | ||
HostTopology(std::string &topo_mask); | ||
|
||
std::string getTopoMask() const; | ||
std::string getFullTopoMask() const; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*___INFO__MARK_BEGIN_NEW__*/ | ||
/*************************************************************************** | ||
* | ||
* Copyright 2024 HPC-Gridware GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
***************************************************************************/ | ||
/*___INFO__MARK_END_NEW__*/ | ||
|
||
#include <iostream> | ||
|
||
#include "sgeobj/ocs_HostTopology.h" | ||
|
||
int main (int argc, char *argv[]) { | ||
std::string topo_mask = "ScTTCtTsctTtt"; | ||
ocs::HostTopology ht = ocs::HostTopology(topo_mask); | ||
|
||
std::cout << topo_mask << std::endl; | ||
std::cout << ht.getTopoMask() << std::endl; | ||
std::cout << ht.getFullTopoMask() << std::endl; | ||
return 0; | ||
} |