|
1 | 1 | // use std::{alloc::Global, collections::HashMap, sync::Arc}; |
2 | | -// |
| 2 | +// |
3 | 3 | // use cs::utils::split_timestamp; |
4 | 4 | // pub use gpu_prover::allocator::host::ConcurrentStaticHostAllocator; |
5 | 5 | // use gpu_prover::circuit_type::{CircuitType, DelegationCircuitType}; |
|
26 | 26 | // merkle_trees::{DefaultTreeConstructor, MerkleTreeConstructor}, |
27 | 27 | // risc_v_simulator::cycle::{IMStandardIsaConfig, IWithoutByteAccessIsaConfigWithDelegation}, |
28 | 28 | // }; |
29 | | -// |
| 29 | +// |
30 | 30 | // use prover::{ |
31 | 31 | // definitions::OPTIMAL_FOLDING_PROPERTIES, |
32 | 32 | // prover_stages::Proof, |
|
37 | 37 | // worker::Worker, |
38 | 38 | // VectorMemoryImplWithRom, |
39 | 39 | // }; |
40 | | -// |
| 40 | +// |
41 | 41 | // use setups::{DelegationCircuitPrecomputations, MainCircuitPrecomputations}; |
42 | 42 | // use trace_and_split::{ |
43 | 43 | // fs_transform_for_memory_and_delegation_arguments, run_and_split_for_gpu, FinalRegisterValue, |
44 | 44 | // }; |
45 | | -// |
| 45 | +// |
46 | 46 | // use crate::{NUM_QUERIES, POW_BITS}; |
47 | | -// |
| 47 | +// |
48 | 48 | // pub fn initialize_host_allocator_if_needed() { |
49 | 49 | // if !ProverContext::is_global_host_allocator_initialized() { |
50 | 50 | // // allocate 8 x 1 GB ((1 << 8) << 22) of pinned host memory with 4 MB (1 << 22) chunking |
51 | 51 | // ProverContext::initialize_global_host_allocator(8, 1 << 8, 22).unwrap(); |
52 | 52 | // } |
53 | 53 | // } |
54 | | -// |
| 54 | +// |
55 | 55 | // pub fn create_default_prover_context<'a>() -> ProverContext { |
56 | 56 | // initialize_host_allocator_if_needed(); |
57 | 57 | // let mut prover_context_config = ProverContextConfig::default(); |
58 | 58 | // prover_context_config.allocation_block_log_size = 22; |
59 | | -// |
| 59 | +// |
60 | 60 | // let prover_context = ProverContext::new(&prover_context_config).unwrap(); |
61 | 61 | // prover_context |
62 | 62 | // } |
63 | | -// |
| 63 | +// |
64 | 64 | // pub fn gpu_prove_image_execution_for_machine_with_gpu_tracers< |
65 | 65 | // ND: NonDeterminismCSRSource<VectorMemoryImplWithRom>, |
66 | 66 | // C: MachineConfig, |
|
87 | 87 | // .lde_factor; |
88 | 88 | // assert_eq!(cycles_per_circuit + 1, trace_len); |
89 | 89 | // let max_cycles_to_run = num_instances_upper_bound * cycles_per_circuit; |
90 | | -// |
| 90 | +// |
91 | 91 | // // Guess circuit type based on the machine type. |
92 | 92 | // let circuit_type = match std::any::TypeId::of::<C>() { |
93 | 93 | // id if id == std::any::TypeId::of::<IMStandardIsaConfig>() => { |
|
104 | 104 | // panic!("Unsupported machine type"); |
105 | 105 | // } |
106 | 106 | // }; |
107 | | -// |
| 107 | +// |
108 | 108 | // let ( |
109 | 109 | // main_circuits_witness, |
110 | 110 | // inits_and_teardowns, |
|
117 | 117 | // non_determinism, |
118 | 118 | // worker, |
119 | 119 | // ); |
120 | | -// |
| 120 | +// |
121 | 121 | // let (num_paddings, inits_and_teardowns) = inits_and_teardowns; |
122 | | -// |
| 122 | +// |
123 | 123 | // let mut memory_trees = vec![]; |
124 | 124 | // // commit memory trees |
125 | 125 | // for (circuit_sequence, witness_chunk) in main_circuits_witness.iter().enumerate() { |
|
138 | 138 | // inits_and_teardowns, |
139 | 139 | // trace, |
140 | 140 | // }; |
141 | | -// |
| 141 | +// |
142 | 142 | // let mut transfer = TracingDataTransfer::new(circuit_type, data, prover_context)?; |
143 | 143 | // transfer.schedule_transfer(prover_context)?; |
144 | 144 | // let job = commit_memory( |
|
152 | 152 | // )?; |
153 | 153 | // job.finish()? |
154 | 154 | // }; |
155 | | -// |
| 155 | +// |
156 | 156 | // memory_trees.push(gpu_caps); |
157 | 157 | // } |
158 | | -// |
| 158 | +// |
159 | 159 | // // same for delegation circuits |
160 | 160 | // let mut delegation_memory_trees = vec![]; |
161 | | -// |
| 161 | +// |
162 | 162 | // let mut delegation_types: Vec<_> = delegation_circuits_witness.keys().copied().collect(); |
163 | 163 | // delegation_types.sort(); |
164 | | -// |
| 164 | +// |
165 | 165 | // for delegation_type in delegation_types.iter().cloned() { |
166 | 166 | // let els = &delegation_circuits_witness[&delegation_type]; |
167 | 167 | // let delegation_type_id = delegation_type as u32; |
|
198 | 198 | // }; |
199 | 199 | // per_tree_set.push(gpu_caps); |
200 | 200 | // } |
201 | | -// |
| 201 | +// |
202 | 202 | // delegation_memory_trees.push((delegation_type_id, per_tree_set)); |
203 | 203 | // } |
204 | | -// |
| 204 | +// |
205 | 205 | // let setup_caps = DefaultTreeConstructor::dump_caps(&risc_v_circuit_precomputations.setup.trees); |
206 | | -// |
| 206 | +// |
207 | 207 | // // commit memory challenges |
208 | 208 | // let memory_challenges_seed = fs_transform_for_memory_and_delegation_arguments( |
209 | 209 | // &setup_caps, |
210 | 210 | // &final_register_values, |
211 | 211 | // &memory_trees, |
212 | 212 | // &delegation_memory_trees, |
213 | 213 | // ); |
214 | | -// |
| 214 | +// |
215 | 215 | // let external_challenges = |
216 | 216 | // ExternalChallenges::draw_from_transcript_seed(memory_challenges_seed, true); |
217 | | -// |
| 217 | +// |
218 | 218 | // let input = final_register_values |
219 | 219 | // .iter() |
220 | 220 | // .map(|el| (el.value, split_timestamp(el.last_access_timestamp))) |
|
229 | 229 | // external_challenges.memory_argument.memory_argument_gamma, |
230 | 230 | // ); |
231 | 231 | // let mut delegation_argument_sum = Mersenne31Quartic::ZERO; |
232 | | -// |
| 232 | +// |
233 | 233 | // let mut aux_memory_trees = vec![]; |
234 | | -// |
| 234 | +// |
235 | 235 | // println!( |
236 | 236 | // "Producing proofs for main RISC-V circuit, {} proofs in total", |
237 | 237 | // main_circuits_witness.len() |
238 | 238 | // ); |
239 | | -// |
| 239 | +// |
240 | 240 | // let total_proving_start = std::time::Instant::now(); |
241 | | -// |
| 241 | +// |
242 | 242 | // let main_circuits_witness_len = main_circuits_witness.len(); |
243 | | -// |
| 243 | +// |
244 | 244 | // let mut gpu_setup_main = { |
245 | 245 | // let setup_row_major = &risc_v_circuit_precomputations.setup.ldes[0].trace; |
246 | 246 | // let mut setup_evaluations = Vec::with_capacity_in( |
|
279 | 279 | // setup.schedule_transfer(setup_evaluations, prover_context)?; |
280 | 280 | // setup |
281 | 281 | // }; |
282 | | -// |
| 282 | +// |
283 | 283 | // // now prove one by one |
284 | 284 | // let main_compiled_circuit = Arc::new(risc_v_circuit_precomputations.compiled_circuit.clone()); |
285 | 285 | // let mut main_proofs = vec![]; |
|
327 | 327 | // )?; |
328 | 328 | // job.finish()?.0.into_regular().unwrap() |
329 | 329 | // }; |
330 | | -// |
| 330 | +// |
331 | 331 | // memory_grand_product.mul_assign(&gpu_proof.memory_grand_product_accumulator); |
332 | 332 | // delegation_argument_sum.add_assign(&gpu_proof.delegation_argument_accumulator.unwrap()); |
333 | | -// |
| 333 | +// |
334 | 334 | // aux_memory_trees.push(gpu_proof.memory_tree_caps.clone()); |
335 | | -// |
| 335 | +// |
336 | 336 | // main_proofs.push(gpu_proof); |
337 | 337 | // } |
338 | | -// |
| 338 | +// |
339 | 339 | // drop(gpu_setup_main); |
340 | | -// |
| 340 | +// |
341 | 341 | // if main_circuits_witness_len > 0 { |
342 | 342 | // println!( |
343 | 343 | // "=== Total proving time: {:?} for {} circuits - avg: {:?}", |
|
346 | 346 | // total_proving_start.elapsed() / main_circuits_witness_len.try_into().unwrap() |
347 | 347 | // ) |
348 | 348 | // } |
349 | | -// |
| 349 | +// |
350 | 350 | // // all the same for delegation circuit |
351 | 351 | // let mut aux_delegation_memory_trees = vec![]; |
352 | 352 | // let mut delegation_proofs = vec![]; |
|
361 | 361 | // delegation_type_id, |
362 | 362 | // els.len() |
363 | 363 | // ); |
364 | | -// |
| 364 | +// |
365 | 365 | // let idx = delegation_circuits_precomputations |
366 | 366 | // .iter() |
367 | 367 | // .position(|el| el.0 == delegation_type_id) |
|
408 | 408 | // setup.schedule_transfer(setup_evaluations, prover_context)?; |
409 | 409 | // setup |
410 | 410 | // }; |
411 | | -// |
| 411 | +// |
412 | 412 | // let mut per_tree_set = vec![]; |
413 | | -// |
| 413 | +// |
414 | 414 | // let mut per_delegation_type_proofs = vec![]; |
415 | 415 | // for (_circuit_idx, el) in els.iter().enumerate() { |
416 | 416 | // delegation_proofs_count += 1; |
417 | | -// |
| 417 | +// |
418 | 418 | // // and prove |
419 | 419 | // let gpu_proof = { |
420 | 420 | // let trace = el.clone(); |
|
444 | 444 | // )?; |
445 | 445 | // job.finish()?.0.into_regular().unwrap() |
446 | 446 | // }; |
447 | | -// |
| 447 | +// |
448 | 448 | // memory_grand_product.mul_assign(&gpu_proof.memory_grand_product_accumulator); |
449 | 449 | // delegation_argument_sum.sub_assign(&gpu_proof.delegation_argument_accumulator.unwrap()); |
450 | | -// |
| 450 | +// |
451 | 451 | // per_tree_set.push(gpu_proof.memory_tree_caps.clone()); |
452 | | -// |
| 452 | +// |
453 | 453 | // per_delegation_type_proofs.push(gpu_proof); |
454 | 454 | // } |
455 | | -// |
| 455 | +// |
456 | 456 | // aux_delegation_memory_trees.push((delegation_type_id, per_tree_set)); |
457 | 457 | // delegation_proofs.push((delegation_type_id, per_delegation_type_proofs)); |
458 | | -// |
| 458 | +// |
459 | 459 | // drop(gpu_setup_delegation); |
460 | 460 | // } |
461 | | -// |
| 461 | +// |
462 | 462 | // if delegation_proofs_count > 0 { |
463 | 463 | // println!( |
464 | 464 | // "=== Total delegation proving time: {:?} for {} circuits - avg: {:?}", |
|
467 | 467 | // delegation_proving_start.elapsed() / delegation_proofs_count |
468 | 468 | // ) |
469 | 469 | // } |
470 | | -// |
| 470 | +// |
471 | 471 | // assert_eq!(memory_grand_product, Mersenne31Quartic::ONE); |
472 | 472 | // assert_eq!(delegation_argument_sum, Mersenne31Quartic::ZERO); |
473 | | -// |
| 473 | +// |
474 | 474 | // let setup_caps = DefaultTreeConstructor::dump_caps(&risc_v_circuit_precomputations.setup.trees); |
475 | | -// |
| 475 | +// |
476 | 476 | // // compare challenge |
477 | 477 | // let aux_memory_challenges_seed = fs_transform_for_memory_and_delegation_arguments( |
478 | 478 | // &setup_caps, |
479 | 479 | // &final_register_values, |
480 | 480 | // &aux_memory_trees, |
481 | 481 | // &aux_delegation_memory_trees, |
482 | 482 | // ); |
483 | | -// |
| 483 | +// |
484 | 484 | // assert_eq!(aux_memory_challenges_seed, memory_challenges_seed); |
485 | | -// |
| 485 | +// |
486 | 486 | // Ok((main_proofs, delegation_proofs, final_register_values)) |
487 | 487 | // } |
488 | | -// |
| 488 | +// |
489 | 489 | // pub fn trace_execution_for_gpu< |
490 | 490 | // ND: NonDeterminismCSRSource<VectorMemoryImplWithRom>, |
491 | 491 | // C: MachineConfig, |
|
507 | 507 | // ) { |
508 | 508 | // let cycles_per_circuit = domain_size - 1; |
509 | 509 | // let max_cycles_to_run = num_instances_upper_bound * cycles_per_circuit; |
510 | | -// |
| 510 | +// |
511 | 511 | // let delegation_factories = setups::delegation_factories_for_machine::<C, A>(); |
512 | | -// |
| 512 | +// |
513 | 513 | // let ( |
514 | 514 | // final_pc, |
515 | 515 | // main_circuits_witness, |
|
524 | 524 | // delegation_factories, |
525 | 525 | // worker, |
526 | 526 | // ); |
527 | | -// |
| 527 | +// |
528 | 528 | // println!( |
529 | 529 | // "Program finished execution with final pc = 0x{:08x} and final register state\n{}", |
530 | 530 | // final_pc, |
|
535 | 535 | // .collect::<Vec<_>>() |
536 | 536 | // .join(", ") |
537 | 537 | // ); |
538 | | -// |
| 538 | +// |
539 | 539 | // // we just need to chunk inits/teardowns |
540 | | -// |
| 540 | +// |
541 | 541 | // let init_and_teardown_chunks = chunk_lazy_init_and_teardown( |
542 | 542 | // main_circuits_witness.len(), |
543 | 543 | // cycles_per_circuit, |
544 | 544 | // &init_and_teardown_chunks, |
545 | 545 | // worker, |
546 | 546 | // ); |
547 | | -// |
| 547 | +// |
548 | 548 | // let main_circuits_witness = main_circuits_witness |
549 | 549 | // .into_iter() |
550 | 550 | // .map(|c| c.into()) |
551 | 551 | // .collect_vec(); |
552 | | -// |
| 552 | +// |
553 | 553 | // let init_and_teardown_chunks = ( |
554 | 554 | // init_and_teardown_chunks.0, |
555 | 555 | // init_and_teardown_chunks |
|
558 | 558 | // .map(|c| c.into()) |
559 | 559 | // .collect_vec(), |
560 | 560 | // ); |
561 | | -// |
| 561 | +// |
562 | 562 | // let delegation_circuits_witness = delegation_circuits_witness |
563 | 563 | // .into_iter() |
564 | 564 | // .map(|(k, v)| (k.into(), v.into_iter().map(|c| c.into()).collect_vec())) |
565 | 565 | // .collect(); |
566 | | -// |
| 566 | +// |
567 | 567 | // ( |
568 | 568 | // main_circuits_witness, |
569 | 569 | // init_and_teardown_chunks, |
|
0 commit comments