The Sparta Modeling Framework
Loading...
Searching...
No Matches
CPUFactory.cpp
1// <CPUFactory.cpp> -*- C++ -*-
2
3
4#include "CPUFactory.hpp"
5#include <string>
6#include <algorithm>
7
12 sparta::ResourceFactory<core_example::CPU, core_example::CPU::CPUParameterSet>(){}
13
18
22auto core_example::CPUFactory::setTopology(const std::string& topology,
23 const uint32_t num_cores) -> void{
24 sparta_assert(!topology_);
25 topology_.reset(core_example::CPUTopology::allocateTopology(topology));
26 topology_->setName(topology);
27 topology_->setNumCores(num_cores);
28}
29
33auto core_example::CPUFactory::buildTree_(sparta::RootTreeNode* root_node,
34 const std::vector<core_example::CPUTopology::UnitInfo>& units) -> void{
35 std::string parent_name, human_name, node_name, replace_with;
36 for(std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores){
37 for(const auto& unit : units){
38 parent_name = unit.parent_name;
39 node_name = unit.name;
40 human_name = unit.human_name;
41 replace_with = std::to_string(num_of_cores);
42 std::replace(parent_name.begin(), parent_name.end(), to_replace_, *replace_with.c_str());
43 std::replace(node_name.begin(), node_name.end(), to_replace_, *replace_with.c_str());
44 std::replace(human_name.begin(), human_name.end(), to_replace_, *replace_with.c_str());
45 auto parent_node = root_node->getChildAs<sparta::TreeNode>(parent_name);
46 auto rtn = new sparta::ResourceTreeNode(parent_node,
47 node_name,
48 unit.group_name,
49 unit.group_id,
50 human_name,
51 unit.factory);
52 if(unit.is_private_subtree){
53 rtn->makeSubtreePrivate();
54 private_nodes_.emplace_back(rtn);
55 }
56 to_delete_.emplace_back(rtn);
57 resource_names_.emplace_back(node_name);
58 }
59 }
60}
61
65auto core_example::CPUFactory::bindTree_(sparta::RootTreeNode* root_node,
66 const std::vector<core_example::CPUTopology::PortConnectionInfo>& ports) -> void{
67 std::string out_port_name, in_port_name,replace_with;
68 for(std::size_t num_of_cores = 0; num_of_cores < topology_->num_cores; ++num_of_cores){
69 for(const auto& port : ports){
70 out_port_name = port.output_port_name;
71 in_port_name = port.input_port_name;
72 replace_with = std::to_string(num_of_cores);
73 std::replace(out_port_name.begin(), out_port_name.end(), to_replace_, *replace_with.c_str());
74 std::replace(in_port_name.begin(), in_port_name.end(), to_replace_, *replace_with.c_str());
75 sparta::bind(root_node->getChildAs<sparta::Port>(out_port_name),
76 root_node->getChildAs<sparta::Port>(in_port_name));
77 }
78
79 // Set the TLBs and preload
80 auto core_tree_node = root_node->getChild(std::string("cpu.core") +
81 sparta::utils::uint32_to_str(num_of_cores));
82 sparta_assert(core_tree_node != nullptr);
83 (core_tree_node->getChild("lsu")->getResourceAs<core_example::LSU>())->
84 setTLB(*private_nodes_.at(num_of_cores)->getResourceAs<core_example::SimpleTLB>());
85 (core_tree_node->getChild("preloader")->getResourceAs<core_example::Preloader>())->
86 preload();
87 }
88}
89
94 sparta_assert(topology_);
95 buildTree_(root_node, topology_->units);
96}
97
102 sparta_assert(topology_);
103 bindTree_(root_node, topology_->port_connections);
104}
105
109auto core_example::CPUFactory::getResourceNames() const -> const std::vector<std::string>&{
110 return resource_names_;
111}
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
auto getResourceNames() const -> const std::vector< std::string > &
Get the list of resources instantiated in this topology.
~CPUFactory()
Destructor for CPUFactory.
auto setTopology(const std::string &, const uint32_t) -> void
Set the user-defined topology for this microarchitecture.
auto buildTree(sparta::RootTreeNode *) -> void
Build the device tree by instantiating resource nodes.
auto bindTree(sparta::RootTreeNode *) -> void
Bind all the ports between different units and set TLBs and preload.
CPUFactory()
Constructor for CPUFactory.
static auto allocateTopology(const std::string &topology) -> CPUTopology *
Static method to allocate memory for topology.
implement a PreloaderIF with appropriate knowledge of how to preload yaml files into the lsu's L1 cac...
Definition Preloader.hpp:29
The port interface used to bind port types together and defines a port behavior.
Definition Port.hpp:59
TreeNode subclass representing a node in the device tree which contains a single ResourceFactory and ...
TreeNode which represents the root ("top") of a device tree.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
const ConstT getChildAs(const std::string &name, bool must_exist=true) const
Retrieves a child that is castable to T with the given dotted path.
void makeSubtreePrivate()
Make the entire subtree private.
Macros for handling exponential backoff.
void bind(Bus *p1, Bus *p2)
Bind two buses together.
Definition Bus.hpp:333