start developing mux library

This commit is contained in:
tangxifan 2019-08-18 12:31:59 -06:00
parent 153d506abb
commit 893683fa95
6 changed files with 180 additions and 31 deletions

View File

@ -48,7 +48,8 @@ MuxGraph::mem_range MuxGraph::memories() const {
/* Find the number of inputs in the MUX graph */
size_t MuxGraph::num_inputs() const {
/* FIXME: need to check if the graph is valid or not */
/* need to check if the graph is valid or not */
VTR_ASSERT_SAFE(valid_mux_graph());
/* Sum up the number of INPUT nodes in each level */
size_t num_inputs = 0;
for (auto node_per_level : node_lookup_) {
@ -59,14 +60,16 @@ size_t MuxGraph::num_inputs() const {
/* Find the number of levels in the MUX graph */
size_t MuxGraph::num_levels() const {
/* FIXME: need to check if the graph is valid or not */
/* need to check if the graph is valid or not */
VTR_ASSERT_SAFE(valid_mux_graph());
/* The num_levels by definition excludes the level for outputs, so a deduection is applied */
return node_lookup_.size() - 1;
}
/* Find the number of configuration memories in the MUX graph */
size_t MuxGraph::num_memory_bits() const {
/* FIXME: need to check if the graph is valid or not */
/* need to check if the graph is valid or not */
VTR_ASSERT_SAFE(valid_mux_graph());
return mem_ids_.size();
}
@ -488,6 +491,11 @@ void MuxGraph::build_node_lookup() {
}
}
/* Invalidate (empty) the node fast lookup*/
void MuxGraph::invalidate_node_lookup() {
node_lookup_.clear();
}
/**************************************************
* Private validators
*************************************************/
@ -522,11 +530,6 @@ bool MuxGraph::valid_node_lookup() const {
return node_lookup_.empty();
}
/* Invalidate (empty) the node fast lookup*/
void MuxGraph::invalidate_node_lookup() {
node_lookup_.clear();
}
/* validate a mux graph and see if it is valid */
bool MuxGraph::valid_mux_graph() const {
/* A valid MUX graph should be
@ -568,12 +571,3 @@ bool MuxGraph::valid_mux_graph() const {
/**************************************************
* End of Member functions for the class MuxGraph
*************************************************/
/**************************************************
* Member functions for the class MuxLibrary
*************************************************/
/**************************************************
* End of Member functions for the class MuxLibrary
*************************************************/

View File

@ -24,9 +24,8 @@
*
*************************************************/
#ifndef MUX_ARCH_H
#define MUX_ARCH_H
#ifndef MUX_GRAPH_H
#define MUX_GRAPH_H
#include "vtr_vector.h"
#include "vtr_range.h"
@ -126,12 +125,4 @@ class MuxGraph {
mutable NodeLookup node_lookup_; /* [num_levels][num_types][num_nodes_per_level] */
};
class MuxLibrary {
private: /* Internal data */
/* MUX graph-based desription */
vtr::vector<MuxId, MuxGraph> mux_graphs_; /* Graphs describing MUX internal structures */
vtr::vector<MuxId, CircuitModelId> circuit_model_ids_; /* ids in the circuit library, each MUX graph belongs to*/
/* Local encoder description */
};
#endif

View File

@ -9,19 +9,16 @@
#include "vtr_strong_id.h"
/* Strong Ids for MUXes */
struct mux_id_tag;
struct mux_node_id_tag;
struct mux_edge_id_tag;
struct mux_mem_id_tag;
struct mux_input_id_tag;
typedef vtr::StrongId<mux_id_tag> MuxId;
typedef vtr::StrongId<mux_node_id_tag> MuxNodeId;
typedef vtr::StrongId<mux_edge_id_tag> MuxEdgeId;
typedef vtr::StrongId<mux_mem_id_tag> MuxMemId;
typedef vtr::StrongId<mux_input_id_tag> MuxInputId;
class MuxGraph;
class MuxLibrary;
#endif

View File

@ -0,0 +1,100 @@
/**************************************************
* This file includes member functions for the
* data structures in mux_library.h
*************************************************/
#include "vtr_assert.h"
#include "mux_library.h"
/**************************************************
* Member functions for the class MuxLibrary
*************************************************/
/**************************************************
* Public accessors: data query
*************************************************/
/* Get a MUX graph (read-only) */
MuxId MuxLibrary::mux_graph(const CircuitModelId& circuit_model,
const size_t& mux_size) const {
/* Make sure we have a valid mux look-up */
VTR_ASSERT_SAFE(valid_mux_lookup());
/* Validate circuit model id and mux_size */
VTR_ASSERT_SAFE(valid_mux_size(circuit_model, mux_size));
return mux_lookup_[circuit_model][mux_size];
}
const MuxGraph& MuxLibrary::mux_graph(const MuxId& mux_id) const {
VTR_ASSERT_SAFE(valid_mux_id(mux_id));
return mux_graphs_[mux_id];
}
/**************************************************
* Private mutators:
*************************************************/
/* Add a mux to the library */
void MuxLibrary::add_mux(const CircuitLibrary& circuit_lib, const CircuitModelId& circuit_model, const size_t& mux_size) {
/* First, check if there is already an existing graph */
if (valid_mux_size(circuit_model, mux_size)) {
return;
}
/* create a new id for the mux */
MuxId mux = MuxId(mux_ids_.size());
/* Push to the node list */
mux_ids_.push_back(mux);
/* Add a mux graph */
mux_graphs_.push_back(MuxGraph(circuit_lib, circuit_model, mux_size));
/* update mux_lookup*/
mux_lookup_[circuit_model][mux_size] = mux;
}
/**************************************************
* Private accessors: validator and invalidators
*************************************************/
bool MuxLibrary::valid_mux_id(const MuxId& mux) const {
return size_t(mux) < mux_ids_.size() && mux_ids_[mux] == mux;
}
bool MuxLibrary::valid_mux_lookup() const {
return mux_lookup_.empty();
}
bool MuxLibrary::valid_mux_circuit_model_id(const CircuitModelId& circuit_model) const {
MuxLookup::iterator it = mux_lookup_.find(circuit_model);
return (it != mux_lookup_.end());
}
bool MuxLibrary::valid_mux_size(const CircuitModelId& circuit_model, const size_t& mux_size) const {
if (false == valid_mux_circuit_model_id(circuit_model)) {
return false;
}
std::map<size_t, MuxId>::iterator it = mux_lookup_[circuit_model].find(mux_size);
return (it != mux_lookup_[circuit_model].end());
}
/**************************************************
* Private mutators: validator and invalidators
*************************************************/
/* Build fast node lookup */
void MuxLibrary::build_mux_lookup() {
/* Invalidate the mux lookup if necessary */
invalidate_mux_lookup();
}
/* Invalidate (empty) the mux fast lookup*/
void MuxLibrary::invalidate_mux_lookup() {
mux_lookup_.clear();
}
/**************************************************
* End of Member functions for the class MuxLibrary
*************************************************/

View File

@ -0,0 +1,47 @@
/**************************************************
* This file includes a data structure to describe
* the multiplexer implementations in FPGA architectures
* MuxLibrary is a collection of multiplexers
* with various circuit-level description (related to
* the information available in CircuitLibrary
* and the input size of multiplexers)
*************************************************/
#ifndef MUX_LIBRARY_H
#define MUX_LIBRARY_H
#include <map>
#include "mux_graph.h"
#include "mux_library_fwd.h"
class MuxLibrary {
public: /* Public accessors */
/* Get a MUX graph (read-only) */
MuxId mux_graph(const CircuitModelId& circuit_model, const size_t& mux_size) const;
const MuxGraph& mux_graph(const MuxId& mux_id) const;
public: /* Public mutators */
/* Add a mux to the library */
void add_mux(const CircuitLibrary& circuit_lib, const CircuitModelId& circuit_model, const size_t& mux_size);
private: /* Private accessors */
bool valid_mux_id(const MuxId& mux) const;
bool valid_mux_lookup() const;
bool valid_mux_circuit_model_id(const CircuitModelId& circuit_model) const;
bool valid_mux_size(const CircuitModelId& circuit_model, const size_t& mux_size) const;
private: /* Private mutators: mux_lookup */
void build_mux_lookup();
/* Invalidate (empty) the mux fast lookup*/
void invalidate_mux_lookup();
private: /* Internal data */
/* MUX graph-based desription */
vtr::vector<MuxId, MuxId> mux_ids_; /* Unique identifier for each mux graph */
vtr::vector<MuxId, MuxGraph> mux_graphs_; /* Graphs describing MUX internal structures */
/* Local encoder description */
//vtr::vector<MuxLocalDecoderId, Decoder> mux_local_encoders_; /* Graphs describing MUX internal structures */
/* a fast look-up to search mux_graphs with given circuit model and mux size */
typedef std::map<CircuitModelId, std::map<size_t, MuxId>> MuxLookup;
mutable MuxLookup mux_lookup_;
};
#endif

View File

@ -0,0 +1,20 @@
/**************************************************
* This file includes only declarations for
* the data structures to describe multiplexer structures
* Please refer to mux_library.h for more details
*************************************************/
#ifndef MUX_LIBRARY_FWD_H
#define MUX_LIBRARY_FWD_H
#include "vtr_strong_id.h"
/* Strong Ids for MUXes */
struct mux_id_tag;
struct mux_local_decoder_id_tag;
typedef vtr::StrongId<mux_id_tag> MuxId;
typedef vtr::StrongId<mux_local_decoder_id_tag> MuxLocalDecoderId;
class MuxLibrary;
#endif