-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSampling.cpp
More file actions
129 lines (113 loc) · 3.12 KB
/
testSampling.cpp
File metadata and controls
129 lines (113 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "ext-sample/testSampling.h"
#include <cassert>
#include <iostream>
#include "base/abc/abc.h"
#include "ext-sample/SampleCircuit.h"
PatGen::PatGen(Abc_Ntk_t *n, unsigned i) : pNtk(n), nPi(i), cnt(0) {
if (i < 1) return;
Abc_Obj_t *pPo;
int j;
if (i > nBit) {
std::cout << "do not support sampling circuit over " << nBit << " PIs"
<< std::endl;
assert(false);
}
Abc_NtkForEachPo(pNtk, pPo, j) {
Abc_Ntk_t *pPoCone =
Abc_NtkCreateCone(pNtk, Abc_ObjFanin0(pPo), Abc_ObjName(pPo), 0);
if (Abc_ObjFaninC0(pPo)) {
Abc_ObjSetFaninC(Abc_NtkPo(pPoCone, 0), 0);
}
if (Abc_NtkPiNum(pPoCone) < nPi) {
}
SampleCircuit sc(nPi, Abc_NtkPiNum(pPoCone));
std::cout << Abc_NtkPiNum(pPoCone) << std::endl;
if (Abc_NtkPiNum(pPoCone) < nPi) {
sampNtkList.push_back(NULL);
} else {
sampNtkList.push_back(sc.genCircuit(pPoCone));
}
coneList.push_back(pPoCone);
}
// generate sampling circuit
// sc.setRndSeed(7);
}
PatVec PatGen::gen(unsigned index) {
Abc_Obj_t *pObj;
int i;
if (sampNtkList[index] == NULL) {
return randGenPat(Abc_NtkPiNum(pNtk));
}
PatVec ret;
ret.reserve(Abc_NtkPiNum(pNtk));
// generate input patterns
if ((cnt * nBit) >= (1 << nPi)) return randGen(Abc_NtkPiNum(pNtk));
PatVec pv(Abc_NtkPiNum(sampNtkList[index]), 0);
for (unsigned j = 0; j < nBit; ++j) {
size_t a = nBit * cnt + j;
for (unsigned i = 0; i < pv.size(); ++i) {
size_t b = (a >> i) & (size_t)1;
pv[i] |= (b << j);
}
}
cnt += 1;
// for(auto p: pv)
// cout << CeNode::getDXPatStr(make_pair((size_t)0, p)) << endl;
// propagate
simPat(sampNtkList[index], pv);
ret.clear();
unsigned j = 0;
assert(Abc_NtkPoNum(sampNtkList[index]) == Abc_NtkPiNum(coneList[index]));
Abc_NtkForEachPi(pNtk, pObj, i) {
if (strcmp(Abc_ObjName(pObj), Abc_ObjName(Abc_NtkPi(coneList[index], j))) != 0) {
ret.push_back(rng.gen());
continue;
}
ret.push_back(getObjPat(Abc_ObjChild0(Abc_NtkPo(sampNtkList[index], j))));
++j;
}
return ret;
}
SimTest::SimTest(Abc_Ntk_t *ntk, bool x) : pNtk(ntk), xOrSim(x) {
if (xOrSim) {
pGen = new PatGen(pNtk, 10);
cout << "generator done" << endl;
}
}
void SimTest::sim(unsigned iter, unsigned index) {
if (xOrSim) {
PatVec pat = pGen->gen(index);
simPat(pNtk, pat, iter);
} else {
simPat(pNtk, randGenPat(Abc_NtkPiNum(pNtk)), iter);
}
}
void SimTest::SimTestExec() {
Abc_Obj_t *pPo, *pObj;
initPatHistory(pNtk, 100);
int i = 0, j = 0;
pattern_map.clear();
if (!xOrSim) {
for (int i = 0; i < 100; ++i) {
sim(i);
}
} else {
Abc_NtkForEachPo(pNtk, pPo, j) {
sim(i, j);
++i;
if (i == 100) break;
}
}
Abc_AigForEachAnd(pNtk, pObj, j) {
// auto equal_range = pattern_map.equal_range(pObj);
pattern_map.insert(pObj);
}
int total_pairs = 0;
for (int i = 0; i < pattern_map.bucket_count(); ++i) {
if (pattern_map.bucket_size(i) != 0) {
std::cout << pattern_map.bucket_size(i) << std::endl;
}
}
cout << "Total equivalent pair: " << total_pairs << endl;
freePatHistory(pNtk);
}