Skip to content

Commit

Permalink
print out port, component connections in graphviz-friendly style
Browse files Browse the repository at this point in the history
ports get ComponentBase* owners
(incomplete, and the graphs are too huge at the moment)
  • Loading branch information
drjohnson committed Apr 9, 2012
1 parent 1c61279 commit 0090268
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rigel-sim/include/packet/packet.h
Expand Up @@ -93,13 +93,13 @@ class Packet {
int _gcoreid; ///< global core ID (should REMOVE, use TID)
int _gtid; ///< global thread ID

uint32_t _gatomic_operand; /// global atomic operand
uint32_t _gatomic_operand; ///< global atomic operand

uint64_t _birthday; ///< cycle this was constructed

uint64_t _id; ///< unique (modulo 2^64) identifier assigned at creation

bool _completed; /// has been fully serviced
bool _completed; ///< has been fully serviced

};

Expand Down
18 changes: 14 additions & 4 deletions rigel-sim/include/port/port.h
Expand Up @@ -9,6 +9,8 @@
#include <iostream>
#include <cassert>

class ComponentBase;

/// this base class is meaningless
/// FIXME either get rid of or define a general port
/// concept with meaning
Expand Down Expand Up @@ -81,13 +83,17 @@ class InPortBase : public PortBase {

friend class PortManager<T>;

ComponentBase* owner() { return _owner; }
void owner(ComponentBase* o) { _owner = o; }

bool ready() { return _ready; }

private:
bool _valid; /// data is valid
bool _ready; /// ready to accept a message
T data;
std::string _name; ///< port name
T data; ///< templated data payload
std::string _name; ///< port name
ComponentBase* _owner; ///< owning Component
bool _valid; ///< data is valid
bool _ready; ///< ready to accept a message

};

