Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BSD
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SunMaple
BSD
Commits
947c1636
Commit
947c1636
authored
Jul 22, 2025
by
chengshuyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Release For Switch Layer Test
parent
888652cb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
119 deletions
+78
-119
src/BSD.cpp
+45
-30
src/BSD.h
+32
-89
src/top.h
+1
-0
No files found.
src/BSD.cpp
View file @
947c1636
...
@@ -32,7 +32,7 @@ using namespace std;
...
@@ -32,7 +32,7 @@ using namespace std;
//电路的parameter Circuit_parameter
//电路的parameter Circuit_parameter
int
circuit_index
=
9999
;
//电路编号
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){
...
@@ -159,12 +159,12 @@ int search_partition(int start_order_depth, int* start_order){
}
}
int
area
=
0
;;
int
area
=
0
;;
int
*
start_order_a
=
new
int
[
parameter_input_bit_width
];
//
int* start_order_a = new int [parameter_input_bit_width];
int
*
start_order_b
=
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
++
){
//
for(int i=0;i<parameter_input_bit_width;i++){
start_order_a
[
i
]
=
0
;
//
start_order_a[i] = 0;
start_order_b
[
i
]
=
0
;
//
start_order_b[i] = 0;
}
//
}
int
area_a
=
search_order
(
10
,
output_partition_set_a
,
start_order_depth
,
start_order
);
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
);
int
area_b
=
search_order
(
10
,
output_partition_set_b
,
start_order_depth
,
start_order
);
area
=
area_a
+
area_b
;
area
=
area_a
+
area_b
;
...
@@ -177,8 +177,8 @@ int search_partition(int start_order_depth, int* start_order){
...
@@ -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
];
best_output_partition_set_b
[
i
]
=
output_partition_set_b
[
i
];
}
}
for
(
int
i
=
0
;
i
<
parameter_input_bit_width
;
i
++
){
for
(
int
i
=
0
;
i
<
parameter_input_bit_width
;
i
++
){
best_start_order_a
[
i
]
=
start_order
_a
[
i
];
best_start_order_a
[
i
]
=
start_order
[
i
];
best_start_order_b
[
i
]
=
start_order
_b
[
i
];
best_start_order_b
[
i
]
=
start_order
[
i
];
}
}
}
}
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
...
@@ -187,13 +187,13 @@ int search_partition(int start_order_depth, int* start_order){
...
@@ -187,13 +187,13 @@ int search_partition(int start_order_depth, int* start_order){
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
delete
[]
output_partition_set_a
;
delete
[]
output_partition_set_a
;
delete
[]
output_partition_set_b
;
delete
[]
output_partition_set_b
;
delete
[]
start_order_a
;
//
delete [] start_order_a;
delete
[]
start_order_b
;
//
delete [] start_order_b;
}
}
parameter_max_orders
*=
2
;
parameter_max_orders
*=
2
;
int
area
=
0
;
int
area
=
0
;
int
area_a
=
search_order
(
20
0
,
best_output_partition_set_a
,
parameter_input_bit_width
,
best_start_order_a
);
int
area_a
=
search_order
(
4
0
,
best_output_partition_set_a
,
parameter_input_bit_width
,
best_start_order_a
);
int
area_b
=
search_order
(
20
0
,
best_output_partition_set_b
,
parameter_input_bit_width
,
best_start_order_b
);
int
area_b
=
search_order
(
4
0
,
best_output_partition_set_b
,
parameter_input_bit_width
,
best_start_order_b
);
area
=
area_a
+
area_b
;
area
=
area_a
+
area_b
;
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
...
@@ -418,9 +418,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
...
@@ -418,9 +418,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
cout
<<
endl
;
cout
<<
endl
;
int
order_num
=
gen
()
%
parameter_max_orders
;
int
order_num
=
gen
()
%
parameter_max_orders
;
if
(
gen
()
%
3
==
0
){
//int best_reward_tmp = 0;
order_num
=
best_order_num
;
//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)
//if(i<100)
// learning_rate= int((100-i)/10);
// learning_rate= int((100-i)/10);
//else
//else
...
@@ -434,18 +443,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
...
@@ -434,18 +443,18 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
vv
=
0
;
vv
=
0
;
}
else
{
}
else
{
best_area_depth
=
best_area_depths
[
vv
];
best_area_depth
=
best_area_depths
[
vv
];
for
(
int
vi
=
1
;
vi
<
best_area_depth
;
vi
++
){
//
for(int vi=1;vi<best_area_depth;vi++){
if
(
(
gen
()
%
int
(
1
+
best_area_depth
)
==
0
)){
//
if( (gen()%int(1+best_area_depth)==0)){
int
vii
=
vi
-
1
;
//
int vii = vi-1;
int
x
=
variable_order
[
vv
][
vi
];
//
int x = variable_order[vv][vi];
variable_order
[
vv
][
vi
]
=
variable_order
[
vv
][
vii
];
//
variable_order[vv][vi] = variable_order[vv][vii];
variable_order
[
vv
][
vii
]
=
x
;
//
variable_order[vv][vii] = x;
//double y = variable_features[vi];
//
//double y = variable_features[vi];
//variable_features[vi] = variable_features[vii];
//
//variable_features[vi] = variable_features[vii];
//variable_features[vii] = y;
//
//variable_features[vii] = y;
break
;
//
break;
}
//
}
}
//
}
int
num_a
=
gen
()
%
int
(
1
+
best_area_depth
/
2
);
int
num_a
=
gen
()
%
int
(
1
+
best_area_depth
/
2
);
//int num_b = gen()%int(1+best_area_depth/4);
//int num_b = gen()%int(1+best_area_depth/4);
int
num_c
=
1
+
gen
()
%
int
(
1
+
best_area_depth
/
4
);
int
num_c
=
1
+
gen
()
%
int
(
1
+
best_area_depth
/
4
);
...
@@ -470,6 +479,12 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
...
@@ -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
...
@@ -533,7 +548,7 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
if
(
i
<
parameter_max_orders
)
if
(
i
<
parameter_max_orders
)
replace_order
=
i
;
replace_order
=
i
;
else
{
else
{
replace_order
=
0
;
replace_order
=
order_num
;
int
best_reward_tmp
=
0
;
int
best_reward_tmp
=
0
;
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
if
(
best_rewards
[
zi
]
>
best_reward_tmp
){
if
(
best_rewards
[
zi
]
>
best_reward_tmp
){
...
@@ -578,7 +593,7 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
...
@@ -578,7 +593,7 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
if
(
best_reward_max
<
500
)
if
(
best_reward_max
<
500
)
parameter_early_stop_split_nodes
=
1000
;
parameter_early_stop_split_nodes
=
1000
;
else
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
2
);
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
4
);
cout
<<
endl
;
cout
<<
endl
;
cout
<<
"Best Iteration: "
<<
best_iteration
<<
endl
;
cout
<<
"Best Iteration: "
<<
best_iteration
<<
endl
;
cout
<<
"This Iteration: "
<<
i
<<
endl
;
cout
<<
"This Iteration: "
<<
i
<<
endl
;
...
...
src/BSD.h
View file @
947c1636
...
@@ -26,8 +26,9 @@ public:
...
@@ -26,8 +26,9 @@ public:
};
};
class
BDD_node_mask
{
class
BDD_node_mask
{
public
:
public
:
bool
mask
[
parameter_input_bit_width
]
=
{
0
}
;
bool
*
mask
;
BDD_node_mask
(){
BDD_node_mask
(){
mask
=
new
bool
[
parameter_input_bit_width
];
}
}
};
};
class
BDD_class
{
class
BDD_class
{
...
@@ -275,8 +276,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
...
@@ -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
;
bool
it_can_simplify_neg
;
bool
it_can_simplify_neg
;
double
all_train_time
;
double
all_train_time
;
int
root_nodes_leafs
[
how_many_start_nodes
];
int
*
root_nodes_leafs
=
new
int
[
how_many_start_nodes
];
int
leaf_nodes_roots
[
how_many_start_nodes
];
int
*
leaf_nodes_roots
=
new
int
[
how_many_start_nodes
];
feature_area
=
0
;
feature_area
=
0
;
...
@@ -875,6 +876,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
...
@@ -875,6 +876,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
cout
<<
"######################################################################"
<<
endl
;
cout
<<
"######################################################################"
<<
endl
;
}
}
delete
[]
root_nodes_leafs
;
delete
[]
leaf_nodes_roots
;
return
0
;
return
0
;
};
};
...
@@ -887,7 +890,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
...
@@ -887,7 +890,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
cout
<<
"test dataset size = "
<<
parameter_test_ios
<<
endl
;
cout
<<
"test dataset size = "
<<
parameter_test_ios
<<
endl
;
error_amount_all
=
0
;
error_amount_all
=
0
;
bool
error_al
l
[
how_many_start_nodes
*
parameter_test_ios
];
bool
*
error_all
=
new
boo
l
[
how_many_start_nodes
*
parameter_test_ios
];
//#pragma omp parallel for
//#pragma omp parallel for
for
(
long
zj
=
0
;
zj
<
how_many_start_nodes
*
parameter_test_ios
;
zj
++
){
for
(
long
zj
=
0
;
zj
<
how_many_start_nodes
*
parameter_test_ios
;
zj
++
){
int
test_bit
=
int
(
zj
/
parameter_test_ios
);
int
test_bit
=
int
(
zj
/
parameter_test_ios
);
...
@@ -939,6 +942,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
...
@@ -939,6 +942,7 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
gettimeofday
(
&
finish_time
,
NULL
);
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
;
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
;
cout
<<
"Total test time = "
<<
test_time
<<
"s"
<<
endl
;
delete
[]
error_all
;
return
0
;
return
0
;
};
};
...
@@ -1013,8 +1017,7 @@ int BDD_class::BDD_FULL_PROCESS(){
...
@@ -1013,8 +1017,7 @@ int BDD_class::BDD_FULL_PROCESS(){
}
}
gettimeofday
(
&
finish_time
,
NULL
);
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
));
srand
((
unsigned
)
time
(
0
));
cout
<<
"ready to train"
<<
endl
;
cout
<<
"ready to train"
<<
endl
;
...
@@ -1033,99 +1036,39 @@ int BDD_class::BDD_FULL_PROCESS(){
...
@@ -1033,99 +1036,39 @@ int BDD_class::BDD_FULL_PROCESS(){
train_BDD
(
BDD
,
most_influence
,
start_depth
,
how_many_start_nodes
,
start_nodes
);
train_BDD
(
BDD
,
most_influence
,
start_depth
,
how_many_start_nodes
,
start_nodes
);
int
best_total_split_nodes_recursive
=
total_split_nodes_recursive
;
int
best_total_split_nodes_recursive
=
total_split_nodes_recursive
;
cout
<<
"Finish Train"
<<
endl
;
cout
<<
"Finish Train"
<<
endl
;
for
(
int
k
=
0
;
k
<
2
;
k
++
){
struct
timeval
switch_start_time
,
switch_finish_time
;
for
(
int
i
=
1
;
i
<
total_BDD_depth
-
2
;
i
++
){
gettimeofday
(
&
switch_start_time
,
NULL
);
//cout<<"Switch BDD: "<<i<<" ";
int
max_group
=
4
;
BSD_switch_layer
(
i
);
//cout<<total_nodes_amount<<" ";
for
(
int
zj
=
total_BDD_depth
/
4
;
zj
>=
0
;
zj
--
){
//cout<<total_split_nodes_recursive<<" ";
for
(
int
i
=
0
;
i
<
total_BDD_depth
-
zj
-
1
;
i
++
){
if
(
total_split_nodes_recursive
<
best_total_split_nodes_recursive
)
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
;
best_total_split_nodes_recursive
=
total_split_nodes_recursive
;
else
{
optimize
=
1
;
BSD_switch_layer
(
i
)
;
break
;
}
}
//cout<<total_nodes_amount<<" ";
//cout<<total_split_nodes_recursive<<endl;
}
}
for
(
int
i
=
1
;
i
<
total_BDD_depth
-
3
;
i
++
){
if
(
optimize
){}
//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
{
else
{
BSD_switch_layer
(
i
+
1
);
for
(
int
zk
=
0
;
zk
<
max_group
;
zk
++
){
BSD_switch_layer
(
i
);
for
(
int
zi
=
zj
-
1
;
zi
>=
0
;
zi
--
){
BSD_switch_layer
(
i
+
zi
);
}
}
//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
);
}
}
//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
;
cout
<<
"Start infer"
<<
endl
;
BDD_infer
(
BDD
,
most_influence
);
BDD_infer
(
BDD
,
most_influence
);
...
...
src/top.h
View file @
947c1636
extern
const
int
parameter_input_bit_width
=
33
+
5
;
//输入bit有几位,写在+6前面。+6是为了防止一些bug的冗余设计。
extern
const
int
parameter_input_bit_width
=
33
+
5
;
//输入bit有几位,写在+6前面。+6是为了防止一些bug的冗余设计。
extern
const
int
parameter_output_bit_width
=
25
;
//输出bit有几位
extern
const
int
parameter_output_bit_width
=
25
;
//输出bit有几位
#include"io_generator/c1908.h"
#include"io_generator/c1908.h"
#include"io_generator_function.h"
#include"c1908_vec.h"
#include"c1908_vec.h"
#define INPUT_AIG
#define INPUT_AIG
//#include"io_generator_function.h"
//#include"io_generator_function.h"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment