Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: prelim cutset based remap #5597

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/rmp/include/rmp/FuncExpr2Kit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <sta/FuncExpr.hh>
#include <sta/StringUtil.hh>
#include <sta/Liberty.hh>
#include <sta/Network.hh>


namespace sta {

class FuncExpr2Kit {
public:
FuncExpr2Kit(FuncExpr* fe, int& var_count, unsigned *&kit_tables);
void RecursivelyEvaluate(FuncExpr* fe, unsigned*);
private:
std::map<LibertyPort*, unsigned*> kit_vars_; //pointer (not name) addressed.
std::map<int,LibertyPort*> lib_ports_;
int var_count_;
};

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: namespace 'sta' not terminated with a closing comment [google-readability-namespace-comments]

Suggested change
}
} // namespace sta
Additional context

src/rmp/include/rmp/FuncExpr2Kit.h:7: namespace 'sta' starts here

namespace sta {
          ^

219 changes: 218 additions & 1 deletion src/rmp/include/rmp/Restructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#include "rsz/Resizer.hh"

namespace abc {
struct Abc_Obj_t_;
struct Abc_Ntk_t_;
struct Amap_Lib_t_;
struct Amap_Par_t_;
extern Abc_Ntk_t_* Abc_NtkDarAmap(Abc_Ntk_t_*, Amap_Par_t_*);
} // namespace abc

namespace utl {
Expand All @@ -57,11 +62,180 @@ class dbITerm;
} // namespace odb

namespace sta {
class dbSta;
class dbSta;
class Network;
class Vertex;
class LibertyBuilder;
} // namespace sta

namespace rmp {


//Cut resynthesis stuff +++


//Cut: Region of network to optimize. File Cut.cpp
struct Cut {
std::vector<sta::Pin*> roots_;
std::vector<sta::Pin*> leaves_;
std::vector<sta::Instance*> volume_;
std::map<const sta::Pin*,sta::LibertyPort*> internal_pins_;
int id_;
sta::LibertyCell* cut_cell_;
void Print(sta::Network* nwk);
bool Check(sta::Network* nwk);
bool LeafPin(const sta::Pin* cur_pin);

};



class CutGen { //File CutGen.cpp
public:
using expansionSet=std::vector<std::pair<std::vector<const sta::Pin*>, std::vector<const sta::Pin*> > >;
CutGen(sta::Network* nwk, sta::LibertyLibrary* liberty_lib):
network_(nwk),liberty_lib_(liberty_lib){}

void GenerateInstanceWaveFrontCutSet(sta::Instance*,std::vector<Cut*>&);
bool EnumerateExpansions(std::vector<const sta::Pin*>& candidate_wavefront,
expansionSet& expansion_set);
Cut* BuildCutFromExpansionElement(sta::Instance* cur_inst,
const sta::Pin* root_pin,
std::vector<const sta::Pin*>& keep, //set of pins to keep
std::vector<const sta::Pin*>& expand);
bool Boundary(const sta::Pin* cur_pin);
const sta::Pin* WalkThroughBuffersAndInverters(Cut*,
const sta::Pin* op_pin,
std::set<const sta::Pin*>& unique_set);
private:
sta::Network* network_;
sta::LibertyLibrary* liberty_lib_;
};



//Library reader. File LibRead.cpp
class LibRead{
public:
LibRead(utl::Logger* logger, char* lib_file_name,bool verbose);

private:
utl::Logger* logger_;
char* lib_file_name_;
bool verbose_;
abc::Amap_Lib_t_ *lib_;
friend class PhysRemap;
};


//STA -> ABC
//
//file Cut2Ntk.cpp
//
class Cut2Ntk {
public:
Cut2Ntk(utl::Logger* logger,
sta::Network* nwk,
Cut* cut,
std::string cut_name):
logger_(logger),
sta_nwk_(nwk),
cut_(cut),
cut_name_(cut_name){}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'cut_name' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param]

src/rmp/include/rmp/Restructure.h:39:

+ #include <utility>
Suggested change
cut_name_(cut_name){}
cut_name_(std::move(cut_name)){}

abc::Abc_Ntk_t_* BuildSopLogicNetlist();
abc::Abc_Obj_t_* CreateGate(const sta::Instance* cur_inst);
void CleanUpNetNets();
private:
utl::Logger* logger_;
sta::Network* sta_nwk_;
Cut* cut_;
std::string cut_name_;
abc::Abc_Ntk_t_* abc_nwk_;
//cross reference dictionaries for ease of constraining.
std::map<const sta::Pin*, abc::Abc_Obj_t_*> pi_table_;
std::map<const sta::Pin*, abc::Abc_Obj_t_*> po_table_;
std::map<const sta::Pin*, abc::Abc_Obj_t_*> net_table_sta2abc_; //sta -> abc
std::map<abc::Abc_Obj_t_*, const sta::Pin*> net_table_abc2sta_; //abc -> sta.
friend class Restructure;
};


//ABC -> STA
//file Ntk2Cut.cpp
class Ntk2Cut {
public:
Ntk2Cut(abc::Abc_Ntk_t_*, Cut*, sta::Network*);
void BuildNwkElements();
private:
abc::Abc_Ntk_t_* mapped_netlist_;
Cut* cut_;
sta::Network* target_nwk_;
};

//Timing record for constraining abc.
struct TimingRecord {
float required_rise;
float required_fall;
float arrival_rise;
float arrival_fall;
float load;
} ;


//Remap a cut
//File: PhysRemap.cpp
class PhysRemap{
public:
PhysRemap(utl::Logger* logger,
sta::Network* nwk,
Cut* cut_to_remap,
std::vector<std::pair<const sta::Pin*, TimingRecord*> > & timing_requirements,
char* lib_name,
LibRead& lib_file,
bool script,
std::string &script_to_apply,
bool accept
):logger_(logger),
nwk_(nwk),
cut_(cut_to_remap),
timing_requirements_(timing_requirements),
lib_name_(lib_name),
liberty_library_(lib_file.lib_),
script_(script),
script_to_apply_(script_to_apply),
accept_(accept)
{
cut_name_ = "cut_" + std::to_string(cut_to_remap -> id_);
global_optimize_ = false;
verbose_=true;
}
void Remap();
void AnnotateTimingRequirementsOntoABCNwk(abc::Abc_Ntk_t_* sop_logic_nwk);
bool getAbcResult(abc::Abc_Ntk_t_*&);
void BuildCutRealization(abc::Abc_Ntk_t_*);
float TimingGain();

private:
utl::Logger* logger_;
sta::Network* nwk_;

Cut* cut_;
std::vector<std::pair<const sta::Pin*, TimingRecord*> > & timing_requirements_;
char* lib_name_;
std::string cut_name_;
abc::Amap_Lib_t_* liberty_library_;
bool global_optimize_;
bool verbose_;
bool script_;
std::string script_to_apply_;
bool accept_;
abc::Abc_Ntk_t_* intermediate_result_;
friend class Restructure;
};
//Cut resynthesis ----



using utl::Logger;

enum class Mode
Expand Down Expand Up @@ -96,6 +270,49 @@ class Restructure
void setTieLoPort(sta::LibertyPort* loport);
void setTieHiPort(sta::LibertyPort* hiport);

//Cut based resynthesis methods

void cutresynthrun(char* liberty_file_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'rmp::Restructure::cutresynthrun' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]

