比较高效的分数计算

This commit is contained in:
YuhangQ 2023-07-18 10:52:51 +00:00
parent b4916a2a9b
commit 4aa1c086b7
9 changed files with 126 additions and 20534 deletions

View File

@ -1,20 +0,0 @@
cmake_minimum_required(VERSION 3.0)
project(atpg)
set(CMAKE_CXX_STANDARD 17)
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
#
aux_source_directory(${PROJECT_SOURCE_DIR}/src SOURCES)
set(INCLUDES ${PROJECT_SOURCE_DIR}/src)
message(${SOURCES})
#
add_executable(${PROJECT_NAME} ${SOURCES})
#
include_directories(${INCLUDES})

BIN
atpg

Binary file not shown.

19341
b17.txt

File diff suppressed because one or more lines are too long

2
crun
View File

@ -10,6 +10,6 @@ if [ $? -ne 0 ]; then
else else
clear clear
echo "========================" echo "========================"
time ./atpg -i $1 --lut 8 time ./atpg -i $1 --lut 4
fi fi

1152
otuput.txt

File diff suppressed because it is too large Load Diff

View File

@ -23,10 +23,16 @@ void LUTCircuit::ls_flip(LUT *lut) {
} }
} }
// lut->cal_score(); lut->cal_score();
// for(LUT* r : lut->reigon) { for(LUT* r : lut->reigon) {
// r->cal_score(); r->cal_score();
// } }
for(LUT* r : lut->fanouts) {
r->cal_score();
}
for(LUT* r : lut->update_reigon) {
r->cal_update();
}
} }
void LUTCircuit::ls_main() { void LUTCircuit::ls_main() {
@ -63,6 +69,26 @@ void LUTCircuit::ls_main() {
} }
} }
for(LUT* lut : luts) {
std::set<LUT*> t_reigon;
for(LUT* r: lut->reigon) {
t_reigon.insert(r);
for(LUT* out2 : r->fanouts) {
t_reigon.insert(out2);
for(LUT* in2 : out2->fanins) {
t_reigon.insert(in2);
}
}
}
for(LUT* r : lut->fanouts) {
t_reigon.insert(r);
}
for(LUT* r : t_reigon) {
lut->update_reigon.push_back(r);
}
printf("rg: %d %d\n", lut->reigon.size(), lut->update_reigon.size());
}
printf("generating initial solution ...\n"); printf("generating initial solution ...\n");
for(LUT* lut : luts) { for(LUT* lut : luts) {
@ -89,36 +115,44 @@ void LUTCircuit::ls_main() {
lut->cal_fault_info(lut->fd, lut->fpl); lut->cal_fault_info(lut->fd, lut->fpl);
} }
// for(LUT* lut : luts) { for(LUT* lut : luts) {
// lut->cal_score(); lut->cal_score();
// } }
print(); print();
int seed = time(0); int seed = time(0);
srand(seed); srand(1689658115);
int t1 = check(); int T = 10000;
while(T--) {
if(T % 1000 == 0) {
printf("T: %d\n", T);
}
// int t1 = check();
// print(); // print();
LUT* pick = luts[rand() % luts.size()]; LUT* pick = luts[rand() % luts.size()];
pick->cal_score(); // pick->cal_score();
printf(">>>> flip: %s\n", pick->name); // printf(">>>> flip: %s\n", pick->name);
int s = pick->score; // int s = pick->score;
printf("##### score: %d seed: %d\n", pick->score, seed); // printf("##### score: %d seed: %d\n", pick->score, seed);
printf("vusat_cost: %d fdw: %d fplw: %d up: %d\n", pick->score_value_unsatisfied_cost, pick->score_fault_detected_weight, pick->score_fault_propagated_weight, pick->score_fault_update_cost); // printf("vusat_cost: %d fdw: %d fplw: %d up: %d\n", pick->score_value_unsatisfied_cost, pick->score_fault_detected_weight, pick->score_fault_propagated_weight, pick->score_fault_update_cost);
ls_flip(pick); ls_flip(pick);
int t2 = check(); // int t2 = check();
// print(); // print();
assert(s == (t2 - t1)); // assert(s == (t2 - t1));
}
// print(); // print();
// exit(0); // exit(0);

View File

@ -3,6 +3,10 @@
#include "lut.h" #include "lut.h"
#include "paras.h" #include "paras.h"
void LUT::get_fault_info(Gate* gate, int *t_fd, int* t_fpl) {
}
void LUT::cal_fault_info(int *fd, int* fpl) { void LUT::cal_fault_info(int *fd, int* fpl) {
fd[0] = fd[1] = fpl[0] = fpl[1] = 0; fd[0] = fd[1] = fpl[0] = fpl[1] = 0;

View File

@ -14,10 +14,16 @@ public:
std::vector<LUT*> fanouts; std::vector<LUT*> fanouts;
std::vector<LUT*> reigon; std::vector<LUT*> reigon;
std::vector<LUT*> update_reigon;
std::vector<LUT*> add_update_to_this;
std::vector<Gate*> inner_gates; std::vector<Gate*> inner_gates;
std::vector<Gate*> __gate_fanins; std::vector<Gate*> __gate_fanins;
std::unordered_map<Gate*, int> input_id;
int& value; int& value;
const char* name; const char* name;
@ -30,6 +36,8 @@ public:
std::vector<FaultInfo*> fault_info; std::vector<FaultInfo*> fault_info;
std::unordered_set<LUT*> update_luts;
void init_lookup_table(); void init_lookup_table();
// local search // local search
@ -41,6 +49,7 @@ public:
int cal_value(); int cal_value();
void cal_fault_info(int *t_fd, int* t_fpl); void cal_fault_info(int *t_fd, int* t_fpl);
void get_fault_info(Gate* gate, int *t_fd, int* t_fpl);
// score // score
int score; int score;
@ -50,6 +59,7 @@ public:
int score_fault_update_cost; int score_fault_update_cost;
void cal_score(); void cal_score();
void cal_update();
}; };

View File

@ -1,6 +1,65 @@
#include "lut.h" #include "lut.h"
void LUT::cal_update() {
score_fault_update_cost = 0;
value = !value;
if(uptag) {
score_fault_update_cost -= up_cost;
}
// value sat score
if(!isPI) {
vsat = !vsat;
}
for(LUT* out : fanouts) {
out->vsat = ( out->cal_value() == out->value );
}
int old_fd[2], old_fpl[2];
old_fd[0] = fd[0];
old_fd[1] = fd[1];
old_fpl[0] = fpl[0];
old_fpl[1] = fpl[1];
// fault detected score
cal_fault_info(fd, fpl);
// update cost score
for(LUT* r : reigon) {
int t_fd[2], t_fpl[2];
r->cal_fault_info(t_fd, t_fpl);
if(t_fd[0] == r->fd[0] && t_fd[1] == r->fd[1] && t_fpl[0] == r->fpl[0] && t_fpl[1] == r->fpl[1]) continue;
if(!r->uptag) {
score_fault_update_cost += r->up_cost;
}
}
value = !value;
if(!isPI) vsat = !vsat;
fd[0] = old_fd[0];
fd[1] = old_fd[1];
fpl[0] = old_fpl[0];
fpl[1] = old_fpl[1];
for(LUT* out : fanouts) {
out->vsat = ( out->cal_value() == out->value );
}
score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost;
}
void LUT::cal_score() { void LUT::cal_score() {
update_luts.clear();
score = 0; score = 0;
score_value_unsatisfied_cost = 0; score_value_unsatisfied_cost = 0;
@ -8,8 +67,6 @@ void LUT::cal_score() {
score_fault_propagated_weight = 0; score_fault_propagated_weight = 0;
score_fault_update_cost = 0; score_fault_update_cost = 0;
// printf("old_fd: %d %d\n", old_fd[0], old_fd[1]); // printf("old_fd: %d %d\n", old_fd[0], old_fd[1]);
value = !value; value = !value;
@ -90,8 +147,6 @@ void LUT::cal_score() {
} }
} }
int in1 = 0, in2 = 0; int in1 = 0, in2 = 0;
for(int i=0; i<fanins.size(); i++) { for(int i=0; i<fanins.size(); i++) {
in1 |= (fanins[i]->value << i); in1 |= (fanins[i]->value << i);
@ -133,6 +188,8 @@ void LUT::cal_score() {
if(!r->uptag) { if(!r->uptag) {
score_fault_update_cost += r->up_cost; score_fault_update_cost += r->up_cost;
update_luts.insert(r);
r->add_update_to_this.push_back(this);
} }
} }