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
00a996fb
Commit
00a996fb
authored
Sep 28, 2025
by
chengshuyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug accuracy
parent
8beb97fc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
35 deletions
+82
-35
src/BSD.cpp
+2
-2
src/BSD.h
+64
-25
src/io_generator_function.h
+6
-3
src/tool_function.h
+1
-0
src/top.h
+8
-4
src/zstart.sh
+1
-1
No files found.
src/BSD.cpp
View file @
00a996fb
...
...
@@ -39,7 +39,7 @@ extern const int parameter_max_orders = 2;
//算法的parameter Algorithm_parameter
extern
const
int
parameter_num_threads
=
64
;
//线程数
extern
const
int
parameter_multi_output_index
=
0
;
//BSD从第几层开始化简,前面若干层展开序确定
extern
const
int
parameter_max_BDD_width
=
32000
0
;
//BSD每一层最多多少个节点
extern
const
int
parameter_max_BDD_width
=
32000
;
//BSD每一层最多多少个节点
int
parameter_early_stop_depth
=
parameter_input_bit_width
;
//BSD到第几层终止,输出此时的不准确BSD
int
parameter_early_stop_split_nodes
=
1000000
;
//BSD每一层最多多少个节点
...
...
@@ -140,7 +140,7 @@ int main(int argc,char* argv[]){
int
*
start_order
=
new
int
[
parameter_input_bit_width
];
int
area_a
=
search_order
(
10
,
default_partition_set
,
0
,
start_order
);
int
area_a
=
search_order
(
parameter_search_iterations
,
default_partition_set
,
0
,
start_order
);
//search_partition(parameter_input_bit_width,start_order);
};
int
search_partition
(
int
start_order_depth
,
int
*
start_order
){
...
...
src/BSD.h
View file @
00a996fb
...
...
@@ -141,7 +141,7 @@ public:
bool
*
all_zero_left_list
;
bool
*
all_one_right_list
;
bool
*
all_zero_right_list
;
int
partition_depth
=
1000
;
int
partition_depth
=
1000
00
;
int
partition_parts
=
2
;
int
partition_into_how_many_parts
=
2
;
int
*
partition_start_node_numbers
;
...
...
@@ -183,8 +183,8 @@ public:
right_son_mask
=
new
bool
[
parameter_input_bit_width
];
left_mask_output_data
=
new
bool
[
parameter_max_samples
];
right_mask_output_data
=
new
bool
[
parameter_max_samples
];
left_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
*
parameter_max_samples
)];
right_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
*
parameter_max_samples
)];
left_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
)
*
long
(
parameter_max_samples
)];
right_mask_output_data_all
=
new
bool
[
long
(
parameter_max_BDD_width
)
*
long
(
parameter_max_samples
)];
all_one_left_list
=
new
bool
[
parameter_max_BDD_width
];
all_zero_left_list
=
new
bool
[
parameter_max_BDD_width
];
all_one_right_list
=
new
bool
[
parameter_max_BDD_width
];
...
...
@@ -621,8 +621,20 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
}
mask_input_data_left
[
most_influence
[
i
]]
=
0
;
mask_input_data_right
[
most_influence
[
i
]]
=
1
;
bool
left_mask_output_data_b
=
io_generator_single
(
mask_input_data_left
,
BDD
[
i
][
j
].
which_bit_output
);
bool
left_mask_output_data_b
=
io_generator_single
(
mask_input_data_left
,
BDD
[
i
][
j
].
which_bit_output
);
/////if(zj<100){
///// for (int jj=0;jj<parameter_input_bit_width;jj++){
///// cout<<mask_input_data_left[jj];
///// }
///// cout<<" "<<left_mask_output_data_b<<endl;
/////}
bool
right_mask_output_data_b
=
io_generator_single
(
mask_input_data_right
,
BDD
[
i
][
j
].
which_bit_output
);
/////if(zj<100){
///// for (int jj=0;jj<parameter_input_bit_width;jj++){
///// cout<<mask_input_data_right[jj];
///// }
///// cout<<" "<<right_mask_output_data_b<<endl;
/////}
right_mask_output_data_all
[
zj
]
=
right_mask_output_data_b
;
left_mask_output_data_all
[
zj
]
=
left_mask_output_data_b
;
...
...
@@ -645,7 +657,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
bool
*
left_mask_output_data_tmp
=
new
bool
[
BSD_samples
];
bool
*
right_mask_output_data_tmp
=
new
bool
[
BSD_samples
];
if
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
0
)
||
((
i
==
(
parameter_early_stop_depth
-
1
))
&&
(
which_BDD
==
1
))
||
((
total_split_nodes_recursive
)
>
parameter_early_stop_split_nodes
-
BDD_width_each_layer
[
i
])){
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
cout
<<
"Early Stop: Condition A "
<<
endl
;
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
100
);
zi
++
){
left_mask_output_data_tmp
[
zi
]
=
left_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
left_mask_output_data_tmp
[
zi
]){
left_ones
+=
1
;
...
...
@@ -653,7 +666,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
0
);
zi
++
){
right_mask_output_data
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
if
(
right_mask_output_data_tmp
[
zi
]){
right_ones
+=
1
;
...
...
@@ -677,6 +690,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
all_zero_right_list
[
j
]
=
1
;
}
}
else
if
((
BDD_width_each_layer
[
i
]
>
parameter_max_BDD_width
/
2
)
){
cout
<<
"Early Stop: Condition B "
<<
endl
;
cout
<<
"which node this layer: "
<<
j
<<
endl
;
cout
<<
" Finish trained weight = "
<<
setprecision
(
12
)
<<
(
total_finish_weight
)
/
pow
(
2
.
0
,
20
)
<<
endl
;
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
...
...
@@ -686,7 +700,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
0
);
zi
++
){
if
(
right_mask_output_data_tmp
[
zi
]){
right_ones
+=
1
;
}
else
{
...
...
@@ -715,6 +729,8 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
all_one_right_list
[
j
]
=
1
;
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
left_mask_output_data_tmp
[
zi
]
=
left_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
//if(zi<100)
//cout<<left_mask_output_data_tmp[zi];
if
(
left_mask_output_data_tmp
[
zi
]){
all_zero_left_list
[
j
]
=
0
;
}
else
{
...
...
@@ -724,8 +740,12 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
break
;
}
}
//cout<<endl;
//cout<<endl;
for
(
int
zi
=
0
;
zi
<
BSD_samples
;
zi
++
){
right_mask_output_data_tmp
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
//if(zi<100)
//cout<<right_mask_output_data_tmp[zi];
if
(
right_mask_output_data_tmp
[
zi
]){
all_zero_right_list
[
j
]
=
0
;
}
else
{
...
...
@@ -735,6 +755,11 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
break
;
}
}
//cout<<endl;
//cout<<"all zero left"<<all_zero_left_list[j] <<endl;
//cout<<"all one left"<<all_one_left_list[j] <<endl;
//cout<<"all zero right"<<all_zero_right_list[j] <<endl;
//cout<<"all one right"<<all_one_right_list[j] <<endl;
}
delete
[]
left_mask_output_data_tmp
;
delete
[]
right_mask_output_data_tmp
;
...
...
@@ -772,24 +797,24 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
right_mask_output_data
[
zi
]
=
right_mask_output_data_all
[
zi
+
BSD_samples
*
j
];
}
//cout<<"Debug 2"<<" ";
int
left_zeros
=
0
;
int
left_ones
=
0
;
int
right_zeros
=
0
;
int
right_ones
=
0
;
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
if
(
left_mask_output_data
[
zi
]){
left_ones
+=
1
;
}
else
{
left_zeros
+=
1
;
}
}
for
(
int
zi
=
0
;
zi
<
min
(
BSD_samples
,
10
);
zi
++
){
if
(
right_mask_output_data
[
zi
]){
right_ones
+=
1
;
}
else
{
right_zeros
+=
1
;
}
}
///
int left_zeros = 0;
///
int left_ones = 0;
///
int right_zeros = 0;
///
int right_ones = 0;
///
for(int zi=0;zi<min(BSD_samples,10);zi++){
///
if(left_mask_output_data[zi]){
///
left_ones += 1;
///
}else{
///
left_zeros += 1;
///
}
///
}
///
for(int zi=0;zi<min(BSD_samples,10);zi++){
///
if(right_mask_output_data[zi]){
///
right_ones += 1;
///
}else{
///
right_zeros += 1;
///
}
///
}
//cout<<"Debug 3"<<" ";
//cout<<"Debug 4"<<" ";
...
...
@@ -799,9 +824,11 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
int
hash_right_neg_number
=
hash_simplify_list_function
(
right_mask_output_data
,
1
);
if
(
i
>
parameter_multi_output_index
-
1
){
if
(
all_zero_left
){
//cout<<"all zero left"<<all_zero_left <<endl;
BDD
[
i
][
j
].
left_node_index
=
-
2
;
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
}
else
if
(
all_one_left
){
//cout<<"all one left"<<all_one_left <<endl;
BDD
[
i
][
j
].
left_node_index
=
-
1
;
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
}
else
{
...
...
@@ -889,9 +916,11 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
if
(
all_zero_right
){
BDD
[
i
][
j
].
right_node_index
=
-
2
;
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
//cout<<"all zero right"<<all_zero_right <<endl;
}
else
if
(
all_one_right
){
BDD
[
i
][
j
].
right_node_index
=
-
1
;
total_finish_weight
+=
BDD
[
i
][
j
].
weight
/
2
;
//cout<<"all one right"<<all_one_right <<endl;
}
else
{
if
(((
i
%
how_often_simplify
==
0
))){
which_list_number
=
compare_simplify_list
(
BDD_width_each_layer
[
i
+
1
],
right_mask_output_data
,
simplify_list
,
hash_simplify_list
,
hash_right_number
);
...
...
@@ -1050,10 +1079,19 @@ int BDD_class::BDD_infer(BDD_node** BDD,int* most_influence){
test_input_data
[
most_influence
[
j
]]
=
BDD
[
start_depth
][
test_bit
].
mask
[
most_influence
[
j
]];
}
test_output_data
=
io_generator_single
(
test_input_data
,
BDD
[
start_depth
][
test_bit
].
which_bit_output
);
infer_output_data
=
cal_infer_result
(
test_input_data
,
test_bit
,
0
);
error_all
[
zj
]
=
(
test_output_data
!=
infer_output_data
);
/////if((zj<1000) && (error_all[zj])){
///// for (int jj=0;jj<parameter_input_bit_width;jj++){
///// cout<<test_input_data[jj];
///// }
///// cout<<" "<<infer_output_data<<endl;
///// cout<<" "<<test_output_data<<endl;
/////}
delete
[]
test_input_data
;
}
cout
<<
endl
;
circuit_accuracy_all_bits
=
new
double
[
how_many_start_nodes
];
for
(
int
test_bit
=
0
;
test_bit
<
how_many_start_nodes
;
test_bit
++
){
error_amount
=
0
;
...
...
@@ -1288,6 +1326,7 @@ int BDD_class::BDD_FULL_PROCESS(){
cout
<<
"Start infer"
<<
endl
;
BDD_infer
(
BDD
,
most_influence
);
print_circuit
(
BDD
,
most_influence
);
if
(
circuit_accuracy
==
1
)
print_circuit
(
BDD
,
most_influence
);
delete
[]
test_input_data
;
...
...
src/io_generator_function.h
View file @
00a996fb
#pragma once
int
parameter_data_width
=
32
;
int
parameter_data_width
=
8
;
bool
*
io_generator_single_function_0
(
bool
*
input_data
,
bool
*
output_data
);
//==
bool
*
io_generator_single_function_1
(
bool
*
input_data
,
bool
*
output_data
);
//add_unsigned
bool
*
io_generator_single_function_2
(
bool
*
input_data
,
bool
*
output_data
);
//add
...
...
@@ -56,8 +56,11 @@ bool* io_generator_single_function_1(bool* input_data,bool* output_data){//add_u
bool
*
output_data_result
=
new
bool
[
parameter_data_width
];
cvt_number_to_bit_unsigned
(
output_data_result
,
data_result
,
parameter_data_width
);
for
(
i
=
0
;
i
<
parameter_data_width
;
i
++
){
output_data
[
i
]
=
output_data_result
[
i
];
for
(
i
=
0
;
i
<
PO_WIDTH
;
i
++
){
if
(
i
<
parameter_data_width
)
output_data
[
i
]
=
output_data_result
[
i
];
else
output_data
[
i
]
=
0
;
}
delete
[]
output_data_result
;
return
output_data
;
...
...
src/tool_function.h
View file @
00a996fb
...
...
@@ -62,6 +62,7 @@ int BDD_class::hash_simplify_list_function(bool* list, bool neg){
}
int
BDD_class
::
compare_simplify_list
(
int
list_line_amount
,
bool
*
this_line
,
bool
**
simplify_list
,
int
*
hash_simplify_list
,
int
hash_number
){
int
which_list_number
=
-
1
;
//return which_list_number;
bool
it_can_simplify
=
0
;
int
i
,
j
;
bool
it_can_simplify_here
;
...
...
src/top.h
View file @
00a996fb
#define INPUT_AIG
#include "io_generator/
vl_arith_unit
.h"
#include "
vl_arith_unit
_vec.h"
#include "io_generator/
multiplier_88
.h"
#include "
multiplier_88
_vec.h"
extern
const
int
parameter_input_bit_width
=
PI_WIDTH
+
5
;
//int PI_WIDTH = 32;
//int PO_WIDTH = 18;
extern
const
int
parameter_input_bit_width
=
PI_WIDTH
+
5
;
extern
const
int
parameter_output_bit_width
=
PO_WIDTH
;
//extern const int parameter_train_output_bit_width = 1 ;
...
...
@@ -14,8 +17,9 @@ extern const int parameter_output_bit_width = PO_WIDTH ;
//#include"io_generator_tmp.h"
//#include"io_generator_function.h"
extern
const
int
parameter_search_iterations
=
1
00
;
//最大设计次数
extern
const
int
parameter_search_iterations
=
1
;
//最大设计次数
extern
const
int
parameter_test_ios
=
1000
;
//测试要求多少样本
extern
const
int
parameter_max_samples
=
int
(
parameter_test_ios
*
100
/
32
)
*
32
;
//BSD每一个节点最多进行多少次采样
...
...
src/zstart.sh
View file @
00a996fb
...
...
@@ -3,5 +3,5 @@ export LIBRARY_PATH=/lustre/S/chengshuyao/haoshiming/anaconda3/envs/BSD/bin:/lus
export
LD_LIBRARY_PATH
=
/lustre/S/chengshuyao/haoshiming/anaconda3/envs/BSD/bin:/lustre/S/chengshuyao/haoshiming/anaconda3/envs/BSD/lib
rm rtl/
*
#bash write_vec.sh
g++ BSD.cpp
-O3
-std
=
c++11
-fopenmp
-pg
g++ BSD.cpp
-O3
-std
=
c++11
-fopenmp
./a.out
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