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
9aee67a1
Commit
9aee67a1
authored
Dec 10, 2025
by
chengshuyao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now partition searching is kind of effective
parent
f4c821d4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
398 additions
and
164 deletions
+398
-164
src/BSD.cpp
+2
-2
src/BSD.h
+54
-30
src/BSD_top.h
+319
-123
src/next_layer_bit.h
+4
-4
src/print_circuit.h
+18
-4
src/top.h
+1
-1
No files found.
src/BSD.cpp
View file @
9aee67a1
...
...
@@ -4,7 +4,7 @@
int
main
(
int
argc
,
char
*
argv
[]){
set_default
();
int
area_a
=
search_order
();
//search_partition(parameter_input_bit_width,start_order
);
//
int area_a = search_order();
search_partition
(
);
};
src/BSD.h
View file @
9aee67a1
...
...
@@ -92,7 +92,7 @@ public:
uint64_t
io_generator_single_vec
(
uint64_t
*
input_data
,
int
which_bit_output
);
int
set_random_input_data
(
bool
**
mask_input_data
);
int
mask_random_input_data
(
int
depth
,
bool
*
mask
,
int
amount
,
int
*
most_influence
,
bool
**
mask_input_data
);
int
next_bit_layer
(
int
depth
,
int
order_num
);
int
next_bit_layer
(
int
depth
);
int
next_bit_layer_0
(
int
depth
);
int
next_bit_layer_1
(
int
depth
);
int
next_bit_layer_old
(
int
depth
);
...
...
@@ -128,7 +128,7 @@ public:
int
BDD_infer
(
BDD_node
**
BDD
,
int
*
most_influence
);
int
print_circuit
(
BDD_node
**
BDD
,
int
*
most_influence
);
int
print_circuit
(
BDD_node
**
BDD
,
int
*
most_influence
,
int
node_depth
,
char
*
start_node_index_string
);
int
BDD_FULL_PROCESS
();
bool
*
left_son_mask
;
...
...
@@ -155,13 +155,16 @@ public:
int
BSD_samples_train_each_layer
();
int
BSD_samples_sort_each_layer
();
int
*
*
BSD_variable_order
;
int
*
BSD_variable_order
;
int
BSD_variable_order_number
;
int
feature_area
;
int
*
split_nodes_each_layer
;
int
*
accuracy_each_layer
;
bool
*
output_partition_set
;
node_index
*
start_node_index
;
char
*
start_node_index_string
;
//huanglue
void
BSD_switch_layer
(
int
i
);
int
*
BDD_split_nodes_each_layer
=
nullptr
;
...
...
@@ -194,9 +197,11 @@ public:
split_nodes_each_layer
=
new
int
[
parameter_input_bit_width
+
1
];
accuracy_each_layer
=
new
int
[
parameter_input_bit_width
+
1
];
BSD_variable_order
=
new
int
*
[
parameter_max_orders
];
BSD_variable_order
=
new
int
[
parameter_input_bit_width
+
1
];
BDD_split_nodes_each_layer
=
new
int
[
parameter_input_bit_width
+
1
];
output_partition_set
=
new
bool
[
parameter_output_bit_width
];
start_node_index
=
new
node_index
[
parameter_output_bit_width
];
start_node_index_string
=
new
char
[
parameter_output_bit_width
];
};
//~BDD_class(){
...
...
@@ -248,22 +253,26 @@ int BDD_class::BSD_samples_sort_each_layer(){
bool
BDD_class
::
io_generator_single
(
bool
*
input_data
,
int
which_bit_output
){
int
origin_which_bit_output
=
this
->
start_node_index
[
which_bit_output
].
root_node_index
;
for
(
int
i
=
0
;
i
<
this
->
start_node_index
[
which_bit_output
].
node_depth
;
i
++
){
input_data
[
this
->
start_node_index
[
which_bit_output
].
expand_input_bit_index
[
i
]]
=
this
->
start_node_index
[
which_bit_output
].
expand_input_bit_data
[
i
];
}
#ifdef SINGLE_BITS
if
(
output_partition_set
[
which_bit_output
]
==
1
){
bool
output_bit_s
=
io_generator_outer_single
(
input_data
,
which_bit_output
)
;
//
if (output_partition_set[which_bit_output]==1){
bool
output_bit_s
=
io_generator_outer_single
(
input_data
,
origin_
which_bit_output
)
;
return
output_bit_s
;
}
else
{
return
0
;
}
//
}else{
//
return 0;
//
}
#else
bool
output_bit
;
bool
*
output_bits
=
new
bool
[
parameter_output_bit_width
];
if
(
output_partition_set
[
which_bit_output
]
==
1
){
//
if (output_partition_set[which_bit_output]==1){
output_bits
=
io_generator_function
(
input_data
,
output_bits
);
output_bit
=
output_bits
[
which_bit_output
]
;
}
else
output_bit
=
0
;
//
}
//
else
//
output_bit = 0;
delete
[]
output_bits
;
return
output_bit
;
#endif
...
...
@@ -272,21 +281,28 @@ bool BDD_class::io_generator_single(bool* input_data,int which_bit_output){
uint64_t
BDD_class
::
io_generator_single_vec
(
uint64_t
*
input_data
,
int
which_bit_output
){
int
origin_which_bit_output
=
this
->
start_node_index
[
which_bit_output
].
root_node_index
;
for
(
int
i
=
0
;
i
<
this
->
start_node_index
[
which_bit_output
].
node_depth
;
i
++
){
if
(
this
->
start_node_index
[
which_bit_output
].
expand_input_bit_data
[
i
]
==
0
)
input_data
[
this
->
start_node_index
[
which_bit_output
].
expand_input_bit_index
[
i
]]
=
uint64_t
(
0
);
else
input_data
[
this
->
start_node_index
[
which_bit_output
].
expand_input_bit_index
[
i
]]
=
~
uint64_t
(
0
);
}
#ifdef SINGLE_BITS
if
(
output_partition_set
[
which_bit_output
]
==
1
){
uint64_t
output_bit_s
=
io_generator_outer_vec_single
(
input_data
,
which_bit_output
)
;
//
if (output_partition_set[which_bit_output]==1){
uint64_t
output_bit_s
=
io_generator_outer_vec_single
(
input_data
,
origin_
which_bit_output
)
;
return
output_bit_s
;
}
else
return
0
;
//
}else
//
return 0;
#else
uint64_t
output_bit
;
uint64_t
*
output_bits
=
new
uint64_t
[
parameter_output_bit_width
];
if
(
output_partition_set
[
which_bit_output
]
==
1
){
//
if (output_partition_set[which_bit_output]==1){
output_bits
=
io_generator_function_vec
(
input_data
,
output_bits
);
output_bit
=
output_bits
[
which_bit_output
]
;
}
else
output_bit
=
0
;
//
}
//
else
//
output_bit = 0;
delete
[]
output_bits
;
return
output_bit
;
#endif
...
...
@@ -406,7 +422,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
for
(
int
zj
=
0
;
zj
<
parameter_input_bit_width
+
1
;
zj
++
){
BDD_partition
[
zi
].
has_been_unfold
[
zj
]
=
has_been_unfold
[
zj
];
BDD_partition
[
zi
].
most_influence
[
zj
]
=
most_influence
[
zj
];
BDD_partition
[
zi
].
BSD_variable_order
[
0
][
zj
]
=
BSD_variable_order
[
zi
+
1
]
[
zj
];
BDD_partition
[
zi
].
BSD_variable_order
[
zj
]
=
BSD_variable_order
[
zj
];
}
for
(
int
zj
=
0
;
zj
<
BDD_partition
[
zi
].
how_many_start_nodes
;
zj
++
){
if
(
partition_index
[
zi
][
zj
]
<
BDD_width_each_layer
[
i
]){
...
...
@@ -473,9 +489,6 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
delete
[]
split_nodes_each_layer
;
delete
[]
accuracy_each_layer
;
for
(
int
zj
=
0
;
zj
<
parameter_max_orders
;
zj
++
){
delete
[]
BSD_variable_order
[
zj
]
;
}
delete
[]
BSD_variable_order
;
for
(
zi
=
0
;
zi
<
partition_into_how_many_parts
;
zi
++
){
...
...
@@ -511,7 +524,7 @@ int BDD_class::train_BDD(BDD_node** BDD,int* most_influence,int start_depth, int
BDD
[
i
+
1
][
zi
].
non_equal_number
=
0
;
}
BSD_samples
=
BSD_samples_sort
;
most_influence
[
i
]
=
next_bit_layer
(
i
,
order_num
);
most_influence
[
i
]
=
next_bit_layer
(
i
);
BSD_samples
=
int
(
BSD_samples_train
/
63
)
*
63
;
//一定要是vec_length的整数倍
cout
<<
BSD_samples
<<
endl
;
...
...
@@ -1246,6 +1259,17 @@ int BDD_class::BDD_FULL_PROCESS(){
for
(
j
=
0
;
j
<
parameter_max_samples
;
j
++
){
mask_input_data
[
j
]
=
new
bool
[
parameter_input_bit_width
+
2
];
}
int
start_node_ij
=
0
;
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
){
if
(
i
==
start_node_index
[
start_node_ij
].
root_node_index
){
start_node_index_string
[
i
]
=
'1'
;
start_node_ij
++
;
}
else
{
start_node_index_string
[
i
]
=
'0'
;
}
}
// for (j=0;j<parameter_max_orders;j++){
// BSD_variable_order[j] = new int [parameter_input_bit_width];
// }
...
...
@@ -1370,12 +1394,12 @@ 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
);
//
print_circuit(BDD,most_influence);
if
(
circuit_accuracy
>
0
.
9999
)
print_circuit
(
BDD
,
most_influence
,
start_depth
,
start_node_index_string
);
delete
[]
test_input_data
;
for
(
int
vi
=
0
;
vi
<
parameter_input_bit_width
;
vi
++
){
BSD_variable_order
[
0
][
vi
]
=
most_influence
[
vi
];
BSD_variable_order
[
vi
]
=
most_influence
[
vi
];
}
//GLOBAL_BDD_nodes += total_nodes_amount;
//GLOBAL_BDD_split_nodes += total_split_nodes;
...
...
src/BSD_top.h
View file @
9aee67a1
...
...
@@ -4,7 +4,7 @@
//电路的parameter Circuit_parameter
int
circuit_index
=
9999
;
//电路编号
extern
const
int
parameter_max_orders
=
2
;
extern
const
int
parameter_max_orders
=
1
;
...
...
@@ -22,13 +22,11 @@ int GLOBAL_BDD_split_nodes;
int
GLOBAL_train_time
;
int
GLOBAL_program_time
;
int
*
start_order
;
bool
**
file_inputs
;
//待优化变量
int
**
variable_order
;
int
**
multi_
variable_order
;
int
variable_order_number
;
int
BSD_execute
(
int
variable_order_number
,
int
**
variable_order
,
int
partition_depth
,
int
partition_parts
,
int
order_num
,
bool
*
output_partition_set
);
//bool truth_table [1024*1024];
...
...
@@ -71,7 +69,28 @@ uint64_t* io_generator_function_vec(uint64_t* input_data, uint64_t* output_data)
return
output_data
;
}
#endif
class
node_index
{
public
:
int
node_depth
;
int
root_node_index
;
int
*
expand_input_bit_index
;
bool
*
expand_input_bit_data
;
node_index
(){
expand_input_bit_index
=
new
int
[
parameter_input_bit_width
];
expand_input_bit_data
=
new
bool
[
parameter_input_bit_width
];
}
~
node_index
(){
delete
[]
expand_input_bit_index
;
delete
[]
expand_input_bit_data
;
}
};
int
default_start_node_number
;
node_index
*
default_start_node_index
;
int
BSD_execute
(
int
start_node_number
,
node_index
*
start_node_index
,
int
variable_order_number
,
int
*
variable_order
);
#include"BSD.h"
#include"next_layer_bit.h"
...
...
@@ -113,10 +132,20 @@ void set_default(){
GLOBAL_BDD_nodes
=
0
;
GLOBAL_BDD_split_nodes
=
0
;
default_start_order
=
new
int
[
parameter_input_bit_width
];
default_partition_set
=
new
bool
[
parameter_output_bit_width
];
start_order
=
new
int
[
parameter_in
put_bit_width
];
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
)
default_partition_set
=
new
bool
[
parameter_output_bit_width
];
default_start_node_index
=
new
node_index
[
parameter_out
put_bit_width
];
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
)
{
default_partition_set
[
i
]
=
1
;
}
default_start_node_number
=
parameter_output_bit_width
;
for
(
int
i
=
0
;
i
<
default_start_node_number
;
i
++
){
default_start_node_index
[
i
].
node_depth
=
0
;
default_start_node_index
[
i
].
root_node_index
=
i
;
for
(
int
j
=
0
;
j
<
parameter_input_bit_width
;
j
++
){
default_start_node_index
[
i
].
expand_input_bit_index
[
j
]
=
0
;
default_start_node_index
[
i
].
expand_input_bit_data
[
j
]
=
0
;
}
}
//for(int i=0;i<parameter_output_bit_width;i++)
default_partition_set
[
0
]
=
1
;
...
...
@@ -180,72 +209,269 @@ void set_default(){
}
BSD_features
BSD_features_0
;
//double variable_features[parameter_input_bit_width];
int
search_order
(
int
search_iterations
,
bool
*
partition_set
,
int
start_order_depth
,
int
*
start_order
);
int
search_order
(
int
start_node_number
,
int
start_node_depth
,
node_index
*
start_node_index
,
int
search_iterations
,
int
*
start_order
);
int
search_reward
(
BSD_features
BSD_features_0
);
int
search_partition
(
int
start_order_depth
,
int
*
start_order
);
int
search_partition
(
int
start_node_number
,
int
start_node_depth
,
node_index
*
start_node_index
,
int
*
start_order
);
int
search_partition
(
int
start_node_number
=
default_start_node_number
,
int
start_node_depth
=
0
,
node_index
*
start_node_index
=
default_start_node_index
,
int
*
start_order
=
default_start_order
){
int
search_order_times
=
2
;
int
search_partition
(
int
start_order_depth
,
int
*
start_order
){
random_device
rddd
;
mt19937
gen
(
rddd
());
int
max_partition_parts
=
min
(
10
,
int
(
parameter_output_bit_width
)
+
1
);
int
best_partition_parts
=
1
;
random_device
rd
;
mt19937
gen
(
rd
());
int
max_partition_parts
=
start_node_number
;
int
best_partition_parts
=
max_partition_parts
;
int
best_area
=
999999
;
bool
**
best_partition_sets
=
new
bool
*
[
max_partition_parts
];
bool
**
partition_sets
=
new
bool
*
[
max_partition_parts
];
bool
**
best_partition_sets
=
new
bool
*
[
max_partition_parts
];
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
partition_sets
[
i
]
=
new
bool
[
max_partition_parts
];
best_partition_sets
[
i
]
=
new
bool
[
max_partition_parts
];
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
partition_sets
[
i
][
j
]
=
0
;
best_partition_sets
[
i
][
j
]
=
0
;
}
partition_sets
[
i
][
i
]
=
1
;
best_partition_sets
[
i
][
i
]
=
1
;
}
int
*
area_parts
=
new
int
[
max_partition_parts
];
int
*
best_area_parts
=
new
int
[
max_partition_parts
];
int
area
=
0
;
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
best_partition_sets
[
i
]
=
new
bool
[
parameter_output_bit_width
];
cout
<<
"Partition_set ["
<<
i
<<
"] "
;
int
start_node_partition
=
0
;
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
cout
<<
partition_sets
[
i
][
j
];
if
(
partition_sets
[
i
][
j
]){
start_node_partition
++
;
}
}
cout
<<
endl
;
node_index
*
start_node_index_partition
=
new
node_index
[
start_node_partition
];
int
zi
=
0
;
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
if
(
partition_sets
[
i
][
j
]){
start_node_index_partition
[
zi
]
=
start_node_index
[
j
];
}
}
area_parts
[
i
]
=
search_order
(
start_node_partition
,
start_node_depth
,
start_node_index_partition
,
search_order_times
,
start_order
);
area
+=
area_parts
[
i
];
}
if
(
area
<
best_area
){
best_area
=
area
;
best_partition_parts
=
max_partition_parts
;
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
best_partition_sets
[
i
][
j
]
=
partition_sets
[
i
][
j
];
}
best_area_parts
[
i
]
=
area_parts
[
i
];
}
}
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"Design Area: "
<<
area
<<
endl
;
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
cout
<<
"partition "
<<
i
<<
" "
<<
area_parts
[
i
]
<<
endl
;
}
char
*
start_node_index_string
=
new
char
[
parameter_output_bit_width
];
ofstream
function_top_file
(
"rtl/function_top.v"
);
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
parameter_output_bit_width
;
j
++
){
if
(
best_partition_sets
[
i
][
j
]){
start_node_index_string
[
j
]
=
'1'
;
}
else
{
start_node_index_string
[
j
]
=
'0'
;
}
}
function_top_file
<<
"`include
\"
function_layer_"
<<
start_node_depth
<<
"_nodes_"
<<
start_node_index_string
<<
".v
\"
"
<<
endl
;
}
function_top_file
<<
endl
;
function_top_file
<<
"module function_top (i,o);"
<<
endl
<<
endl
;
function_top_file
<<
"input ["
<<
parameter_input_bit_width
-
1
<<
":0] i;"
<<
endl
;
function_top_file
<<
"output ["
<<
parameter_output_bit_width
-
1
<<
":0] o;"
<<
endl
<<
endl
;
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
function_top_file
<<
"wire ["
<<
parameter_output_bit_width
-
1
<<
":0] o_"
<<
i
<<
";"
<<
endl
;
}
function_top_file
<<
endl
;
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
parameter_output_bit_width
;
j
++
){
if
(
best_partition_sets
[
i
][
j
]){
start_node_index_string
[
j
]
=
'1'
;
}
else
{
start_node_index_string
[
j
]
=
'0'
;
}
}
function_top_file
<<
"function_layer_"
<<
start_node_depth
<<
"_nodes_"
<<
start_node_index_string
<<
" part"
<<
i
<<
" (.i(i),.o_index(o_"
<<
i
<<
"));"
<<
endl
;
}
function_top_file
<<
"endmodule"
<<
endl
;
function_top_file
.
close
();
cout
<<
"Best Design Area: "
<<
best_area
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
for
(
int
partition_parts
=
max_partition_parts
-
1
;
partition_parts
>
0
;
partition_parts
--
){
bool
**
partition_sets
=
new
bool
*
[
partition_parts
];
int
*
area_parts
=
new
int
[
partition_parts
];
int
area
=
0
;
for
(
int
i
=
0
;
i
<
partition_parts
;
i
++
){
partition_sets
[
i
]
=
new
bool
[
parameter_output_bit_width
];
cout
<<
"Partition_set ["
<<
i
<<
"] "
;
for
(
int
j
=
0
;
j
<
parameter_output_bit_width
;
j
++
){
if
(
int
(
j
/
double
(
double
(
parameter_output_bit_width
)
/
double
(
partition_parts
)))
==
i
){
partition_sets
[
i
][
j
]
=
1
;
}
else
if
(
(
i
==
partition_parts
-
1
)
&&
(
j
>=
(
i
+
1
)
*
double
(
double
(
parameter_output_bit_width
)
/
double
(
partition_parts
)))){
partition_sets
[
i
][
j
]
=
1
;
int
use_part
;
for
(
use_part
=
0
;
use_part
<
partition_parts
;
use_part
++
){
bool
merge_success
=
0
;
for
(
int
merge_part
=
use_part
+
1
;
merge_part
<
partition_parts
;
merge_part
++
){
//改变Partition Set
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
if
(
i
<
merge_part
){
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
partition_sets
[
i
][
j
]
=
best_partition_sets
[
i
][
j
];
}
}
else
if
(
i
<
partition_parts
){
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
partition_sets
[
i
][
j
]
=
best_partition_sets
[
i
+
1
][
j
];
}
}
else
{
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
partition_sets
[
i
][
j
]
=
0
;
}
}
}
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
if
(
!
partition_sets
[
use_part
][
j
])
partition_sets
[
use_part
][
j
]
=
best_partition_sets
[
merge_part
][
j
];
}
else
{
partition_sets
[
i
][
j
]
=
0
;
//执行对比
int
area
=
0
;
for
(
int
i
=
0
;
i
<
partition_parts
;
i
++
){
if
(
i
>=
merge_part
){
area_parts
[
i
]
=
best_area_parts
[
i
+
1
];
area
+=
area_parts
[
i
];
}
else
{
cout
<<
"Partition_set ["
<<
i
<<
"] "
;
int
start_node_partition
=
0
;
for
(
int
j
=
0
;
j
<
partition_parts
;
j
++
){
cout
<<
partition_sets
[
i
][
j
];
if
(
partition_sets
[
i
][
j
]){
start_node_partition
++
;
}
}
cout
<<
endl
;
node_index
*
start_node_index_partition
=
new
node_index
[
start_node_partition
];
int
zi
=
0
;
for
(
int
j
=
0
;
j
<
partition_parts
;
j
++
){
if
(
partition_sets
[
i
][
j
]){
start_node_index_partition
[
zi
]
=
start_node_index
[
j
];
zi
++
;
}
}
area_parts
[
i
]
=
search_order
(
start_node_partition
,
start_node_depth
,
start_node_index_partition
,
search_order_times
,
start_order
);
area
+=
area_parts
[
i
];
}
}
cout
<<
partition_sets
[
i
][
j
];
if
(
area
<
best_area
){
best_area
=
area
;
best_partition_parts
=
partition_parts
;
for
(
int
i
=
0
;
i
<
max_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
best_partition_sets
[
i
][
j
]
=
partition_sets
[
i
][
j
];
}
best_area_parts
[
i
]
=
area_parts
[
i
];
}
merge_success
=
1
;
}
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"Design Area: "
<<
area
<<
endl
;
for
(
int
i
=
0
;
i
<
partition_parts
;
i
++
){
cout
<<
"partition "
<<
i
<<
" "
;
for
(
int
j
=
0
;
j
<
max_partition_parts
;
j
++
){
cout
<<
partition_sets
[
i
][
j
];
}
cout
<<
" "
<<
area_parts
[
i
]
<<
endl
;
}
cout
<<
"Best Design Area: "
<<
best_area
<<
endl
;
char
*
start_node_index_string
=
new
char
[
parameter_output_bit_width
];
ofstream
function_top_file
(
"rtl/function_top.v"
);
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
parameter_output_bit_width
;
j
++
){
if
(
best_partition_sets
[
i
][
j
]){
start_node_index_string
[
j
]
=
'1'
;
}
else
{
start_node_index_string
[
j
]
=
'0'
;
}
}
function_top_file
<<
"`include
\"
function_layer_"
<<
start_node_depth
<<
"_nodes_"
<<
start_node_index_string
<<
".v
\"
"
<<
endl
;
}
function_top_file
<<
endl
;
function_top_file
<<
"module function_top (i,o);"
<<
endl
<<
endl
;
function_top_file
<<
"input ["
<<
parameter_input_bit_width
-
1
<<
":0] i;"
<<
endl
;
function_top_file
<<
"output ["
<<
parameter_output_bit_width
-
1
<<
":0] o;"
<<
endl
<<
endl
;
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
function_top_file
<<
"wire ["
<<
parameter_output_bit_width
-
1
<<
":0] o_"
<<
i
<<
";"
<<
endl
;
}
function_top_file
<<
endl
;
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
for
(
int
j
=
0
;
j
<
parameter_output_bit_width
;
j
++
){
if
(
best_partition_sets
[
i
][
j
]){
start_node_index_string
[
j
]
=
'1'
;
}
else
{
start_node_index_string
[
j
]
=
'0'
;
}
}
function_top_file
<<
"function_layer_"
<<
start_node_depth
<<
"_nodes_"
<<
start_node_index_string
<<
" part"
<<
i
<<
" (.i(i),.o_index(o_"
<<
i
<<
"));"
<<
endl
;
}
function_top_file
<<
endl
;
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
){
int
position_a
=
0
;
for
(
int
j
=
0
;
j
<
best_partition_parts
;
j
++
){
if
(
best_partition_sets
[
j
][
i
]
==
1
){
position_a
=
j
;
break
;
}
}
function_top_file
<<
"assign o["
<<
i
<<
"] = o_"
<<
position_a
<<
"["
<<
i
<<
"];"
<<
endl
;
}
function_top_file
<<
"endmodule"
<<
endl
;
function_top_file
.
close
();
cout
<<
"###########################################################################"
<<
endl
;
if
(
merge_success
)
break
;
}
cout
<<
endl
;
area_parts
[
i
]
=
search_order
(
10
,
partition_sets
[
i
],
start_order_depth
,
start_order
);
area
+=
area_parts
[
i
];
}
if
(
area
<
best_area
){
best_area
=
area
;
if
(
merge_success
)
break
;
}
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"Design Area: "
<<
area
<<
endl
;
for
(
int
i
=
0
;
i
<
partition_parts
;
i
++
){
cout
<<
area_parts
[
i
]
<<
endl
;
}
cout
<<
"Best Design Area: "
<<
best_area
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
if
(
use_part
==
(
partition_parts
-
1
))
break
;
}
cout
<<
"###########################################################################"
<<
endl
;
cout
<<
"Best Design Area: "
<<
best_area
<<
endl
;
cout
<<
"###########################################################################"
<<
endl
;
for
(
int
i
=
0
;
i
<
best_partition_parts
;
i
++
){
cout
<<
best_area_parts
[
i
]
<<
endl
;
}
cout
<<
"###########################################################################"
<<
endl
;
};
int
BSD_execute
(
int
variable_order_number
,
int
**
variable_order
,
int
partition_depth
,
int
partition_parts
,
int
order_num
,
bool
*
output_partition_set
){
int
BSD_execute
(
int
start_node_number
,
node_index
*
start_node_index
,
int
variable_order_number
,
int
*
variable_order
){
cout
<<
"BSD execute start"
<<
endl
;
BDD_class
BDD_class_main
;
cout
<<
"This variable order: "
<<
variable_order_number
<<
endl
;
for
(
int
j
=
0
;
j
<
parameter_max_orders
;
j
++
){
//cout<<"j"<<j<<endl;
BDD_class_main
.
BSD_variable_order
[
j
]
=
new
int
[
parameter_input_bit_width
];
}
BDD_class_main
.
output_partition_set
=
output_partition_set
;
//BDD_class_main.output_partition_set = output_partition_set;
BDD_class_main
.
which_demo_function
=
GLOBAL_which_demo_function
;
//for (int vi=0;vi<partition_parts;vi++){
// BDD_class_main.BSD_variable_order_number = variable_order_number;
...
...
@@ -256,23 +482,20 @@ int BSD_execute(int variable_order_number,int** variable_order, int partition_de
// cout<<endl;
//}
//cout<<endl;
BDD_class_main
.
order_num
=
order_num
;
for
(
int
vi
=
0
;
vi
<
parameter_max_orders
;
vi
++
){
BDD_class_main
.
BSD_variable_order_number
=
variable_order_number
;
for
(
int
i
=
0
;
i
<
variable_order_number
;
i
++
){
BDD_class_main
.
BSD_variable_order
[
vi
][
i
]
=
variable_order
[
vi
]
[
i
];
cout
<<
BDD_class_main
.
BSD_variable_order
[
vi
][
i
]
<<
" "
;
BDD_class_main
.
BSD_variable_order
[
i
]
=
variable_order
[
i
];
cout
<<
BDD_class_main
.
BSD_variable_order
[
i
]
<<
" "
;
}
cout
<<
endl
;
}
cout
<<
endl
;
BDD_class_main
.
start_depth
=
0
;
BDD_class_main
.
BDD_id
=
0
;
BDD_class_main
.
how_many_start_nodes
=
parameter_output_bit_width
;
BDD_class_main
.
how_many_start_nodes
=
start_node_number
;
BDD_class_main
.
start_nodes
=
new
BDD_node
[
BDD_class_main
.
how_many_start_nodes
];
for
(
int
zi
=
0
;
zi
<
BDD_class_main
.
how_many_start_nodes
;
zi
++
){
BDD_class_main
.
start_node_index
[
zi
]
=
start_node_index
[
zi
];
BDD_class_main
.
start_nodes
[
zi
].
which_bit_output
=
zi
;
BDD_class_main
.
start_nodes
[
zi
].
which_root_node
=
zi
;
BDD_class_main
.
start_nodes
[
zi
].
which_root_node_all
[
BDD_class_main
.
start_nodes
[
zi
].
which_root_node
]
=
1
;
...
...
@@ -283,8 +506,8 @@ int BSD_execute(int variable_order_number,int** variable_order, int partition_de
BDD_class_main
.
BDD_width_each_layer
[
zi
]
=
0
;
}
BDD_class_main
.
partition_depth
=
partition_depth
;
BDD_class_main
.
partition_parts
=
partition_parts
;
BDD_class_main
.
partition_depth
=
1000000
;
BDD_class_main
.
partition_parts
=
1
;
BDD_class_main
.
BDD_FULL_PROCESS
();
...
...
@@ -293,19 +516,15 @@ int BSD_execute(int variable_order_number,int** variable_order, int partition_de
BSD_features_0
.
accuracy_layers
[
zi
]
=
BDD_class_main
.
accuracy_each_layer
[
zi
];
BSD_features_0
.
BDD_width_each_layer
[
zi
]
=
BDD_class_main
.
BDD_width_each_layer
[
zi
];
}
if
(
partition_depth
>
parameter_input_bit_width
){
for
(
int
zj
=
0
;
zj
<
parameter_max_orders
;
zj
++
){
if
(
BDD_class_main
.
partition_depth
>
parameter_input_bit_width
){
for
(
int
zi
=
0
;
zi
<
parameter_input_bit_width
;
zi
++
){
variable_order
[
z
j
][
z
i
]
=
BDD_class_main
.
most_influence
[
zi
];
variable_order
[
zi
]
=
BDD_class_main
.
most_influence
[
zi
];
}
}
}
else
{
for
(
int
zj
=
0
;
zj
<
parameter_max_orders
;
zj
++
){
for
(
int
zi
=
0
;
zi
<
parameter_input_bit_width
;
zi
++
){
variable_order
[
z
j
][
zi
]
=
BDD_class_main
.
BSD_variable_order
[
0
]
[
zi
];
variable_order
[
z
i
]
=
BDD_class_main
.
BSD_variable_order
[
zi
];
}
}
}
BSD_features_0
.
BSD_depth
=
BDD_class_main
.
total_BDD_depth
+
1
;
...
...
@@ -332,22 +551,18 @@ int search_reward(BSD_features BSD_features_0){
};
int
search_order
(
int
search_iterations
=
parameter_search_iterations
,
bool
*
output_partition_set
=
default_partition_set
,
int
start_order_depth
=
0
,
int
*
start_order
=
start_order
){
//ofstream result_0("result_0_20bit",ios::app);
//ofstream result_10("result_10_20bit",ios::app);
//ofstream result_100("result_100_20bit",ios::app);
//ofstream result_1000("result_1000_20bit",ios::app);
variable_order
=
new
int
*
[
parameter_max_orders
];
int
search_order
(
int
start_node_number
=
default_start_node_number
,
int
start_node_depth
=
0
,
node_index
*
start_node_index
=
default_start_node_index
,
int
search_iterations
=
parameter_search_iterations
,
int
*
start_order
=
default_start_order
){
multi_variable_order
=
new
int
*
[
parameter_max_orders
];
for
(
int
vi
=
0
;
vi
<
parameter_max_orders
;
vi
++
){
variable_order
[
vi
]
=
new
int
[
parameter_input_bit_width
];
multi_
variable_order
[
vi
]
=
new
int
[
parameter_input_bit_width
];
for
(
int
vj
=
0
;
vj
<
parameter_input_bit_width
;
vj
++
)
variable_order
[
vi
][
vj
]
=
0
;
multi_
variable_order
[
vi
][
vj
]
=
0
;
}
int
best_area
=
9999999
;
int
best_reward
=
9999999
;
int
best_area_depth
=
2
;
int
best_area_depth
=
0
;
int
**
best_variable_order
;
int
*
best_BDD_split_nodes
=
new
int
[
parameter_input_bit_width
];
...
...
@@ -395,24 +610,7 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
GLOBAL_BDD_id_number
+=
1
;
//if(i==1){
// result_0 << best_area << endl;
// best_area_0 = best_area;
//}
//else if(i==11){
// result_10 << best_area << endl;
// best_area_10 = best_area;
//
//}
//else if(i==101){
// result_100 << best_area << endl;
// best_area_100 = best_area;
//
//}
//else if(i==999){
// result_1000 << best_area << endl;
//}
int
parameter_learning_rate
=
2
;
if
(
best_area
>
10000
){
parameter_learning_rate
=
6
;
...
...
@@ -434,14 +632,14 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
for
(
int
vj
=
0
;
vj
<
parameter_max_orders
;
vj
++
){
if
(
i
==
0
){
for
(
int
vi
=
0
;
vi
<
best_area_depth
;
vi
++
){
variable_order
[
vj
][
vi
]
=
start_order
[
vi
];
cout
<<
variable_order
[
vj
][
vi
]
<<
" "
;
multi_
variable_order
[
vj
][
vi
]
=
start_order
[
vi
];
cout
<<
multi_
variable_order
[
vj
][
vi
]
<<
" "
;
}
}
else
{
for
(
int
vi
=
0
;
vi
<
best_area_depth
;
vi
++
){
variable_order
[
vj
][
vi
]
=
best_variable_order
[
vj
][
vi
];
cout
<<
variable_order
[
vj
][
vi
]
<<
" "
;
multi_
variable_order
[
vj
][
vi
]
=
best_variable_order
[
vj
][
vi
];
cout
<<
multi_
variable_order
[
vj
][
vi
]
<<
" "
;
}
}
cout
<<
endl
;
...
...
@@ -501,13 +699,13 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
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
];
int
x
=
multi_
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
;
multi_
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
)];
multi_variable_order
[
vv
][(
num_a
+
vj
)
%
int
(
best_area_depth
)]
=
multi_
variable_order
[
vv
][(
num_a
+
vj
+
1
)
%
int
(
best_area_depth
)];
}
}
...
...
@@ -553,7 +751,7 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
//}
if
(
i
<
parameter_max_orders
){
//parameter_max_samples = int(parameter_max_samples/10); //BSD每一个节点最多进行多少次采样
reward
=
BSD_execute
(
start_
order_depth
,
variable_order
,
partition_depth
,
partition_parts
,
0
,
output_partition_set
);
reward
=
BSD_execute
(
start_
node_number
,
start_node_index
,
start_node_depth
,
multi_variable_order
[
order_num
]
);
//parameter_max_samples *= 10; //BSD每一个节点最多进行多少次采样
}
//else if (i<parameter_max_orders){
...
...
@@ -561,13 +759,11 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
//}
else
if
(
i
==
search_iterations
-
1
){
parameter_early_stop_split_nodes
=
9999999
;
// area = BSD_execute(best_area_depth,variable_order,partition_depth,partition_parts,order_num,output_partition_set);
reward
=
BSD_execute
(
best_area_depth
,
best_variable_order
,
partition_depth
,
partition_parts
,
order_num
,
output_partition_set
);
//area = BSD_execute(parameter_input_bit_width,best_variable_order,10000,best_partition_parts,best_order_num,output_partition_set);
reward
=
BSD_execute
(
start_node_number
,
start_node_index
,
best_area_depth
,
best_variable_order
[
order_num
]);
break
;
}
else
{
reward
=
BSD_execute
(
best_area_depth
,
variable_order
,
partition_depth
,
partition_parts
,
order_num
,
output_partition_set
);
reward
=
BSD_execute
(
start_node_number
,
start_node_index
,
best_area_depth
,
multi_variable_order
[
order_num
]
);
}
...
...
@@ -624,7 +820,7 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
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
];
best_variable_order
[
replace_order
][
vi
]
=
multi_variable_order
[
order_num
][
vi
];
cout
<<
best_variable_order
[
replace_order
][
vi
]
<<
" "
;
best_BDD_split_nodes
[
vi
]
=
BSD_features_0
.
BSD_area_layers
[
vi
];
}
...
...
@@ -638,10 +834,10 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
if
(
best_rewards
[
zi
]
==
best_reward
)
best_order_num
=
zi
;
}
if
(
best_reward_max
<
1000
)
parameter_early_stop_split_nodes
=
4000
;
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
4
);
if
(
best_reward_max
<
1000
)
parameter_early_stop_split_nodes
=
4000
;
else
parameter_early_stop_split_nodes
=
int
(
best_reward_max
*
4
);
}
else
{
best_iteration
=
i
;
...
...
@@ -656,7 +852,7 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
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
];
best_variable_order
[
replace_order
][
vi
]
=
multi_variable_order
[
order_num
][
vi
];
cout
<<
best_variable_order
[
replace_order
][
vi
]
<<
" "
;
best_BDD_split_nodes
[
vi
]
=
BSD_features_0
.
BSD_area_layers
[
vi
];
}
...
...
@@ -713,16 +909,16 @@ int search_order(int search_iterations = parameter_search_iterations ,bool* outp
//area = BSD_execute(parameter_input_bit_width,best_variable_order,10000,best_partition_parts,best_order_num,output_partition_set);
//
delete [] best_BDD_split_nodes ;
//
delete [] best_areas ;
//
delete [] best_rewards ;
//
delete [] best_area_depths;
//
for (int vi=0;vi<parameter_max_orders;vi++){
//
delete [] variable_order[vi];
//
delete [] best_variable_order[vi];
//
}
//
delete [] variable_order;
//
delete [] best_variable_order;
//
delete [] best_BDD_split_nodes ;
//
delete [] best_areas ;
//
delete [] best_rewards ;
//
delete [] best_area_depths;
//
for (int vi=0;vi<parameter_max_orders;vi++){
//
delete [] variable_order[vi];
//
delete [] best_variable_order[vi];
//
}
//
delete [] variable_order;
//
delete [] best_variable_order;
return
reward
;
};
src/next_layer_bit.h
View file @
9aee67a1
...
...
@@ -117,15 +117,15 @@ int BDD_class::next_bit_layer_single(int depth,int which_node_this_layer){
};
int
BDD_class
::
next_bit_layer
(
int
depth
,
int
order_num
){
int
BDD_class
::
next_bit_layer
(
int
depth
){
//cout<<"Depth: "<<depth<<" Order num: "<<BSD_variable_order_number<<endl;
if
((
depth
<
BSD_variable_order_number
)
){
for
(
int
i
=
depth
;
i
<
BSD_variable_order_number
;
i
++
){
if
(
!
has_been_unfold
[
BSD_variable_order
[
order_num
][
depth
]]){
most_influence
[
depth
]
=
BSD_variable_order
[
order_num
][
depth
];
if
(
!
has_been_unfold
[
BSD_variable_order
[
depth
]]){
most_influence
[
depth
]
=
BSD_variable_order
[
depth
];
has_been_unfold
[
most_influence
[
depth
]]
=
1
;
cout
<<
most_influence
[
depth
]
<<
endl
;
return
BSD_variable_order
[
order_num
][
depth
];
return
BSD_variable_order
[
depth
];
}
else
{
;
...
...
src/print_circuit.h
View file @
9aee67a1
int
BDD_class
::
print_circuit
(
BDD_node
**
BDD
,
int
*
most_influence
){
int
BDD_class
::
print_circuit
(
BDD_node
**
BDD
,
int
*
most_influence
,
int
node_depth
,
char
*
start_node_index_string
){
int
i
,
j
;
int
zi
;
char
output_file_name
[
100
];
//sprintf(output_file_name,"rtl/module_output_bit_%d.v",which_bit_output);
sprintf
(
output_file_name
,
"rtl/function_%d_id_%d.v"
,
circuit_index
,
BDD_id
);
// sprintf(output_file_name,"rtl/function_%d_id_%d.v",circuit_index,BDD_id);
sprintf
(
output_file_name
,
"rtl/function_layer_%d_nodes_%s.v"
,
node_depth
,
start_node_index_string
);
// string output_file_name << output_file_name_begin << which_bit_output << output_file_name_end;
...
...
@@ -134,9 +135,22 @@ int BDD_class::print_circuit(BDD_node** BDD,int* most_influence){
output_module_file
<<
"//total BDD nodes recursive = "
<<
total_nodes_amount_recursive
<<
endl
;
output_module_file
<<
"//total split modes recursive = "
<<
total_split_nodes_recursive
<<
endl
;
output_module_file
<<
"//train time = "
<<
train_time
<<
endl
;
output_module_file
<<
"module function_"
<<
circuit_index
<<
"_BDD_id_"
<<
BDD_id
<<
" (i,o);"
<<
endl
<<
endl
;
// output_module_file << "module function_"<<circuit_index<<"_BDD_id_"<<BDD_id<<" (i,o);"<<endl<<endl;
output_module_file
<<
"module function_layer_"
<<
node_depth
<<
"_nodes_"
<<
start_node_index_string
<<
" (i,o_index);"
<<
endl
<<
endl
;
output_module_file
<<
"input ["
<<
parameter_input_bit_width
-
1
<<
":0] i;"
<<
endl
;
output_module_file
<<
"output ["
<<
how_many_start_nodes
-
1
<<
":0] o;"
<<
endl
<<
endl
;
output_module_file
<<
"output ["
<<
parameter_output_bit_width
-
1
<<
":0] o_index;"
<<
endl
<<
endl
;
output_module_file
<<
"wire ["
<<
how_many_start_nodes
-
1
<<
":0] o;"
<<
endl
<<
endl
;
int
ij
=
0
;
for
(
int
i
=
0
;
i
<
parameter_output_bit_width
;
i
++
){
if
(
start_node_index_string
[
i
]
==
'1'
){
output_module_file
<<
"assign o_index["
<<
i
<<
"] = o["
<<
ij
<<
"];"
<<
endl
;
ij
++
;
}
}
output_module_file
<<
endl
;
if
(
partition_depth
==
total_BDD_depth
){
for
(
i
=
0
;
i
<
total_BDD_depth
+
1
;
i
++
){
...
...
src/top.h
View file @
9aee67a1
...
...
@@ -11,7 +11,7 @@ int parameter_output_bit_width = PO_WIDTH;
extern
const
int
parameter_search_iterations
=
10
;
//最大设计次数
extern
const
int
parameter_test_ios
=
10000
00
;
//测试要求多少样本
extern
const
int
parameter_test_ios
=
10000
;
//测试要求多少样本
extern
const
int
parameter_max_samples
=
64
*
100
;
//BSD每一个节点最多进行多少次采样,至少为64
extern
const
double
parameter_early_stop_accuracy
=
1
;
//允许的错误率,如果完全不允许,设为1;
//没有特殊需要不要设到<1,会慢一些。
...
...
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