Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arch-content and tree node extensions final config YAML bugs #540

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sparta/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ build*
[Ff]ast[Dd]ebug*
cmake-build-*
*~
compile_commands.json
compile_commands.json
.vscode
116 changes: 56 additions & 60 deletions sparta/sparta/parsers/ConfigEmitterYAML.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "sparta/simulation/Parameter.hpp"
#include "sparta/app/SimulationInfo.hpp"
#include "sparta/simulation/TreeNodePrivateAttorney.hpp"
#include "sparta/simulation/ParameterTree.hpp"

namespace YP = YAML; // Prevent collision with YAML class in ConfigEmitter namespace.

Expand Down Expand Up @@ -80,6 +81,7 @@ class YAML : public ConfigEmitter
* \post emitter_ will be nullptr
*/
void addParameters(TreeNode* device_tree,
const ParameterTree* extensions_ptree,
bool verbose=false)
{
sparta_assert(emitter_ == nullptr);
Expand All @@ -102,52 +104,26 @@ class YAML : public ConfigEmitter

*emitter_ << YP::BeginDoc;
sparta_assert(emitter_->good());
handleNode_(device_tree, verbose); // Recurse

if (!tree_node_extensions_.empty()) {
for (auto & ext_info : tree_node_extensions_) {
TreeNode * tn = ext_info.first;
std::vector<std::pair<std::string, TreeNode::ExtensionsBase*>> & node_extensions =
ext_info.second;

*emitter_ << YP::BeginMap;
*emitter_ << YP::Key << tn->getLocation();
*emitter_ << YP::Value;
*emitter_ << YP::BeginMap;

for (auto & node_extension : node_extensions) {
*emitter_ << YP::Key << ("extension." + node_extension.first);
*emitter_ << YP::Value;
*emitter_ << YP::BeginMap;

TreeNode::ExtensionsBase * ext_base = node_extension.second;
ParameterSet * params = ext_base->getYamlOnlyParameters();
auto param_names = params->getNames();
for (const auto & param_name : param_names) {
*emitter_ << YP::Key << param_name;
*emitter_ << YP::Value // << YP::PadToColumn(50)
<< params->getParameter(param_name)->getValueAsString();
std::stringstream tags;
params->getParameter(param_name)->stringizeTags(tags);
*emitter_ << YP::Comment(tags.str());
}

params = ext_base->getParameters();
param_names = params->getNames();
for (const auto & param_name : param_names) {
*emitter_ << YP::Key << param_name;
*emitter_ << YP::Value // << YP::PadToColumn(50)
<< params->getParameter(param_name)->getValueAsString();
std::stringstream tags;
params->getParameter(param_name)->stringizeTags(tags);
*emitter_ << YP::Comment(tags.str());
}

*emitter_ << YP::EndMap;
}
*emitter_ << YP::EndMap;
*emitter_ << YP::EndMap;
}
handleNode_(device_tree, verbose);

if (extensions_ptree) {
// Note we use the ParameterTree to get the tree node extensions instead
// of the device tree since using the device tree might serialize an extension
// defn of:
//
// top.cpu.core*.extension.core_extensions:
// name: value
// name: value
//
// As:
//
// top.cpu.core0.extension.core_extensions:
// name: value
// name: value
//
// But the ParameterTree retains the wildcards in the path.
handleNode_(extensions_ptree->getRoot());
}

*emitter_ << YP::EndDoc;
Expand All @@ -172,6 +148,41 @@ class YAML : public ConfigEmitter


private:
/*!
* \brief Recursively write the TreeNode extensions defns to YAML
*/
void handleNode_(const ParameterTree::Node* subtree)
{
sparta_assert(subtree);
sparta_assert(emitter_ != nullptr);

if (subtree->getName() == "extension") {
auto location_key = subtree->getParent()->getPath();
*emitter_ << YP::BeginMap;
*emitter_ << YP::Key << location_key;
*emitter_ << YP::Value;
*emitter_ << YP::BeginMap;

for (const auto child : subtree->getChildren()) {
auto extension_name = child->getName();
*emitter_ << YP::Key << ("extension." + extension_name);
*emitter_ << YP::Value;
*emitter_ << YP::BeginMap;
for (const auto param : child->getChildren()) {
*emitter_ << YP::Key << param->getName();
*emitter_ << YP::Value << param->getValue();
}
*emitter_ << YP::EndMap;
}

*emitter_ << YP::EndMap;
*emitter_ << YP::EndMap;
} else {
for (const auto child : subtree->getChildren()) {
handleNode_(child);
}
}
}

/*!
* \brief Render the content of this node as a sequence of YAML
Expand All @@ -186,15 +197,6 @@ class YAML : public ConfigEmitter
sparta_assert(subtree);
sparta_assert(emitter_ != nullptr);

const auto & extension_names = subtree->getAllExtensionNames();
for (const auto & ext_name : extension_names) {
auto extension = subtree->getExtension(ext_name);
if (extension) {
tree_node_extensions_[subtree].emplace_back(
std::make_pair(ext_name, subtree->getExtension(ext_name)));
}
}

// Print parameter value if this node is a parameter
const ParameterBase* pb = dynamic_cast<const ParameterBase*>(subtree);
if(pb){
Expand Down Expand Up @@ -396,12 +398,6 @@ class YAML : public ConfigEmitter
*/
const bool show_param_descs_;

/*!
* \brief Mapping from tree nodes to their named extensions, if any
*/
std::unordered_map<TreeNode*,
std::vector<std::pair<std::string, TreeNode::ExtensionsBase*>>> tree_node_extensions_;

}; // class YAML

} // namespace ConfigEmitter
Expand Down
6 changes: 4 additions & 2 deletions sparta/src/CommandLineSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2110,13 +2110,15 @@ void CommandLineSimulator::populateSimulation_(Simulation* sim)
if(final_config_file_ != ""){
sparta::ConfigEmitter::YAML param_out(final_config_file_,
false); // Hide descriptions
param_out.addParameters(sim->getRoot()->getSearchScope(), sim_config_.verbose_cfg);
const auto& ptree = sim->getSimulationConfiguration()->getExtensionsUnboundParameterTree();
param_out.addParameters(sim->getRoot()->getSearchScope(), &ptree, sim_config_.verbose_cfg);
}

