Skip to content

Commit

Permalink
Fix arch-content and tree node extensions final config YAML bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
colby-nyce authored and klingaard committed Nov 11, 2024
1 parent 6b015e3 commit 9cb50ce
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 65 deletions.
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
117 changes: 56 additions & 61 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,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;
Expand All @@ -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<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);

// 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());
Expand All @@ -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
Expand All @@ -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<const ParameterBase*>(subtree);
if(pb){
Expand Down Expand Up @@ -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<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

0 comments on commit 9cb50ce

Please sign in to comment.