Commit 947c1636 by chengshuyao

Release For Switch Layer Test

parent 888652cb
......@@ -32,7 +32,7 @@ using namespace std;
//电路的parameter Circuit_parameter
int circuit_index = 9999; //电路编号
int parameter_max_orders = 4;
int parameter_max_orders = 8;
......@@ -159,12 +159,12 @@ int search_partition(int start_order_depth, int* start_order){
}
int area=0;;
int* start_order_a = new int [parameter_input_bit_width];
int* start_order_b = new int [parameter_input_bit_width];
for(int i=0;i<parameter_input_bit_width;i++){
start_order_a[i] = 0;
start_order_b[i] = 0;
}
// int* start_order_a = new int [parameter_input_bit_width];
// int* start_order_b = new int [parameter_input_bit_width];
// for(int i=0;i<parameter_input_bit_width;i++){
// start_order_a[i] = 0;
// start_order_b[i] = 0;
// }
int area_a = search_order(10,output_partition_set_a,start_order_depth,start_order);
int area_b = search_order(10,output_partition_set_b,start_order_depth,start_order);
area = area_a + area_b;
......@@ -177,8 +177,8 @@ int search_partition(int start_order_depth, int* start_order){
best_output_partition_set_b[i]=output_partition_set_b[i];
}
for (int i=0;i<parameter_input_bit_width;i++){
best_start_order_a[i]=start_order_a[i];
best_start_order_b[i]=start_order_b[i];
best_start_order_a[i]=start_order[i];
best_start_order_b[i]=start_order[i];
}
}
cout<<"###########################################################################"<<endl;
......@@ -187,13 +187,13 @@ int search_partition(int start_order_depth, int* start_order){
cout<<"###########################################################################"<<endl;
delete [] output_partition_set_a;
delete [] output_partition_set_b;
delete [] start_order_a;
delete [] start_order_b;
// delete [] start_order_a;
// delete [] start_order_b;
}
parameter_max_orders *= 2;
int area=0;
int area_a = search_order(200,best_output_partition_set_a,parameter_input_bit_width,best_start_order_a);
int area_b = search_order(200,best_output_partition_set_b,parameter_input_bit_width,best_start_order_b);
int area_a = search_order(40,best_output_partition_set_a,parameter_input_bit_width,best_start_order_a);
int area_b = search_order(40,best_output_partition_set_b,parameter_input_bit_width,best_start_order_b);
area = area_a + area_b;
cout<<"###########################################################################"<<endl;
......@@ -418,9 +418,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
cout<<endl;
int order_num = gen()%parameter_max_orders;
if(gen()%3==0){
order_num = best_order_num;
}
//int best_reward_tmp = 0;
//int max_best_order = 0;
//for(int zi=0;zi<parameter_max_orders;zi++){
// if(best_rewards[zi] > best_reward_tmp){
// best_reward_tmp = best_rewards[zi];
// max_best_order = zi;
// }
//}
//if(gen()%4==0){
// order_num = max_best_order;
//}
//if(i<100)
// learning_rate= int((100-i)/10);
//else
......@@ -434,18 +443,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
vv=0;
}else{
best_area_depth = best_area_depths[vv];
for(int vi=1;vi<best_area_depth;vi++){
if( (gen()%int(1+best_area_depth)==0)){
int vii = vi-1;
int x = variable_order[vv][vi];
variable_order[vv][vi] = variable_order[vv][vii];
variable_order[vv][vii] = x;
//double y = variable_features[vi];
//variable_features[vi] = variable_features[vii];
//variable_features[vii] = y;
break;
}
}
//for(int vi=1;vi<best_area_depth;vi++){
// if( (gen()%int(1+best_area_depth)==0)){
// int vii = vi-1;
// int x = variable_order[vv][vi];
// variable_order[vv][vi] = variable_order[vv][vii];
// variable_order[vv][vii] = x;
// //double y = variable_features[vi];
// //variable_features[vi] = variable_features[vii];
// //variable_features[vii] = y;
// break;
// }
//}
int num_a = gen()%int(1+best_area_depth/2);
//int num_b = gen()%int(1+best_area_depth/4);
int num_c = 1+gen()%int(1+best_area_depth/4);
......@@ -453,13 +462,13 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
cout<<"num_a: "<<num_a<<" num_b: "<<num_b<<" num_c: "<<num_c<<endl;
for(int vc=0;vc<num_c;vc++){
int x = variable_order[vv][num_a];
for (int vj=0;vj<num_b+num_c;vj++){
if( (vj==(num_b+num_c-1))){
variable_order[vv][(num_a + vj)%int(best_area_depth)] =x;
}
else
variable_order[vv][(num_a + vj)%int(best_area_depth)] = variable_order[vv][(num_a + vj+1)%int(best_area_depth)];
}
for (int vj=0;vj<num_b+num_c;vj++){
if( (vj==(num_b+num_c-1))){
variable_order[vv][(num_a + vj)%int(best_area_depth)] =x;
}
else
variable_order[vv][(num_a + vj)%int(best_area_depth)] = variable_order[vv][(num_a + vj+1)%int(best_area_depth)];
}
}
for(int vi=0;vi<best_area_depth;vi++){
......@@ -470,6 +479,12 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
}
}
}
/// int num_d = gen()%int(1+best_area_depth);
/// int num_e = gen()%int(1+best_area_depth);
/// int x = variable_order[vv][num_d];
/// variable_order[vv][num_d] = variable_order[vv][num_e];
/// variable_order[vv][num_e] = x;
}
//}
......@@ -533,7 +548,7 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
if(i<parameter_max_orders)
replace_order = i;
else{
replace_order = 0;
replace_order = order_num;
int best_reward_tmp = 0;
for(int zi=0;zi<parameter_max_orders;zi++){
if(best_rewards[zi] > best_reward_tmp){
......@@ -578,7 +593,7 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
if(best_reward_max<500)
parameter_early_stop_split_nodes = 1000;
else
parameter_early_stop_split_nodes = int(best_reward_max*2);
parameter_early_stop_split_nodes = int(best_reward_max*4);
cout<<endl;
cout<<"Best Iteration: "<<best_iteration<<endl;
cout<<"This Iteration: "<<i<<endl;
......
......@@ -26,8 +26,9 @@ public:
};
class BDD_node_mask{
public:
bool mask[parameter_input_bit_width] = {0};
bool* mask;
BDD_node_mask(){
mask = new bool [parameter_input_bit_width];
}
};
class BDD_class{
......@@ -275,8 +276,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
bool it_can_simplify ;
bool it_can_simplify_neg ;
double all_train_time;
int root_nodes_leafs[how_many_start_nodes];
int leaf_nodes_roots[how_many_start_nodes];
int* root_nodes_leafs = new int [how_many_start_nodes];
int* leaf_nodes_roots = new int [how_many_start_nodes];
feature_area=0;
......@@ -875,6 +876,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
cout<<"######################################################################"<<endl;
}
delete [] root_nodes_leafs ;
delete [] leaf_nodes_roots ;
return 0;
};
......@@ -887,7 +890,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
cout<<"test dataset size = "<<parameter_test_ios<<endl;
error_amount_all = 0;
bool error_all [how_many_start_nodes*parameter_test_ios];
bool* error_all = new bool [how_many_start_nodes*parameter_test_ios];
//#pragma omp parallel for
for(long zj=0;zj<how_many_start_nodes*parameter_test_ios;zj++){
int test_bit = int(zj/parameter_test_ios);
......@@ -939,6 +942,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
gettimeofday(&finish_time,NULL);
double test_time = double(finish_time.tv_usec-start_time.tv_usec+1000000*(finish_time.tv_sec-start_time.tv_sec))/1000000;
cout<<"Total test time = "<<test_time<<"s"<<endl;
delete [] error_all;
return 0;
};
......@@ -1013,8 +1017,7 @@ int BDD_class::BDD_FULL_PROCESS(){
}
gettimeofday(&finish_time,NULL);
train_time = double(finish_time.tv_usec-start_time.tv_usec+1000000*(finish_time.tv_sec-start_time.tv_sec))/1000000;
double train_time = double(finish_time.tv_usec-start_time.tv_usec+1000000*(finish_time.tv_sec-start_time.tv_sec))/1000000;
srand((unsigned)time(0));
cout<<"ready to train"<<endl;
......@@ -1033,98 +1036,38 @@ int BDD_class::BDD_FULL_PROCESS(){
train_BDD(BDD,most_influence,start_depth,how_many_start_nodes,start_nodes);
int best_total_split_nodes_recursive = total_split_nodes_recursive;
cout<<"Finish Train"<<endl;
for (int k=0;k<2;k++){
for(int i=1;i<total_BDD_depth-2;i++){
//cout<<"Switch BDD: "<<i<<" ";
BSD_switch_layer(i);
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<" ";
if(total_split_nodes_recursive < best_total_split_nodes_recursive)
best_total_split_nodes_recursive = total_split_nodes_recursive;
else{
BSD_switch_layer(i);
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
for(int i=1;i<total_BDD_depth-3;i++){
//cout<<"Switch BDD: "<<i<<" ";
BSD_switch_layer(i);
BSD_switch_layer(i+1);
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<" ";
if(total_split_nodes_recursive < best_total_split_nodes_recursive)
best_total_split_nodes_recursive = total_split_nodes_recursive;
else{
BSD_switch_layer(i+1);
BSD_switch_layer(i);
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
for(int i=1;i<total_BDD_depth-4;i++){
//cout<<"Switch BDD: "<<i<<" ";
BSD_switch_layer(i);
BSD_switch_layer(i+1);
BSD_switch_layer(i+2);
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<" ";
if(total_split_nodes_recursive < best_total_split_nodes_recursive)
best_total_split_nodes_recursive = total_split_nodes_recursive;
else{
BSD_switch_layer(i+2);
BSD_switch_layer(i+1);
BSD_switch_layer(i);
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
for(int i=1;i<total_BDD_depth-5;i++){
//cout<<"Switch BDD: "<<i<<" ";
BSD_switch_layer(i);
BSD_switch_layer(i+1);
BSD_switch_layer(i+2);
BSD_switch_layer(i+3);
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<" ";
if(total_split_nodes_recursive < best_total_split_nodes_recursive)
best_total_split_nodes_recursive = total_split_nodes_recursive;
else{
BSD_switch_layer(i+3);
BSD_switch_layer(i+2);
BSD_switch_layer(i+1);
BSD_switch_layer(i);
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
for(int i=1;i<total_BDD_depth-6;i++){
//cout<<"Switch BDD: "<<i<<" ";
BSD_switch_layer(i);
BSD_switch_layer(i+1);
BSD_switch_layer(i+2);
BSD_switch_layer(i+3);
BSD_switch_layer(i+4);
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<" ";
if(total_split_nodes_recursive < best_total_split_nodes_recursive)
best_total_split_nodes_recursive = total_split_nodes_recursive;
else{
BSD_switch_layer(i+4);
BSD_switch_layer(i+3);
BSD_switch_layer(i+2);
BSD_switch_layer(i+1);
BSD_switch_layer(i);
struct timeval switch_start_time,switch_finish_time;
gettimeofday(&switch_start_time,NULL);
int max_group = 4;
for(int zj=total_BDD_depth/4;zj>=0;zj--){
for(int i=0;i<total_BDD_depth-zj-1;i++){
bool optimize=0;
for(int zk=0;zk<max_group;zk++){
for(int zi=0;zi<zj;zi++){
BSD_switch_layer(i+zi);
}
if(total_split_nodes_recursive < best_total_split_nodes_recursive){
best_total_split_nodes_recursive = total_split_nodes_recursive;
optimize = 1;
break;
}
}
if(optimize){}
else{
for(int zk=0;zk<max_group;zk++){
for(int zi=zj-1;zi>=0;zi--){
BSD_switch_layer(i+zi);
}
}
}
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
}
gettimeofday(&switch_finish_time,NULL);
double switch_time = double(switch_finish_time.tv_usec-switch_start_time.tv_usec+1000000*(switch_finish_time.tv_sec-switch_start_time.tv_sec))/1000000;
cout<<" Switch time = "<<switch_time<<"s"<<endl;
cout<<"Start infer"<<endl;
......
extern const int parameter_input_bit_width = 33+5; //输入bit有几位,写在+6前面。+6是为了防止一些bug的冗余设计。
extern const int parameter_output_bit_width = 25 ; //输出bit有几位
#include"io_generator/c1908.h"
#include"io_generator_function.h"
#include"c1908_vec.h"
#define INPUT_AIG
//#include"io_generator_function.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment