From dfec04e653c566f0838e242926492e1ac652288c Mon Sep 17 00:00:00 2001 From: PKU-ZLR <55825746+PKU-ZLR@users.noreply.github.com> Date: Tue, 29 Oct 2019 20:46:10 +0800 Subject: [PATCH] Update MAIN.cpp --- source/MAIN.cpp | 141 +++++++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 54 deletions(-) diff --git a/source/MAIN.cpp b/source/MAIN.cpp index 6bba742..74f1e45 100644 --- a/source/MAIN.cpp +++ b/source/MAIN.cpp @@ -14,10 +14,14 @@ #include #include +#define MAXDEP 100 + using namespace std; FILE *out; +int Luts = 6; map vis; +vector L[MAXDEP]; void get_file_name(string path, vector &files) { struct dirent *ptr; @@ -32,21 +36,26 @@ void get_file_name(string path, vector &files) { bool cmp_Depth(Cut A, Cut B) { return A.mindep < B.mindep || (A.mindep == B.mindep && A.AreaFlow < B.AreaFlow) - || (A.mindep == B.mindep && A.AreaFlow == B.AreaFlow && A.Area < B.Area); + || (A.mindep == B.mindep && A.AreaFlow == B.AreaFlow && A.Area < B.Area); } bool cmp_Depth2(Cut A, Cut B) { return A.mindep < B.mindep || (A.mindep == B.mindep && A.Area < B.Area) - || (A.mindep == B.mindep && A.Area == B.Area && A.AreaFlow < B.AreaFlow); + || (A.mindep == B.mindep && A.Area == B.Area && A.AreaFlow < B.AreaFlow); } void Output(Circuit c) { + map Flag; + Flag.clear(); queue Q; vis.clear(); + for (int i = 0; i < MAXDEP; i++) + L[i].clear(); int area = 0, dep = 0; for (string s : c.output) { Q.push(s); vis[s] = 1; + //L[c.graph[s]->mindep].push_back(s); dep = max(dep, c.graph[s]->mindep); //cout << s << ":" << c.graph[s]->mindep << endl; } @@ -55,36 +64,60 @@ void Output(Circuit c) { Q.pop(); if (c.graph[now]->pre.size() == 0) continue; - fprintf(out, "input:\n"); + L[c.graph[now]->mindep].push_back(now); + //fprintf(out, "input:\n"); //cout << now << ":" << c.graph[now]->mindep << endl; area++; for (string st : c.graph[now]->Rcut) { - fprintf(out, "%s ", st.c_str()); + //fprintf(out, "%s ", st.c_str()); if (!vis[st]) { Q.push(st); vis[st] = 1; } } - fprintf(out, "%s\n", ("\noutput:\n" + now).c_str()); + //fprintf(out, "%s\n", ("\noutput:\n" + now).c_str()); } - - fstream fout("result/overall.txt", ios::app); - fout << c.benchmark << ' ' << area << ' ' << c.abc_lut_area << endl; - fout.close(); + //fprintf(stdout, "Area: %d\nDepth: %d\n", area, dep); + printf("HH\n"); + for (int i = 1; i <= dep; i++) + for (string st1 : L[i]) + for (string st2 : L[i]) { + if (st1 == st2) continue; + if (Flag[st1] || Flag[st2]) continue; + set s1 = c.graph[st1]->Rcut; + set s2 = c.graph[st2]->Rcut; + set st = s1; + st.insert(s2.begin(), s2.end()); + if (st.size() < (unsigned)Luts) { + Flag[st1] = 1, Flag[st2] = 1; + fprintf(out, "input:\n"); + for (string str : st) + fprintf(out, "%s ", str.c_str()); + fprintf(out, "%s\n", ("\noutput:\n" + st1 + " " + st2).c_str()); + } + } + for (int i = 1; i <= dep; i++) { + for (string st : L[i]) + if (!Flag[st]) { + fprintf(out, "input:\n"); + for (string str : c.graph[st]->Rcut) + fprintf(out, "%s ", str.c_str()); + fprintf(out, "%s\n", ("\noutput:\n" + st).c_str()); + } + } + } - int main(int argc, char *argv[]) { vector benchmark; queue Q; map ind; - int Luts = 6; unsigned int C = 15; // record the most C Cuts string dir = "benchmark/ISCAS85"; string outdir = "result/ISCAS85"; get_file_name(dir, benchmark); for (string str : benchmark) { - cout << str << endl; + cout << str << endl; double total_time; clock_t start = clock(); @@ -95,8 +128,8 @@ int main(int argc, char *argv[]) { for (pair p : c.graph) { ind[p.first] = p.second->pre.size(); - p.second->mindep = 0; - } + p.second->mindep = 0; + } for (string s : c.input) { // Initial queue c.graph[s]->cuts[1].insert(set { s }); @@ -120,22 +153,22 @@ int main(int argc, char *argv[]) { if (c.graph[now]->pre.size() == 2) { string input1 = c.graph[now]->pre[0]; string input2 = c.graph[now]->pre[1]; - for (int t = 1; t <= Luts; t++) - for (set c1 : c.graph[input1]->cuts[t]) { - for (int k = 1; k <= Luts; k++) - for (set c2 : c.graph[input2]->cuts[k]) { + for (int t = 1; t <= Luts; t++) + for (set c1 : c.graph[input1]->cuts[t]) { + for (int k = 1; k <= Luts; k++) + for (set c2 : c.graph[input2]->cuts[k]) { set st = c1; st.insert(c2.begin(), c2.end()); if (st.size() > (unsigned) Luts) continue; c.graph[now]->cuts[st.size()].insert(st); } - } + } } if (c.graph[now]->pre.size() == 1) { string input1 = c.graph[now]->pre[0]; - for (int k = 1; k <= Luts; k++) + for (int k = 1; k <= Luts; k++) for (set c1 : c.graph[input1]->cuts[k]) c.graph[now]->cuts[k].insert(c1); } @@ -151,8 +184,8 @@ int main(int argc, char *argv[]) { c.graph[now]->mindep = INF; c.graph[now]->Area = INF; c.graph[now]->AreaFlow = inf; - for (int k = 1; k <= Luts; k++) - for (set ct : c.graph[now]->cuts[k]) { + for (int k = 1; k <= Luts; k++) + for (set ct : c.graph[now]->cuts[k]) { int dep = 0, area = 0; double AF = 0; for (string nt : ct) { @@ -164,52 +197,52 @@ int main(int argc, char *argv[]) { AF /= max(1.0, 1.0 * c.graph[now]->suc.size()); Cuts[k].push_back(Cut(ct, dep, area, AF)); - Ct.push_back(Cut(ct, dep, area, AF)); - /*Compare dep*/ - /*if (dep < c.graph[now]->mindep) { - c.graph[now]->mindep = dep; - c.graph[now]->AreaFlow = AF; - c.graph[now]->Area = area; - c.graph[now]->Rcut = ct; - continue; - }*/ + Ct.push_back(Cut(ct, dep, area, AF)); + /*Compare dep*/ + /*if (dep < c.graph[now]->mindep) { + c.graph[now]->mindep = dep; + c.graph[now]->AreaFlow = AF; + c.graph[now]->Area = area; + c.graph[now]->Rcut = ct; + continue; + }*/ - /*Compare Area Flow*/ - /*if (dep == c.graph[now]->mindep && AF < c.graph[now]->AreaFlow) { - c.graph[now]->mindep = dep; - c.graph[now]->AreaFlow = AF; - c.graph[now]->Area = area; - c.graph[now]->Rcut = ct; - continue; - }*/ + /*Compare Area Flow*/ + /*if (dep == c.graph[now]->mindep && AF < c.graph[now]->AreaFlow) { + c.graph[now]->mindep = dep; + c.graph[now]->AreaFlow = AF; + c.graph[now]->Area = area; + c.graph[now]->Rcut = ct; + continue; + }*/ - /*Compare Area*/ - /*if (dep == c.graph[now]->mindep && AF == c.graph[now]->AreaFlow && area < c.graph[now]->Area) { - c.graph[now]->mindep = dep; - c.graph[now]->AreaFlow = AF; - c.graph[now]->Area = area; - c.graph[now]->Rcut = ct; - continue; - }*/ + /*Compare Area*/ + /*if (dep == c.graph[now]->mindep && AF == c.graph[now]->AreaFlow && area < c.graph[now]->Area) { + c.graph[now]->mindep = dep; + c.graph[now]->AreaFlow = AF; + c.graph[now]->Area = area; + c.graph[now]->Rcut = ct; + continue; + }*/ - } - //if (now == "G473") + } + //if (now == "G473") // cout << Cuts.size() << endl; for (int k = 1; k <= Luts; k++) { sort(Cuts[k].begin(), Cuts[k].end(), cmp_Depth2); c.graph[now]->cuts[k].clear(); unsigned int len = Cuts[k].size(); - //cout << "now:" << now << endl; + //cout << "now:" << now << endl; for (unsigned int i = 0; i < min(C, len); i++) { c.graph[now]->cuts[k].insert(Cuts[k][i].names); - //cout << Cuts[i].mindep << endl; + //cout << Cuts[i].mindep << endl; } } //if (c.graph[now]->pre.size() != 1) c.graph[now]->cuts[1].insert(set { now }); /*for (string s : Cuts[0].names) - cout << s << endl;*/ - sort(Ct.begin(), Ct.end(), cmp_Depth2); + cout << s << endl;*/ + sort(Ct.begin(), Ct.end(), cmp_Depth2); c.graph[now]->mindep = Ct[0].mindep; c.graph[now]->AreaFlow = Ct[0].AreaFlow; c.graph[now]->Area = Ct[0].Area; @@ -217,7 +250,7 @@ int main(int argc, char *argv[]) { //cout << c.graph[now]->mindep << endl; } Output(c); - //cout << c.abc_lut_area << endl; + //cout << c.abc_lut_area << endl; clock_t finish = clock(); total_time = (double) (finish - start) / CLOCKS_PER_SEC; cout << "Run time: " << total_time << "s" << endl;