if(final_config_file_verbose_ != ""){
sparta::ConfigEmitter::YAML param_out(final_config_file_verbose_,
true); // Show descriptions
param_out.addParameters(sim->getRoot()->getSearchScope(), sim_config_.verbose_cfg);
const auto& ptree = sim->getSimulationConfiguration()->getExtensionsUnboundParameterTree();
param_out.addParameters(sim->getRoot()->getSearchScope(), &ptree, sim_config_.verbose_cfg);
}

if(sim_config_.pipeline_collection_file_prefix != NoPipelineCollectionStr)
Expand Down
5 changes: 4 additions & 1 deletion sparta/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,16 @@ class ReportFileParserYAML
}
}
}
else{
else if (!skip_content_leaves_){
Report* const r = report_map_.at(scope.uid);
statistics::expression::Expression expr(assoc_key, node_context, r->getStatistics());

// Add the expresssion
add_expression(expr);
}
else {
return true;
}
}
else{
Report* const r = report_map_.at(scope.uid);
Expand Down
6 changes: 3 additions & 3 deletions sparta/test/TreeNode/TreeNode_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ int main()
sparta::ConfigEmitter::YAML param_out(filename_orig,
true); // verbose

EXPECT_NOTHROW(param_out.addParameters(&top, true)); // verbose
EXPECT_NOTHROW(param_out.addParameters(&top, nullptr, true)); // verbose

// Ensure taht the read count on this crazy parameter has not changed
// when emitting the YAML
Expand All @@ -1128,7 +1128,7 @@ int main()
// Store Parameter Tree
sparta::ConfigEmitter::YAML param_out(filename_new,
false); // Terse
EXPECT_NOTHROW(param_out.addParameters(&top, false));
EXPECT_NOTHROW(param_out.addParameters(&top, nullptr, false));

// Reset read counts to write them again
recurs_reset(&top);
Expand All @@ -1144,7 +1144,7 @@ int main()
// Store Parameter Tree
sparta::ConfigEmitter::YAML param_out(filename_new,
true); // Verbose
EXPECT_NOTHROW(param_out.addParameters(&top, false));
EXPECT_NOTHROW(param_out.addParameters(&top, nullptr, false));

// Reset read counts to write them again
recurs_reset(&top);
Expand Down
Loading