From 893683fa95ce45a9c716a58f70f3134cb36f8dd3 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Sun, 18 Aug 2019 12:31:59 -0600 Subject: [PATCH] start developing mux library --- vpr7_x2p/vpr/SRC/device/mux_graph.cpp | 28 +++--- vpr7_x2p/vpr/SRC/device/mux_graph.h | 13 +-- vpr7_x2p/vpr/SRC/device/mux_graph_fwd.h | 3 - vpr7_x2p/vpr/SRC/device/mux_library.cpp | 100 ++++++++++++++++++++++ vpr7_x2p/vpr/SRC/device/mux_library.h | 47 ++++++++++ vpr7_x2p/vpr/SRC/device/mux_library_fwd.h | 20 +++++ 6 files changed, 180 insertions(+), 31 deletions(-) create mode 100644 vpr7_x2p/vpr/SRC/device/mux_library.cpp create mode 100644 vpr7_x2p/vpr/SRC/device/mux_library.h create mode 100644 vpr7_x2p/vpr/SRC/device/mux_library_fwd.h diff --git a/vpr7_x2p/vpr/SRC/device/mux_graph.cpp b/vpr7_x2p/vpr/SRC/device/mux_graph.cpp index 6655619c8..69e2da14e 100644 --- a/vpr7_x2p/vpr/SRC/device/mux_graph.cpp +++ b/vpr7_x2p/vpr/SRC/device/mux_graph.cpp @@ -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(); } @@ -487,6 +490,11 @@ void MuxGraph::build_node_lookup() { node_lookup_[node_levels_[node]][size_t(node_types_[node])].push_back(node); } } + +/* 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 - *************************************************/ - diff --git a/vpr7_x2p/vpr/SRC/device/mux_graph.h b/vpr7_x2p/vpr/SRC/device/mux_graph.h index e9dd1e3bc..dad40aaf7 100644 --- a/vpr7_x2p/vpr/SRC/device/mux_graph.h +++ b/vpr7_x2p/vpr/SRC/device/mux_graph.h @@ -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 mux_graphs_; /* Graphs describing MUX internal structures */ - vtr::vector circuit_model_ids_; /* ids in the circuit library, each MUX graph belongs to*/ - /* Local encoder description */ -}; - #endif diff --git a/vpr7_x2p/vpr/SRC/device/mux_graph_fwd.h b/vpr7_x2p/vpr/SRC/device/mux_graph_fwd.h index f4a163bb8..815102e6d 100644 --- a/vpr7_x2p/vpr/SRC/device/mux_graph_fwd.h +++ b/vpr7_x2p/vpr/SRC/device/mux_graph_fwd.h @@ -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 MuxId; typedef vtr::StrongId MuxNodeId; typedef vtr::StrongId MuxEdgeId; typedef vtr::StrongId MuxMemId; typedef vtr::StrongId MuxInputId; class MuxGraph; -class MuxLibrary; #endif diff --git a/vpr7_x2p/vpr/SRC/device/mux_library.cpp b/vpr7_x2p/vpr/SRC/device/mux_library.cpp new file mode 100644 index 000000000..717d1aac7 --- /dev/null +++ b/vpr7_x2p/vpr/SRC/device/mux_library.cpp @@ -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::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 + *************************************************/ + + + diff --git a/vpr7_x2p/vpr/SRC/device/mux_library.h b/vpr7_x2p/vpr/SRC/device/mux_library.h new file mode 100644 index 000000000..3c3b0329a --- /dev/null +++ b/vpr7_x2p/vpr/SRC/device/mux_library.h @@ -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 +#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 mux_ids_; /* Unique identifier for each mux graph */ + vtr::vector mux_graphs_; /* Graphs describing MUX internal structures */ + + /* Local encoder description */ + //vtr::vector 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> MuxLookup; + mutable MuxLookup mux_lookup_; +}; + +#endif diff --git a/vpr7_x2p/vpr/SRC/device/mux_library_fwd.h b/vpr7_x2p/vpr/SRC/device/mux_library_fwd.h new file mode 100644 index 000000000..7bc3091eb --- /dev/null +++ b/vpr7_x2p/vpr/SRC/device/mux_library_fwd.h @@ -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 MuxId; +typedef vtr::StrongId MuxLocalDecoderId; + +class MuxLibrary; + +#endif