  void cutresynthrun(char* liberty_file_name,
       ^
Additional context

src/rmp/src/Restructure.cpp:696: the definition seen here

void Restructure::cutresynthrun(
                  ^

src/rmp/include/rmp/Restructure.h:274: differing parameters are named here: ('liberty_file_name'), in definition: ('target_library')

  void cutresynthrun(char* liberty_file_name,
       ^

char* script,
sta::Pin* head_pin, //if null we do the big blob, if set we do single op
bool unconstrained,
bool verbose);

void annotateCutTiming(Cut*, std::vector<std::pair<const sta::Pin*, TimingRecord*> >& timing_requirements);

//Various cut generation methods
//The default: big cut like a blob
void generateUnconstrainedCuts(std::vector<Cut*>& cut_set);
//Focussed: use wavefront cut
void generateWaveFrontSingleOpCutSet(sta::Network* nwk,
sta::Pin* root,
std::vector<Cut*>& cut_set);
void generateWaveFrontSingleOpCutSet(sta::Network* nwk,
sta::Instance* root,
std::vector<Cut*>& cut_set);


static bool isRegInput(sta::Network* nwk, sta::Vertex* vertex);
static bool isRegOutput(sta::Network* nwk, sta::Vertex* vertex);
static bool isPrimary(sta::Network* nwk, sta::Vertex* vertex);
void ResetCutTemporaries(){ leaves_.clear(); roots_.clear(); cut_volume_.clear();ordered_leaves_.clear();ordered_roots_.clear(); pin_visited_.clear();}
void AmendCutForEscapeLeaves(sta::Network* nwk);

//privates for cut based resynthesis
private:
//These are used for the blob/cut generation
std::set<sta::Vertex*> end_points_; //full set of end points
std::map<sta::Pin*,int> leaves_;
std::map<sta::Pin*,int> roots_;
std::set<sta::Instance*> cut_volume_;
std::set<sta::Pin*> pin_visited_;
std::vector<sta::Pin*> ordered_leaves_;
std::vector<sta::Pin*> ordered_roots_;
Cut* extractCut(int cut_id);
void walkBackwardsToTimingEndPointsR(sta::Graph* graph, sta::Network* nwk, sta::Pin* start_pin, int depth);
void walkForwardsToTimingEndPointsR(sta::Graph* graph, sta::Network* nwk, sta::Pin* start_pin, int depth);


private:
void deleteComponents();
void getBlob(unsigned max_depth);
Expand Down
7 changes: 7 additions & 0 deletions src/rmp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ target_sources(rmp
blifParser.cpp
blif.cpp
Restructure.cpp
Cut.cpp
CutGen.cpp
FuncExpr2Kit.cpp
LibRead.cpp
Ntk2Cut.cpp
Cut2Ntk.cpp
MakeRestructure.cpp
PhysRemap.cpp
)

messages(
Expand Down
Loading
Loading