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
chengshuyao
BSD
Commits
7014457a
Commit
7014457a
authored
Aug 11, 2025
by
chengshuyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug long output
parent
947c1636
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
176 additions
and
81 deletions
+176
-81
src/BSD.cpp
+76
-41
src/BSD.h
+90
-30
src/next_layer_bit.h
+1
-1
src/top.h
+8
-8
src/write_vec.sh
+1
-1
No files found.
src/BSD.cpp
View file @
7014457a
...
...
@@ -32,7 +32,7 @@ using namespace std;
//电路的parameter Circuit_parameter
int
circuit_index
=
9999
;
//电路编号
int
parameter_max_orders
=
8
;
int
parameter_max_orders
=
1
;
...
...
@@ -457,8 +457,9 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
//}
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
);
int
num_c
=
gen
()
%
int
(
1
+
best_area_depth
/
4
);
int
num_b
=
num_c
+
gen
()
%
int
(
1
+
best_area_depth
/
2
);
cout
<<
"order number "
<<
order_num
<<
endl
;
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
];
...
...
@@ -513,9 +514,9 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
//}
if
(
i
==
0
)
reward
=
BSD_execute
(
start_order_depth
,
variable_order
,
partition_depth
,
partition_parts
,
0
,
output_partition_set
);
else
if
(
i
<
parameter_max_orders
){
reward
=
BSD_execute
(
0
,
variable_order
,
partition_depth
,
partition_parts
,
0
,
output_partition_set
);
}
//
else if (i<parameter_max_orders){
//
reward = BSD_execute(0,variable_order,partition_depth,partition_parts,0,output_partition_set);
//
}
else
{
reward
=
BSD_execute
(
best_area_depth
,
variable_order
,
partition_depth
,
partition_parts
,
order_num
,
output_partition_set
);
}
...
...
@@ -545,9 +546,6 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
}
if
(
accept
){
int
replace_order
;
if
(
i
<
parameter_max_orders
)
replace_order
=
i
;
else
{
replace_order
=
order_num
;
int
best_reward_tmp
=
0
;
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
...
...
@@ -557,44 +555,81 @@ int search_order(int search_iterations,bool* output_partition_set,int start_orde
}
}
}
best_iteration
=
i
;
if
(
reward
<
best_reward
){
best_reward
=
reward
;
best_area
=
BSD_features_0
.
BSD_area
;
best_area_depth
=
BSD_features_0
.
BSD_depth
;
}
best_rewards
[
replace_order
]
=
reward
;
best_areas
[
replace_order
]
=
BSD_features_0
.
BSD_area
;
best_area_depths
[
replace_order
]
=
BSD_features_0
.
BSD_depth
;
best_partition_depth
=
partition_depth
;
best_partition_parts
=
partition_parts
;
for
(
int
vi
=
0
;
vi
<
parameter_input_bit_width
;
vi
++
){
best_variable_order
[
replace_order
][
vi
]
=
variable_order
[
0
][
vi
];
cout
<<
best_variable_order
[
replace_order
][
vi
]
<<
" "
;
best_BDD_split_nodes
[
vi
]
=
BSD_features_0
.
BSD_area_layers
[
vi
];
//variable_features[vi] = double(BSD_features_0.BDD_width_each_layer[vi+1]) / double(BSD_features_0.BDD_width_each_layer[vi]);
//cout<<variable_features[vi]<<" ";
if
(
i
==
0
){
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
replace_order
=
zi
;
best_iteration
=
i
;
if
(
reward
<
best_reward
){
best_reward
=
reward
;
best_area
=
BSD_features_0
.
BSD_area
;
best_area_depth
=
BSD_features_0
.
BSD_depth
;
}
cout
<<
endl
;
best_rewards
[
replace_order
]
=
reward
;
best_areas
[
replace_order
]
=
BSD_features_0
.
BSD_area
;
best_area_depths
[
replace_order
]
=
BSD_features_0
.
BSD_depth
;
best_partition_depth
=
partition_depth
;
best_partition_parts
=
partition_parts
;
for
(
int
vi
=
0
;
vi
<
parameter_input_bit_width
;
vi
++
){
best_variable_order
[
replace_order
][
vi
]
=
variable_order
[
0
][
vi
];
cout
<<
best_variable_order
[
replace_order
][
vi
]
<<
" "
;
best_BDD_split_nodes
[
vi
]
=
BSD_features_0
.
BSD_area_layers
[
vi
];
}
cout
<<
endl
;
best_reward_max
=
0
;
best_order_num
=
0
;
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
if
(
best_rewards
[
zi
]
>
best_reward_max
)
best_reward_max
=
best_rewards
[
zi
];
if
(
best_rewards
[
zi
]
==
best_reward
)
best_order_num
=
zi
;
}
if
(
i
>=
parameter_max_orders
)
if
(
best_reward_max
<
1000
)
parameter_early_stop_split_nodes
=
2000
;
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
2
);
}
}
else
{
best_iteration
=
i
;
if
(
reward
<
best_reward
){
best_reward
=
reward
;
best_area
=
BSD_features_0
.
BSD_area
;
best_area_depth
=
BSD_features_0
.
BSD_depth
;
}
best_rewards
[
replace_order
]
=
reward
;
best_areas
[
replace_order
]
=
BSD_features_0
.
BSD_area
;
best_area_depths
[
replace_order
]
=
BSD_features_0
.
BSD_depth
;
best_partition_depth
=
partition_depth
;
best_partition_parts
=
partition_parts
;
for
(
int
vi
=
0
;
vi
<
parameter_input_bit_width
;
vi
++
){
best_variable_order
[
replace_order
][
vi
]
=
variable_order
[
0
][
vi
];
cout
<<
best_variable_order
[
replace_order
][
vi
]
<<
" "
;
best_BDD_split_nodes
[
vi
]
=
BSD_features_0
.
BSD_area_layers
[
vi
];
}
cout
<<
endl
;
best_reward_max
=
0
;
best_order_num
=
0
;
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
if
(
best_rewards
[
zi
]
>
best_reward_max
)
best_reward_max
=
best_rewards
[
zi
];
if
(
best_rewards
[
zi
]
==
best_reward
)
best_order_num
=
zi
;
}
if
(
i
>=
parameter_max_orders
)
if
(
best_reward_max
<
1000
)
parameter_early_stop_split_nodes
=
2000
;
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
2
);
}
cout
<<
"#############################"
<<
endl
;
cout
<<
"# This order accept #"
<<
endl
;
cout
<<
"#############################"
<<
endl
;
}
best_reward_max
=
0
;
best_order_num
=
0
;
for
(
int
zi
=
0
;
zi
<
parameter_max_orders
;
zi
++
){
if
(
best_rewards
[
zi
]
>
best_reward_max
)
best_reward_max
=
best_rewards
[
zi
];
if
(
best_rewards
[
zi
]
==
best_reward
)
best_order_num
=
zi
;
}
if
(
i
>=
parameter_max_orders
)
if
(
best_reward_max
<
500
)
parameter_early_stop_split_nodes
=
1000
;
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
4
);
cout
<<
endl
;
if
(
parameter_early_stop_split_nodes
<
4
*
best_reward_max
)
parameter_early_stop_split_nodes
+=
100
;
cout
<<
endl
;
cout
<<
"Best Iteration: "
<<
best_iteration
<<
endl
;
cout
<<
"This Iteration: "
<<
i
<<
endl
;
cout
<<
"Reward: "
<<
reward
<<
endl
;
...
...
src/BSD.h
View file @
7014457a
...
...
@@ -20,9 +20,14 @@ public:
int
switch_to_which_node
=
0
;
BDD_node
(){
which_root_node_all
=
new
bool
[
100
];
which_root_node_all
=
new
bool
[
parameter_output_bit_width
];
mask
=
new
bool
[
parameter_input_bit_width
];
};
~
BDD_node
(){
delete
[]
which_root_node_all
;
delete
[]
mask
;
};
};
class
BDD_node_mask
{
public
:
...
...
@@ -30,6 +35,9 @@ public:
BDD_node_mask
(){
mask
=
new
bool
[
parameter_input_bit_width
];
}
~
BDD_node_mask
(){
delete
[]
mask
;
}
};
class
BDD_class
{
public
:
...
...
@@ -41,7 +49,7 @@ public:
//BSD内部使用的变量(固定)
const
double
total_weight_max
=
pow
(
2
.
0
,
20
);
//指导权重分布修改
const
int
total_sample_max
=
1000000000
;
//指导采样个数修改
const
int
BSD_samples_influence_max
=
1
0
*
parameter_num_threads
;
//BSD确定展开序的置信度
const
int
BSD_samples_influence_max
=
1
*
parameter_num_threads
;
//BSD确定展开序的置信度
int
which_demo_function
;
int
BDD_id
;
...
...
@@ -177,7 +185,33 @@ public:
output_partition_set
=
new
bool
[
parameter_output_bit_width
];
};
//~BDD_class(){
// delete [] most_influence ;
// delete [] BDD_width_each_layer ;
// delete [] mask_input_data ;
// delete [] mask_output_data ;
// delete [] simplify_list ;
// delete [] BDD ;
// delete [] BDD_mask_this ;
// delete [] BDD_mask_next ;
// delete [] has_been_unfold ;
// delete [] amount_turn_output_data ;
// delete [] amount_turn ;
// delete [] test_input_data ;
// delete [] left_son_mask ;
// delete [] right_son_mask ;
// delete [] left_mask_output_data ;
// delete [] right_mask_output_data ;
// delete [] left_mask_output_data_all ;
// delete [] right_mask_output_data_all ;
//delete [] split_nodes_each_layer ;
//delete [] accuracy_each_layer ;
//delete [] BSD_variable_order ;
//delete [] BDD_split_nodes_each_layer ;
//delete [] output_partition_set ;
//};
};
int
BDD_class
::
BSD_samples_train_each_layer
(){
...
...
@@ -209,7 +243,7 @@ int BDD_class::BSD_samples_sort_each_layer(){
bool
BDD_class
::
io_generator_single
(
bool
input_data
[
parameter_input_bit_width
],
int
which_bit_output
){
bool
output_bit
;
bool
*
output_bits
=
new
bool
[
100
];
bool
*
output_bits
=
new
bool
[
parameter_output_bit_width
];
output_bits
=
io_generator_function
(
input_data
,
output_bits
);
if
(
output_partition_set
[
which_bit_output
]
==
1
)
output_bit
=
output_bits
[
which_bit_output
]
;
...
...
@@ -234,7 +268,7 @@ int BDD_class::io_generator_single_vec(int input_data[parameter_input_bit_width]
//cout<<"Debug 3"<<endl;
int
output_bit
;
//cout<<"Debug 3"<<endl;
int
*
output_bits
=
new
int
[
100
];
int
*
output_bits
=
new
int
[
parameter_output_bit_width
];
//cout<<"Debug 3"<<endl;
output_bits
=
io_generator_function_vec
(
input_data
,
output_bits
);
if
(
output_partition_set
[
which_bit_output
]
==
1
)
...
...
@@ -531,6 +565,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
// cout<<vec_output_left[31-kk];
// }
// cout<<endl;
//cout<<"Debug 3"<<endl;
for
(
int
kk
=
0
;
kk
<
vec_length
;
kk
++
){
long
zj
=
vec_length
*
zk
+
kk
;
...
...
@@ -1038,40 +1073,65 @@ int BDD_class::BDD_FULL_PROCESS(){
cout
<<
"Finish Train"
<<
endl
;
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
;
int
max_move_length
=
40
;
int
max_group
=
5
;
BDD_infer
(
BDD
,
most_influence
);
if
(
circuit_accuracy
<
0
.
96
){}
else
{
int
optimize_time
=
0
;
for
(
int
k
=
1
;
k
<
2
;
k
++
){
for
(
int
zj
=
0
;
zj
<
5
;
zj
++
){
max_group
=
(
zj
)
+
1
;
max_move_length
=
int
((
parameter_input_bit_width
/
(
1
+
zj
))
-
1
)
;
cout
<<
"######################################################################"
<<
endl
;
cout
<<
"Switch Times "
<<
zj
<<
endl
;
optimize_time
=
0
;
int
best_move_times_zk
=
0
;
int
best_move_times_zi
=
0
;
random_device
rd
;
mt19937
gen
(
rd
());
//int start_i = gen()%total_BDD_depth;
int
start_i
=
0
;
for
(
int
si
=
0
;
si
<
total_BDD_depth
-
1
;
si
++
){
int
i
=
(
start_i
+
si
)
%
total_BDD_depth
;
cout
<<
"Switch bit: "
<<
i
<<
" "
<<
endl
;
bool
optimize
=
0
;
int
move_length
=
min
(
total_BDD_depth
-
i
-
max_group
-
1
,
max_move_length
);
for
(
int
zi
=
0
;
zi
<=
move_length
;
zi
++
){
for
(
int
zk
=
0
;
zk
<=
min
(
max_group
,
move_length
-
1
);
zk
++
){
BSD_switch_layer
(
i
+
zi
+
min
(
max_group
,
move_length
-
1
)
-
zk
);
if
(
total_split_nodes_recursive
<
best_total_split_nodes_recursive
){
best_total_split_nodes_recursive
=
total_split_nodes_recursive
;
cout
<<
" move length "
<<
zi
<<
" move group "
<<
zk
;
cout
<<
" Best area update: "
<<
best_total_split_nodes_recursive
<<
endl
;
optimize_time
+=
1
;
}
}
}
}
if
(
optimize
){}
else
{
for
(
int
zk
=
0
;
zk
<
max_group
;
zk
++
){
for
(
int
zi
=
zj
-
1
;
zi
>=
0
;
zi
--
){
BSD_switch_layer
(
i
+
zi
);
for
(
int
zi
=
move_length
;
zi
>=
0
;
zi
--
){
for
(
int
zk
=
min
(
max_group
,
move_length
-
1
);
zk
>=
0
;
zk
--
){
if
(
total_split_nodes_recursive
==
best_total_split_nodes_recursive
)
break
;
else
BSD_switch_layer
(
i
+
zi
+
min
(
max_group
,
move_length
-
1
)
-
zk
);
}
}
}
if
(
optimize_time
<
10
)
break
;
}
}
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
;
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
<<
" Switch time = "
<<
switch_time
<<
"s"
<<
endl
;
}
cout
<<
"Start infer"
<<
endl
;
BDD_infer
(
BDD
,
most_influence
);
///
BDD_infer(BDD,most_influence);
//print_circuit(BDD,most_influence);
delete
[]
test_input_data
;
...
...
src/next_layer_bit.h
View file @
7014457a
...
...
@@ -358,7 +358,7 @@ int BDD_class::next_bit_layer_0(int depth){
}
}
int
BSD_samples_influence
=
BSD_samples_influence_max
;
for
(
zz
=
0
;
zz
<
1
0
;
zz
++
){
for
(
zz
=
0
;
zz
<
1
;
zz
++
){
if
(
depth
<
parameter_multi_output_index
){
break
;
}
...
...
src/top.h
View file @
7014457a
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"
extern
const
int
parameter_input_bit_width
=
256
+
5
;
//输入bit有几位,写在+6前面。+6是为了防止一些bug的冗余设计。
extern
const
int
parameter_output_bit_width
=
129
;
//输出bit有几位
#include"io_generator/adder.h"
#include "adder_vec.h"
#include"io_generator_function.h"
#include"c1908_vec.h"
#define INPUT_AIG
//#include"io_generator_function.h"
int
parameter_search_iterations
=
1000
;
//最大设计次数
int
parameter_test_ios
=
100
0
;
//测试要求多少样本
extern
const
int
parameter_max_samples
=
int
(
parameter_test_ios
*
16
);
//BSD每一个节点最多进行多少次采样
int
parameter_test_ios
=
100
;
//测试要求多少样本
extern
const
int
parameter_max_samples
=
int
(
parameter_test_ios
*
40
);
//BSD每一个节点最多进行多少次采样
bool
*
io_generator_function
(
bool
input_data
[
parameter_input_bit_width
],
bool
*
output_data
)
{
int
i
,
j
;
bool
*
output_data_temp
=
new
bool
[
100
];
bool
*
output_data_temp
=
new
bool
[
parameter_output_bit_width
];
io_generator_outer
(
input_data
,
output_data_temp
);
//io_generator_single_function_1(input_data,output_data_temp);
...
...
@@ -31,7 +31,7 @@ int* io_generator_function_vec(int input_data[parameter_input_bit_width], int* o
int
i
,
j
;
int
*
output_data_temp
=
new
int
[
100
];
int
*
output_data_temp
=
new
int
[
parameter_output_bit_width
];
io_generator_outer_vec
(
input_data
,
output_data_temp
);
//io_generator_single_function_1(input_data,output_data_temp);
...
...
src/write_vec.sh
View file @
7014457a
module_name
=
"
c1908
"
module_name
=
"
adder
"
vim
-c
"open io_generator/
${
module_name
}
.h"
\
-c
"1d"
\
-c
"1d"
\
...
...
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