From 9cb50cebda704a0c7a5a9818e2796d8d8c34e836 Mon Sep 17 00:00:00 2001 From: Colby Nyce Date: Fri, 8 Nov 2024 08:52:53 -0600 Subject: [PATCH] Fix arch-content and tree node extensions final config YAML bugs --- sparta/.gitignore | 3 +- sparta/sparta/parsers/ConfigEmitterYAML.hpp | 117 ++++++++++---------- sparta/src/CommandLineSimulator.cpp | 6 +- sparta/src/Report.cpp | 5 +- 4 files changed, 66 insertions(+), 65 deletions(-) diff --git a/sparta/.gitignore b/sparta/.gitignore index 9378c4b050..0f83e90cef 100644 --- a/sparta/.gitignore +++ b/sparta/.gitignore @@ -11,4 +11,5 @@ build* [Ff]ast[Dd]ebug* cmake-build-* *~ -compile_commands.json \ No newline at end of file +compile_commands.json +.vscode \ No newline at end of file diff --git a/sparta/sparta/parsers/ConfigEmitterYAML.hpp b/sparta/sparta/parsers/ConfigEmitterYAML.hpp index 80c5f6ef36..1b125ab36b 100644 --- a/sparta/sparta/parsers/ConfigEmitterYAML.hpp +++ b/sparta/sparta/parsers/ConfigEmitterYAML.hpp @@ -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. @@ -80,10 +81,12 @@ 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); sparta_assert(device_tree); + sparta_assert(extensions_ptree); if(verbose){ std::cout << "Writing parameters to \"" << filename_ << "\"" << std::endl; @@ -102,53 +105,25 @@ 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> & 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); + + // 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; sparta_assert(emitter_->good()); @@ -172,6 +147,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 @@ -186,15 +196,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(subtree); if(pb){ @@ -396,12 +397,6 @@ class YAML : public ConfigEmitter */ const bool show_param_descs_; - /*! - * \brief Mapping from tree nodes to their named extensions, if any - */ - std::unordered_map>> tree_node_extensions_; - }; // class YAML } // namespace ConfigEmitter diff --git a/sparta/src/CommandLineSimulator.cpp b/sparta/src/CommandLineSimulator.cpp index ba3785ef15..f9eee50bb2 100644 --- a/sparta/src/CommandLineSimulator.cpp +++ b/sparta/src/CommandLineSimulator.cpp @@ -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) diff --git a/sparta/src/Report.cpp b/sparta/src/Report.cpp index a9bd554667..a1e0dd39fe 100644 --- a/sparta/src/Report.cpp +++ b/sparta/src/Report.cpp @@ -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);