Expand Down Expand Up @@ -147,6 +153,9 @@ class OutPortBase : public PortBase {

std::string name() { return _name; }

ComponentBase* owner() { return _owner; }
void owner(ComponentBase* o) { _owner = o; }

std::string connection_name() {
if (_connection) {
return _connection->name();
Expand All @@ -158,6 +167,7 @@ class OutPortBase : public PortBase {
friend class PortManager<T>;

private:
ComponentBase* _owner;
std::string _name; ///< port name
InPortBase<T>* _connection;

Expand Down
30 changes: 30 additions & 0 deletions rigel-sim/include/port/portmanager.h
@@ -1,6 +1,7 @@

#include <map>
#include <iostream>
#include <fstream>
#include "util/util.h" // for ExitSim

// forward declarations
Expand Down Expand Up @@ -34,6 +35,35 @@ class PortManager {

}

static void DumpGraphviz() {

std::fstream portgraph;

portgraph.open("ports.dot", std::fstream::out);

portgraph << "digraph PortGraph {" << std::endl;

{
typename std::map< std::string, OutPortBase<T>* >::iterator it;
for ( it = OutPorts.begin(); it != OutPorts.end(); ++it ) {
portgraph << (*it).second->owner()->name() << "_" << (*it).second->owner()->id() << " -> ";
portgraph << (*it).first << " -> " << (*it).second->connection_name() << std::endl;
}
}
{
typename std::map< std::string, InPortBase<T>* >::iterator it;
for ( it = InPorts.begin(); it != InPorts.end(); ++it ) {
portgraph << (*it).second->owner()->name() << "_" << (*it).second->owner()->id() << " -> ";
portgraph << (*it).first << std::endl;
}
}

portgraph << "}";

portgraph.close();

}

static void registerInPort( InPortBase<T>* p ) {

typename std::map< std::string, InPortBase<T>* >::iterator it;
Expand Down
1 change: 1 addition & 0 deletions rigel-sim/include/sim/component_base.h
Expand Up @@ -66,6 +66,7 @@ class ComponentBase {
////////////////////////////////////////////////////////////////////////////

void printHierarchy( int indent = 0 );
void printGraphviz();
void dumpHierarchy();
void addChild( ComponentBase* c );

Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/cluster/cluster_cache_functional.cpp
Expand Up @@ -38,11 +38,13 @@ ClusterCacheFunctional::ClusterCacheFunctional(
for (int i = 0; i < coreside_ins.size(); i++) {
std::string n = PortName( name(), id(), "coreside_in", i );
coreside_ins[i] = new InPortCallback<Packet*>(n, mcb);
coreside_ins[i]->owner(this);
}

for (int i = 0; i < coreside_outs.size(); i++) {
std::string n = PortName( name(), id(), "coreside_out", i );
coreside_outs[i] = new OutPortBase<Packet*>(n);
coreside_outs[i]->owner(this);
}

}
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/cluster/cluster_cache_structural.cpp
Expand Up @@ -33,11 +33,13 @@ ClusterCacheStructural::ClusterCacheStructural(
for (unsigned i = 0; i < coreside_ins.size(); i++) {
std::string pname = PortName( name(), id(), "coreside_in", i );
coreside_ins[i] = new InPortBase<Packet*>(pname);
coreside_ins[i]->owner(this);
}

for (unsigned i = 0; i < coreside_outs.size(); i++) {
std::string pname = PortName( name(), id(), "coreside_out", i );
coreside_outs[i] = new OutPortBase<Packet*>(pname);
coreside_outs[i]->owner(this);
}

}
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/cluster/cluster_functional.cpp
Expand Up @@ -23,7 +23,9 @@ ClusterFunctional::ClusterFunctional(
// we like this because the cluster is contained, but the ccache is a separate object
// we could instead try to use a DUMMY port object that basically does this assignment via attach
from_interconnect = new InPortBase<Packet*>( PortName(name(), id(), "in") );
from_interconnect->owner(this);
to_interconnect = new OutPortBase<Packet*>( PortName(name(), id(), "out") );
to_interconnect->owner(this);

// the ccache will actually be responsible for reading, writing to the cluster's ports
ccache = new ClusterCacheFunctional(cp, from_interconnect, to_interconnect);
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/cluster/cluster_structural.cpp
Expand Up @@ -23,7 +23,9 @@ ClusterStructural::ClusterStructural(
// we like this because the cluster is contained, but the ccache is a separate object
// we could instead try to use a DUMMY port object that basically does this assignment via attach
from_interconnect = new InPortBase<Packet*>( PortName(name(), id(), "in") );
from_interconnect->owner(this);
to_interconnect = new OutPortBase<Packet*>( PortName(name(), id(), "out") );
to_interconnect->owner(this);

// the ccache will actually be responsible for reading, writing to the cluster's ports
ccache = new ClusterCacheStructural(cp, from_interconnect, to_interconnect);
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/core/core_functional.cpp
Expand Up @@ -53,7 +53,9 @@ CoreFunctional::CoreFunctional(
std::string pname_out = PortName(name(), id(), "cache_out");
std::string pname_in = PortName(name(), id(), "cache_in");
to_ccache = new OutPortBase<Packet*>(pname_out);
to_ccache->owner(this);
from_ccache = new InPortBase<Packet*>(pname_in);
from_ccache->owner(this);

// per thread init
thread_state.resize(numthreads);
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/interconnect/crossbar.cpp
Expand Up @@ -28,9 +28,11 @@ CrossBar::CrossBar(
// TODO: do elsewhere, and connect
for (unsigned i = 0; i < inports.size(); i++) {
inports[i] = new InPortBase<Packet*>( PortName(name(), id(), "in", i) );
inports[i]->owner(this);
}
for (unsigned i = 0; i < outports.size(); i++) {
outports[i] = new OutPortBase<Packet*>( PortName(name(), id(), "out", i) );
outports[i]->owner(this);
}
}

Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/interconnect/tree_network.cpp
Expand Up @@ -29,9 +29,11 @@ TreeNetwork::TreeNetwork(
// construct ports
for (unsigned i = 0; i < leaf_inports.size(); i++) {
leaf_inports[i] = new InPortBase<Packet*>( PortName(name(), id(), "leaf_in", i) );
leaf_inports[i]->owner(this);
}
for (unsigned i = 0; i < leaf_outports.size(); i++) {
leaf_outports[i] = new OutPortBase<Packet*>( PortName(name(), id(), "leaf_out", i) );
leaf_outports[i]->owner(this);
}
}

Expand Down
6 changes: 6 additions & 0 deletions rigel-sim/src/port/port.cpp
Expand Up @@ -7,10 +7,16 @@
std::string PortName(std::string parent, int id, std::string suffix, int index) {

std::stringstream port_name;
#if 0
port_name << parent << "[" << std::setw(4) << id << "]." << suffix;
if (index >= 0) {
port_name << "[" << std::setw(4) << index << "]";
}
#endif
port_name << parent << "_" << id << "_" << suffix;
if (index >= 0) {
port_name << "_" << index ;
}
return port_name.str();

}
Expand Down
11 changes: 11 additions & 0 deletions rigel-sim/src/sim/component_base.cpp
Expand Up @@ -41,6 +41,17 @@ ComponentBase::printHierarchy( int indent ) {
}
}

/// print object hierarchy in graphviz dot format
void
ComponentBase::printGraphviz() {
for(size_t i=0; i<children_.size(); ++i) {
// print this node
fprintf(stderr,"%s_%d -> ", name_.c_str(), id_);
fprintf(stderr,"%s_%d\n", children_[i]->name().c_str(), children_[i]->id());
children_[i]->printGraphviz();
}
}

/// add a child object to this parent
void
ComponentBase::addChild( ComponentBase* c ) {
Expand Down
2 changes: 2 additions & 0 deletions rigel-sim/src/tile/tile_new.cpp
Expand Up @@ -25,7 +25,9 @@ TileNew::TileNew(
// contruct ports with outside world
// TODO: relocate construction?
from_gnet = new InPortBase<Packet*>( PortName(name(), id(), "memside_in") );
from_gnet->owner(this);
to_gnet = new OutPortBase<Packet*>( PortName(name(), id(), "memside_out") );
to_gnet->owner(this);
//< end contruction of ports

// new interconnect
Expand Down

0 comments on commit 0090268

Please sign in to comment.