Skip to content

Commit 5703a80

Browse files
authored
Merge pull request #107 from iden3/adding-parallel-components
adding definition of parallel at component level
2 parents 9fb57b6 + 6bad344 commit 5703a80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+835
-291
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

circom/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "circom"
3-
version = "2.0.7"
3+
version = "2.0.8"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

code_producers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "code_producers"
3-
version = "2.0.7"
3+
version = "2.0.8"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

code_producers/src/c_elements/c_code_generator.rs

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ pub fn function_table() -> CInstruction {
205205
format!("{}", FUNCTION_TABLE)
206206
}
207207

208+
pub const FUNCTION_TABLE_PARALLEL: &str = "_functionTableParallel";
209+
pub fn function_table_parallel() -> CInstruction {
210+
format!("{}", FUNCTION_TABLE_PARALLEL)
211+
}
212+
208213
pub const SIGNAL_VALUES: &str = "signalValues";
209214
pub fn declare_signal_values() -> CInstruction {
210215
format!("FrElement* {} = {}->{}", SIGNAL_VALUES, CIRCOM_CALC_WIT, SIGNAL_VALUES)
@@ -282,6 +287,17 @@ pub fn my_subcomponents() -> CInstruction {
282287
format!("{}", MY_SUBCOMPONENTS)
283288
}
284289

290+
pub const MY_SUBCOMPONENTS_PARALLEL: &str = "mySubcomponentsParallel";
291+
pub fn declare_my_subcomponents_parallel() -> CInstruction {
292+
format!(
293+
"bool* {} = {}->componentMemory[{}].subcomponentsParallel",
294+
MY_SUBCOMPONENTS_PARALLEL, CIRCOM_CALC_WIT, CTX_INDEX
295+
)
296+
}
297+
pub fn my_subcomponents_parallel() -> CInstruction {
298+
format!("{}", MY_SUBCOMPONENTS_PARALLEL)
299+
}
300+
285301
pub const CIRCUIT_CONSTANTS: &str = "circuitConstants";
286302
pub fn declare_circuit_constants() -> CInstruction {
287303
format!("FrElement* {} = {}->{}", CIRCUIT_CONSTANTS, CIRCOM_CALC_WIT, CIRCUIT_CONSTANTS)
@@ -347,6 +363,15 @@ pub fn set_list(elems: Vec<usize>) -> String {
347363
set_string
348364
}
349365

366+
pub fn set_list_bool(elems: Vec<bool>) -> String {
367+
let mut set_string = "{".to_string();
368+
for elem in elems {
369+
set_string = format!("{}{},", set_string, elem);
370+
}
371+
set_string.pop();
372+
set_string.push('}');
373+
set_string
374+
}
350375

351376
pub fn add_return() -> String {
352377
"return;".to_string()
@@ -388,12 +413,11 @@ pub fn merge_code(instructions: Vec<String>) -> String {
388413
code
389414
}
390415

391-
pub fn collect_template_headers(instances: &TemplateList) -> Vec<String> {
416+
pub fn collect_template_headers(instances: &TemplateListParallel) -> Vec<String> {
392417
let mut template_headers = vec![];
393418
for instance in instances {
394419
let params_run = vec![declare_ctx_index(), declare_circom_calc_wit()];
395420
let params_run = argument_list(params_run);
396-
let run_header = format!("void {}_run({});", instance, params_run);
397421
let params_create = vec![
398422
declare_signal_offset(),
399423
declare_component_offset(),
@@ -402,9 +426,18 @@ pub fn collect_template_headers(instances: &TemplateList) -> Vec<String> {
402426
declare_component_father(),
403427
];
404428
let params_create = argument_list(params_create);
405-
let create_header = format!("void {}_create({});", instance, params_create);
406-
template_headers.push(create_header);
407-
template_headers.push(run_header);
429+
if instance.is_parallel{
430+
let run_header = format!("void {}_run_parallel({});", instance.name, params_run);
431+
let create_header = format!("void {}_create_parallel({});", instance.name, params_create);
432+
template_headers.push(create_header);
433+
template_headers.push(run_header);
434+
}
435+
if instance.is_not_parallel{
436+
let run_header = format!("void {}_run({});", instance.name, params_run);
437+
let create_header = format!("void {}_create({});", instance.name, params_create);
438+
template_headers.push(create_header);
439+
template_headers.push(run_header);
440+
}
408441
}
409442
template_headers
410443
}
@@ -645,16 +678,34 @@ pub fn generate_dat_file(dat_file: &mut dyn Write, producer: &CProducer) -> std:
645678
*/
646679
Ok(())
647680
}
648-
649-
pub fn generate_function_list(_producer: &CProducer, list: &TemplateList) -> String {
650-
let mut func_list = "".to_string();
681+
pub fn generate_function_list(_producer: &CProducer, list: &TemplateListParallel) -> (String, String) {
682+
let mut func_list= "".to_string();
683+
let mut func_list_parallel= "".to_string();
651684
if list.len() > 0 {
652-
func_list.push_str(&format!("\n{}_run", list[0]));
653-
for i in 1..list.len() {
654-
func_list.push_str(&format!(",\n{}_run", list[i]));
685+
if list[0].is_parallel{
686+
func_list_parallel.push_str(&format!("\n{}_run_parallel",list[0].name));
687+
}else{
688+
func_list_parallel.push_str(&format!("\nNULL"));
689+
}
690+
if list[0].is_not_parallel{
691+
func_list.push_str(&format!("\n{}_run",list[0].name));
692+
}else{
693+
func_list.push_str(&format!("\nNULL"));
655694
}
695+
for i in 1..list.len() {
696+
if list[i].is_parallel{
697+
func_list_parallel.push_str(&format!(",\n{}_run_parallel",list[i].name));
698+
}else{
699+
func_list_parallel.push_str(&format!(",\nNULL"));
700+
}
701+
if list[i].is_not_parallel{
702+
func_list.push_str(&format!(",\n{}_run",list[i].name));
703+
}else{
704+
func_list.push_str(&format!(",\nNULL"));
705+
}
706+
}
656707
}
657-
func_list
708+
(func_list, func_list_parallel)
658709
}
659710

660711
pub fn generate_message_list_def(_producer: &CProducer, message_list: &MessageList) -> Vec<String> {
@@ -852,10 +903,18 @@ pub fn generate_c_file(name: String, producer: &CProducer) -> std::io::Result<()
852903
let mut run_defs = collect_template_headers(producer.get_template_instance_list());
853904
code.append(&mut run_defs);
854905

906+
let (func_list_no_parallel, func_list_parallel) = generate_function_list(producer, producer.get_template_instance_list());
907+
855908
code.push(format!(
856909
"Circom_TemplateFunction _functionTable[{}] = {{ {} }};",
857910
producer.get_number_of_template_instances(),
858-
generate_function_list(producer, producer.get_template_instance_list())
911+
func_list_no_parallel,
912+
));
913+
914+
code.push(format!(
915+
"Circom_TemplateFunction _functionTableParallel[{}] = {{ {} }};",
916+
producer.get_number_of_template_instances(),
917+
func_list_parallel,
859918
));
860919

861920
code.push(format!("uint get_size_of_input_hashmap() {{return {};}}\n", len));

code_producers/src/c_elements/common/circom.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct Circom_Component {
4848
std::string componentName;
4949
u64 idFather;
5050
u32* subcomponents;
51+
bool* subcomponentsParallel;
5152
bool *outputIsSet; //one for each output
5253
std::mutex *mutexes; //one for each output
5354
std::condition_variable *cvs;

code_producers/src/c_elements/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use crate::components::*;
55
pub type CInstruction = String;
66
pub struct CProducer {
77
pub main_header: String,
8+
pub main_is_parallel: bool,
89
//pub fr_memory_size: usize, // depending of the prime; missing in build.rs
910
pub has_parallelism: bool,
1011
pub number_of_main_outputs: usize,
@@ -21,7 +22,7 @@ pub struct CProducer {
2122
pub main_input_list: InputList,
2223
pub witness_to_signal_list: SignalList,
2324
pub io_map: TemplateInstanceIOMap,
24-
pub template_instance_list: TemplateList,
25+
pub template_instance_list: TemplateListParallel,
2526
pub message_list: MessageList,
2627
pub field_tracking: Vec<String>,
2728
pub major_version: usize,
@@ -59,6 +60,7 @@ impl Default for CProducer {
5960
);
6061
CProducer {
6162
main_header: "Main_0".to_string(),
63+
main_is_parallel: false,
6264
has_parallelism: false,
6365
main_signal_offset: 1,
6466
prime: "21888242871839275222246405745257275088548364400416034343698204186575808495617"
@@ -88,7 +90,7 @@ impl Default for CProducer {
8890
size_32_bit: 8,
8991
size_32_shift: 5,
9092
io_map: my_map, //TemplateInstanceIOMap::new(),
91-
template_instance_list: [].to_vec(),
93+
template_instance_list: Vec::new(),
9294
major_version: 0,
9395
minor_version: 0,
9496
patch_version: 0,
@@ -111,6 +113,9 @@ impl CProducer {
111113
pub fn get_main_header(&self) -> &str {
112114
&self.main_header
113115
}
116+
pub fn get_main_is_parallel(&self) -> bool {
117+
self.main_is_parallel
118+
}
114119
pub fn get_has_parallelism(&self) -> bool {
115120
self.has_parallelism
116121
}
@@ -144,7 +149,7 @@ impl CProducer {
144149
pub fn get_io_map(&self) -> &TemplateInstanceIOMap {
145150
&self.io_map
146151
}
147-
pub fn get_template_instance_list(&self) -> &TemplateList {
152+
pub fn get_template_instance_list(&self) -> &TemplateListParallel {
148153
&self.template_instance_list
149154
}
150155
pub fn get_number_of_template_instances(&self) -> usize {

code_producers/src/components/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pub struct IODef {
1010
// It is an array that contains (name, start position, size)
1111
pub type InputList = Vec<(String, usize, usize)>;
1212
pub type TemplateList = Vec<String>;
13+
pub struct InfoParallel{
14+
pub name: String,
15+
pub is_parallel: bool,
16+
pub is_not_parallel: bool,
17+
}
18+
pub type TemplateListParallel = Vec<InfoParallel>;
1319
pub type SignalList = Vec<usize>;
1420
pub type InputOutputList = Vec<IODef>;
1521
pub type TemplateInstanceIOMap = BTreeMap<usize, InputOutputList>;

compiler/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "compiler"
3-
version = "2.0.7"
3+
version = "2.0.8"
44
authors = ["Costa Group UCM","iden3"]
55
edition = "2018"
66

0 commit comments

Comments
 (0)