Skip to content

Commit 2458743

Browse files
Merge branch 'master' of github.com:highperformancecoder/ecolab
2 parents 1566333 + a226650 commit 2458743

4 files changed

Lines changed: 43 additions & 12 deletions

File tree

models/abc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace ecolab {
101101
assert(numOutputs()==1);
102102
std::vector<I> workspace(Abc_NtkObjNumMax(aig));
103103
for (unsigned i=0; i<numInputs(); ++i)
104-
workspace[abc::Abc_ObjId(&input(i))]=input[i];
104+
workspace[abc::Abc_ObjId(&this->input(i))]=input[i];
105105
AbcNodes orderedNodes(aig);
106106
for (auto obj: orderedNodes)
107107
if (obj)
@@ -113,7 +113,7 @@ namespace ecolab {
113113
if (abc::Abc_ObjFaninC1(obj)) v1 = ~v1;
114114
workspace[abc::Abc_ObjId(obj)] = v0 & v1;
115115
}
116-
auto r=workspace[abc::Abc_ObjId(&output(0))];
116+
auto r=workspace[abc::Abc_ObjFaninId0(&output(0))];
117117
return abc::Abc_ObjFaninC0(&output(0))? ~r: r;
118118
}
119119
};

models/starComplexity.cc

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,12 @@ unsigned StarComplexityGen::starUpperBound(const linkRep& x) const
697697
return min(ub, complementUb);
698698
}
699699

700-
unsigned StarComplexityGen::starUpperBoundABC(linkRep x) const
700+
unsigned starUpperBoundABC(linkRep x, const ElemStars& elemStars)
701701
{
702702
if (x.empty()) return 3; // intersection of 3 stars is empty.
703703
// Firstly remove those nodes that are full stars
704704
vector<unsigned> fullStars;
705-
const unsigned nodes=elemStars.size();
705+
unsigned nodes=elemStars.size();
706706
for (unsigned i=0; i<nodes; ++i)
707707
{
708708
bool fullStar=true;
@@ -719,7 +719,7 @@ unsigned StarComplexityGen::starUpperBoundABC(linkRep x) const
719719

720720
AIG aig;
721721
// build the remaining edges into an AIG
722-
aig.setInputs(elemStars.size());
722+
aig.setInputs(nodes);
723723
vector<abc::Abc_Obj_t*> edges;
724724
for (unsigned i=0; i<nodes; ++i)
725725
for (unsigned j=0; j<i; ++j)
@@ -728,19 +728,40 @@ unsigned StarComplexityGen::starUpperBoundABC(linkRep x) const
728728
abc::Abc_Obj_t* graphRemainder=edges[0];
729729
for (size_t i=1; i<edges.size(); ++i)
730730
graphRemainder=&aig.addOr(*graphRemainder, *edges[i]);
731+
assert(aig.numGates()==2*edges.size()-1);
731732
aig.addOutputs(*graphRemainder);
733+
assert(aig.eval(elemStars)==x);
732734
aig.cleanup();
733-
for (unsigned i=0; i<3; ++i)
735+
assert(aig.eval(elemStars)==x);
736+
for (unsigned i=0; i<100; ++i)
734737
{
738+
auto prevNumGates=aig.numGates();
739+
for (unsigned i=0; i<3; ++i)
740+
{
741+
aig.balance();
742+
assert(aig.eval(elemStars)==x);
743+
aig.rewrite();
744+
assert(aig.eval(elemStars)==x);
745+
aig.refactor();
746+
assert(aig.eval(elemStars)==x);
747+
}
735748
aig.balance();
736-
aig.rewrite();
737-
aig.refactor();
749+
assert(aig.eval(elemStars)==x);
750+
aig.rewrite(true); // final zero-cost pass
751+
assert(aig.eval(elemStars)==x);
752+
if (aig.numGates()==prevNumGates) break; // terminate on no improvement
738753
}
739-
aig.balance();
740-
aig.rewrite(true); // final zero-cost pass
741754
return fullStars.size()+aig.numGates()+1;
742755
}
743756

757+
unsigned StarComplexityGen::starUpperBoundABC(const linkRep& x) const
758+
{
759+
unsigned ub=::starUpperBoundABC(x, elemStars);
760+
unsigned complementUb=::starUpperBoundABC((~x).maskOut(elemStars.size()), elemStars);
761+
assert(ub>0 && complementUb>0);
762+
return min(ub, complementUb);
763+
}
764+
744765
GraphComplexity StarComplexityGen::randomERGraph(unsigned nodes, unsigned links)
745766
{
746767
linkRep g=0;

models/starComplexity.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ class linkRepImpl
8989
}
9090
};
9191

92+
template <class I>
93+
std::ostream& operator<<(std::ostream& o, const linkRepImpl<I>& x)
94+
{
95+
auto d=x.dataAsVector();
96+
o<<"[";
97+
for (auto& i:d) o<<i<<",";
98+
o<<"]";
99+
return o;
100+
}
101+
92102
//#ifdef SYCL_LANGUAGE_VERSION
93103
//using linkRep=linkRepImpl<VecBitSet<unsigned,4>>;
94104
//#else
@@ -159,7 +169,7 @@ struct StarComplexityGen
159169
/// return an upper bound on the number of stars in the link representation
160170
unsigned starUpperBound(const linkRep&) const;
161171
/// star upper bound using ABC library
162-
unsigned starUpperBoundABC(linkRep) const;
172+
unsigned starUpperBoundABC(const linkRep&) const;
163173

164174
/// random number generator
165175
ecolab::urand uni;

models/starComplexity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
maxStars=max(maxStars,v)
1313

1414
print('maxStars=',maxStars)
15-
maxStars=10
15+
maxStars=9
1616

1717
#starC.blockSize(256)
1818
starC.blockSize(4096)

0 commit comments

Comments
 (0)