v1.4: 初步解决了效率问题

This commit is contained in:
YuhangQ 2023-08-14 02:57:32 +00:00
parent c112a34dd6
commit 2dc85e3e88
10 changed files with 64 additions and 640783 deletions

BIN
atpg

Binary file not shown.

2
crun
View File

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

View File

@ -2,17 +2,17 @@
#include "circuit.h" #include "circuit.h"
int LUTCircuit::check() { double LUTCircuit::check() {
// static bool init = 0; // static bool init = 0;
// static std::unordered_set<Gate*> dt; // static std::unordered_set<Gate*> dt;
printf("checking circuit ...\n"); printf("checking circuit ...\n");
int score_value_unsatisfied_cost = 0; double score_value_unsatisfied_cost = 0;
int score_fault_detected_weight = 0; double score_fault_detected_weight = 0;
int score_fault_propagated_weight = 0; double score_fault_propagated_weight = 0;
int score_fault_update_cost = 0; double score_fault_update_cost = 0;
int unsatisfied_lut = 0; int unsatisfied_lut = 0;
for(LUT* lut : luts) { for(LUT* lut : luts) {
@ -55,19 +55,21 @@ int LUTCircuit::check() {
score_fault_detected_weight += t_fd[0] * g->fault_detected_weight[0]; score_fault_detected_weight += t_fd[0] * g->fault_detected_weight[0];
score_fault_detected_weight += t_fd[1] * g->fault_detected_weight[1]; score_fault_detected_weight += t_fd[1] * g->fault_detected_weight[1];
score_fault_propagated_weight += t_fpl[0] * g->fault_propagated_weight[0]; if(!g->isPO) {
score_fault_propagated_weight += t_fpl[1] * g->fault_propagated_weight[1]; score_fault_propagated_weight += (double)t_fpl[0] / g->avg_dist * g->fault_detected_weight[0];
score_fault_propagated_weight += (double)t_fpl[1] / g->avg_dist * g->fault_detected_weight[1];
}
} }
} }
printf("=====================================\n"); printf("=====================================\n");
printf("unsat_lut: %d\n", unsatisfied_lut); printf("unsat_lut: %d\n", unsatisfied_lut);
printf("score_value_unsatisfied_cost: %d\n", score_value_unsatisfied_cost); printf("score_value_unsatisfied_cost: %.2f\n", score_value_unsatisfied_cost);
printf("score_fault_detected_weight: %d\n", score_fault_detected_weight); printf("score_fault_detected_weight: %.2f\n", score_fault_detected_weight);
printf("score_fault_propagated_weight: %d\n", score_fault_propagated_weight); printf("score_fault_propagated_weight: %.2f\n", score_fault_propagated_weight);
printf("score_fault_update_cost: %d\n", score_fault_update_cost); printf("score_fault_update_cost: %.2f\n", score_fault_update_cost);
int score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost; double score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost;
printf("score: %d\n", score); printf("score: %d\n", score);

View File

@ -29,7 +29,7 @@ void ls_random_sol();
void ls_gen_sol(); void ls_gen_sol();
// checker // checker
int check(); double check();
Simulator *simulator; Simulator *simulator;
Circuit *C; Circuit *C;

View File

@ -79,13 +79,13 @@ void LUTCircuit::ls_update(std::vector<LUT*> &unsat) {
} }
// printf("cost: %d add: %d\n", lut->vunat_cost, OPT(vsat_inc)); // printf("cost: %d add: %d\n", lut->vunat_cost, OPT(vsat_inc));
for(LUT* out : lut->fanouts) { // for(LUT* out : lut->fanouts) {
if(out->vunat_cost -= OPT(vsat_inc) > 1) { // if(out->vunat_cost -= OPT(vsat_inc) > 1) {
out->vunat_cost -= OPT(vsat_inc); // out->vunat_cost -= OPT(vsat_inc);
} else { // } else {
out->vunat_cost = 1; // out->vunat_cost = 1;
} // }
} // }
unsat.push_back(lut); unsat.push_back(lut);
} }
@ -201,32 +201,34 @@ void LUTCircuit::ls_gen_sol() {
break; break;
} }
pick->cal_score(); // pick->cal_score();
// int t1 = check(); // double t1 = check();
// printf(">>>>>>>>>>>>>\n"); // printf(">>>>>>>>>>>>>\n");
// printf("dert_score: %d\n", pick->score); // printf("dert_score: %.2f\n", pick->score);
// printf("dert_fault_detected_weight: %d\n", pick->score_fault_detected_weight); // printf("dert_unsat_cost: %.2f\n", pick->score_value_unsatisfied_cost);
// printf("dert_fault_propagated_weight: %d\n", pick->score_fault_propagated_weight); // printf("dert_fault_detected_weight: %.2f\n", pick->score_fault_detected_weight);
// printf("dert_up_cost: %d\n", pick->score_fault_update_cost); // printf("dert_fault_propagated_weight: %.2f\n", pick->score_fault_propagated_weight);
// printf("dert_unsat_cost: %d\n", pick->score_value_unsatisfied_cost); // printf("dert_up_cost: %.2f\n", pick->score_fault_update_cost);
ls_flip(pick); ls_flip(pick);
// int t2 = check(); // double t2 = check();
// assert((t2 - t1) == pick->score); // assert(((t2 - t1) - pick->score) < 1e-6);
if(pick->isPI) { if(pick->isPI) {
int score; int score;
simulator->simulate(PIs, score, fault_detected); simulator->simulate(PIs, score, fault_detected);
// printf("step: %d fd: %d\n", step, score); printf("step: %d fd: %d\n", step, score);
} }
} }
} }
void LUTCircuit::ls_init() { void LUTCircuit::ls_init() {
for(LUT* lut : luts) { for(LUT* lut : luts) {
static int cnt = 0;
printf("[%d/%d]\n", ++cnt, luts.size());
lut->init_lookup_table(); lut->init_lookup_table();
} }
@ -280,6 +282,8 @@ void LUTCircuit::ls_random_sol() {
step = 0; step = 0;
std::vector<int*> t_focus;
for(LUT* lut : luts) { for(LUT* lut : luts) {
lut->up_cost = 1; lut->up_cost = 1;
@ -294,11 +298,22 @@ void LUTCircuit::ls_random_sol() {
g->fault_detected_weight[0] = !fault_detected[g->id-1][0]; g->fault_detected_weight[0] = !fault_detected[g->id-1][0];
g->fault_detected_weight[1] = !fault_detected[g->id-1][1]; g->fault_detected_weight[1] = !fault_detected[g->id-1][1];
if(g->fault_detected_weight[0]) {
t_focus.push_back(&g->fault_detected_weight[0]);
}
if(g->fault_detected_weight[1]) {
t_focus.push_back(&g->fault_detected_weight[1]);
}
g->fault_propagated_weight[0] = !fault_detected[g->id-1][0]; g->fault_propagated_weight[0] = !fault_detected[g->id-1][0];
g->fault_propagated_weight[1] = !fault_detected[g->id-1][1]; g->fault_propagated_weight[1] = !fault_detected[g->id-1][1];
} }
} }
int *tw = t_focus[rand()%t_focus.size()];
*tw = 100000;
for(LUT* lut : luts) { for(LUT* lut : luts) {
lut->uptag = 0; lut->uptag = 0;

View File

@ -62,11 +62,11 @@ public:
void get_fault_info(Gate *gate, int *t_fd, int *t_fpl); void get_fault_info(Gate *gate, int *t_fd, int *t_fpl);
// score // score
int score; double score;
int score_value_unsatisfied_cost; double score_value_unsatisfied_cost;
int score_fault_detected_weight; double score_fault_detected_weight;
int score_fault_propagated_weight; double score_fault_propagated_weight;
int score_fault_update_cost; double score_fault_update_cost;
void cal_score(); void cal_score();
void cal_update(); void cal_update();

View File

@ -29,10 +29,10 @@ int main(int argc, char *argv[]) {
printf("PO:\t%ld\n", circuit->POs.size()); printf("PO:\t%ld\n", circuit->POs.size());
printf("Gate:\t%ld\n", circuit->gates.size()); printf("Gate:\t%ld\n", circuit->gates.size());
printf("LUT:\t%ld\n", C->luts.size()); printf("LUT:\t%ld\n", C->luts.size());
// printf("================================ \n"); printf("================================ \n");
C->print(); // C->print();
C->ls_main(); C->ls_main();
return 0; return 0;

View File

@ -8,7 +8,7 @@
// name, type, short-name,must-need, default ,low, high, comments // name, type, short-name,must-need, default ,low, high, comments
#define PARAS \ #define PARAS \
PARA( seed , int , '\0' , false , 17 , 0 , 100000000 , "max input numbers of LUT") \ PARA( seed , int , '\0' , false , 17 , 0 , 100000000 , "max input numbers of LUT") \
PARA( lut , int , '\0' , false , 8 , 0 , 16 , "max input numbers of LUT") \ PARA( lut , int , '\0' , false , 8 , 0 , 30 , "max input numbers of LUT") \
PARA( sp , double , '\0' , false , 0.01 , 0 , 1 , "max input numbers of LUT") \ PARA( sp , double , '\0' , false , 0.01 , 0 , 1 , "max input numbers of LUT") \
PARA( brk_sp , double , '\0' , false , 0.05 , 0 , 1 , "max input numbers of LUT") \ PARA( brk_sp , double , '\0' , false , 0.05 , 0 , 1 , "max input numbers of LUT") \
PARA( t , int , '\0' , false , 20 , 0 , 1000 , "max input numbers of LUT") \ PARA( t , int , '\0' , false , 20 , 0 , 1000 , "max input numbers of LUT") \

View File

@ -75,8 +75,10 @@ void LUT::cal_score() {
score_fault_detected_weight += (t_fd2[0] - t_fd1[0]) * g->fault_detected_weight[0]; score_fault_detected_weight += (t_fd2[0] - t_fd1[0]) * g->fault_detected_weight[0];
score_fault_detected_weight += (t_fd2[1] - t_fd1[1]) * g->fault_detected_weight[1]; score_fault_detected_weight += (t_fd2[1] - t_fd1[1]) * g->fault_detected_weight[1];
score_fault_propagated_weight += (t_fpl2[0] - t_fpl1[0]) * g->fault_propagated_weight[0]; if(!g->isPO) {
score_fault_propagated_weight += (t_fpl2[1] - t_fpl1[1]) * g->fault_propagated_weight[1]; score_fault_propagated_weight += (double)(t_fpl2[0] - t_fpl1[0]) / g->avg_dist * g->fault_detected_weight[0];
score_fault_propagated_weight += (double)(t_fpl2[1] - t_fpl1[1]) / g->avg_dist * g->fault_detected_weight[1];
}
} }
} }
@ -105,8 +107,10 @@ void LUT::cal_score() {
score_fault_detected_weight += (t_fd2[0] - t_fd1[0]) * g->fault_detected_weight[0]; score_fault_detected_weight += (t_fd2[0] - t_fd1[0]) * g->fault_detected_weight[0];
score_fault_detected_weight += (t_fd2[1] - t_fd1[1]) * g->fault_detected_weight[1]; score_fault_detected_weight += (t_fd2[1] - t_fd1[1]) * g->fault_detected_weight[1];
score_fault_propagated_weight += (t_fpl2[0] - t_fpl1[0]) * g->fault_propagated_weight[0]; if(!g->isPO) {
score_fault_propagated_weight += (t_fpl2[1] - t_fpl1[1]) * g->fault_propagated_weight[1]; score_fault_propagated_weight += (double)(t_fpl2[0] - t_fpl1[0]) / g->avg_dist * g->fault_detected_weight[0];
score_fault_propagated_weight += (double)(t_fpl2[1] - t_fpl1[1]) / g->avg_dist * g->fault_detected_weight[1];
}
} }
// update cost score // update cost score
@ -131,7 +135,5 @@ void LUT::cal_score() {
out->vsat = ( out->cal_value() == out->value ); out->vsat = ( out->cal_value() == out->value );
} }
score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost; score = - score_value_unsatisfied_cost + score_fault_detected_weight + score_fault_propagated_weight - score_fault_update_cost;
} }

640738
test.txt

File diff suppressed because it is too large Load Diff