Skip to content

Commit 736a6e2

Browse files
committed
fix format
1 parent 4fee136 commit 736a6e2

9 files changed

Lines changed: 52 additions & 98 deletions

File tree

circuit-std-rs/src/logup.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ impl LogUpSingleKeyTable {
328328

329329
assert_eq_rational(builder, &v_table, &v_query);
330330
}
331-
pub fn final_check_with_query_count<C: Config, B: RootAPI<C>>(&mut self, builder: &mut B, query_count: &[Variable]) {
331+
pub fn final_check_with_query_count<C: Config, B: RootAPI<C>>(
332+
&mut self,
333+
builder: &mut B,
334+
query_count: &[Variable],
335+
) {
332336
if self.table.is_empty() || self.query_keys.is_empty() {
333337
panic!("empty table or empty query");
334338
}
@@ -487,7 +491,11 @@ impl LogUpRangeProofTable {
487491
assert_eq_rational(builder, &v_table, &v_query);
488492
}
489493

490-
pub fn final_check_with_query_count<C: Config, B: RootAPI<C>>(&mut self, builder: &mut B, query_count: &[Variable]) {
494+
pub fn final_check_with_query_count<C: Config, B: RootAPI<C>>(
495+
&mut self,
496+
builder: &mut B,
497+
query_count: &[Variable],
498+
) {
491499
let alpha = builder.get_random_value();
492500
let inputs = self.query_keys.clone();
493501

expander_compiler/src/zkcuda/proving_system/expander/prove_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ where
3030
{
3131
let mut expander_circuit = kernel.layered_circuit().export_to_expander().flatten();
3232
expander_circuit.pre_process_gkr();
33-
33+
3434
let (max_num_input_var, max_num_output_var) = super::utils::max_n_vars(&expander_circuit);
3535
let prover_scratch =
3636
ProverScratchPad::<F>::new(max_num_input_var, max_num_output_var, mpi_world_size);

expander_compiler/src/zkcuda/proving_system/expander_no_oversubscribe/api_no_oversubscribe.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::zkcuda::proving_system::expander::structs::{
66
};
77
use crate::zkcuda::proving_system::expander_parallelized::client_utils::{
88
client_launch_server_and_setup, client_parse_args, client_send_witness_and_prove, wait_async,
9-
ClientHttpHelper, client_send_witness_and_prove_nowait
9+
ClientHttpHelper,
1010
};
1111
use crate::zkcuda::proving_system::{
1212
CombinedProof, ExpanderPCSDefered, ParallelizedExpander, ProvingSystem,
@@ -81,10 +81,7 @@ where
8181
{
8282
/// Lightweight prove that doesn't require computation_graph or prover_setup.
8383
/// Use this after setup() to allow releasing those large data structures before proving.
84-
pub fn prove_lightweight(
85-
device_memories: Vec<Vec<SIMDField<ZC::ECCConfig>>>,
86-
) {
84+
pub fn prove_lightweight(device_memories: Vec<Vec<SIMDField<ZC::ECCConfig>>>) {
8785
client_send_witness_and_prove::<ZC::GKRConfig, ZC::ECCConfig>(device_memories);
88-
// client_send_witness_and_prove_nowait::<ZC::GKRConfig, ZC::ECCConfig>(device_memories);
8986
}
9087
}

expander_compiler/src/zkcuda/proving_system/expander_no_oversubscribe/prove_impl.rs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ where
416416
FieldEngine<CircuitField = FBasic::CircuitField, ChallengeField = FBasic::ChallengeField>,
417417
T: Transcript,
418418
{
419-
420419
let input_vals_multi_copies = local_commitment_values_multi_copies
421420
.iter()
422421
.map(|local_commitment_values| {
@@ -714,9 +713,16 @@ fn wait_for_dependencies(task_name: &str, dependencies: &[String], my_rank: usiz
714713

715714
// Only log if actually waited
716715
if !waited_deps.is_empty() && my_rank % 8 == 0 {
717-
eprintln!("[RANK {}] Task {} waited for {} deps (longest: {:.1}s)",
718-
my_rank, task_name, waited_deps.len(),
719-
waited_deps.iter().map(|(_, t)| t).fold(0.0f64, |a, &b| a.max(b)));
716+
eprintln!(
717+
"[RANK {}] Task {} waited for {} deps (longest: {:.1}s)",
718+
my_rank,
719+
task_name,
720+
waited_deps.len(),
721+
waited_deps
722+
.iter()
723+
.map(|(_, t)| t)
724+
.fold(0.0f64, |a, &b| a.max(b))
725+
);
720726
}
721727
}
722728

@@ -800,8 +806,11 @@ where
800806

801807
if global_mpi_config.is_root() {
802808
eprintln!("========== SCHEDULER MODE ==========");
803-
eprintln!(" Schedule: {} ranks, max {} steps",
804-
schedule.rank_tasks.len(), schedule.max_steps());
809+
eprintln!(
810+
" Schedule: {} ranks, max {} steps",
811+
schedule.rank_tasks.len(),
812+
schedule.max_steps()
813+
);
805814
}
806815

807816
// Safety checks
@@ -855,7 +864,10 @@ where
855864
deps
856865
}
857866
Err(e) => {
858-
eprintln!("[RANK {}] ERROR: Failed to load dependencies: {}", my_rank, e);
867+
eprintln!(
868+
"[RANK {}] ERROR: Failed to load dependencies: {}",
869+
my_rank, e
870+
);
859871
HashMap::new()
860872
}
861873
}
@@ -882,7 +894,10 @@ where
882894
let mut task_mpi_configs: HashMap<String, Option<MPIConfig<'static>>> = HashMap::new();
883895

884896
if global_mpi_config.is_root() {
885-
eprintln!(" Pre-creating MPI subgroups for {} tasks...", all_unique_tasks.len());
897+
eprintln!(
898+
" Pre-creating MPI subgroups for {} tasks...",
899+
all_unique_tasks.len()
900+
);
886901
}
887902

888903
for task_name in &all_unique_tasks {
@@ -1044,7 +1059,6 @@ where
10441059
);
10451060

10461061
let gkr_end_state = if let Some(ref local_config) = local_mpi_config {
1047-
10481062
prove_kernel_gkr_no_oversubscribe::<GetFieldConfig<ZC>, GetTranscript<ZC>, ZC::ECCConfig>(
10491063
local_config,
10501064
&computation_graph.kernels()[template.kernel_id()],
@@ -1202,7 +1216,6 @@ where
12021216

12031217
// Step 1: Non-root subgroup roots send their results to rank 0
12041218
if i_am_subgroup_root && my_rank != 0 {
1205-
12061219
// Serialize the indexed structures (maintains template order)
12071220
let mut vals_bytes = Vec::new();
12081221
vals_per_template.serialize_into(&mut vals_bytes).unwrap();
@@ -1325,7 +1338,6 @@ where
13251338
all_proofs[template_idx] = received_all_proofs[template_idx].clone();
13261339
}
13271340
}
1328-
13291341
}
13301342

13311343
// Build final vals_ref and challenges in template order
@@ -1342,12 +1354,19 @@ where
13421354
}
13431355

13441356
let completed_templates = all_proofs.iter().filter(|p| p.is_some()).count();
1345-
eprintln!("Result collection: {}/{} templates, {} vals, {} challenges",
1346-
completed_templates, num_templates,
1347-
vals_ref_owned.len(), challenges_final.len());
1357+
eprintln!(
1358+
"Result collection: {}/{} templates, {} vals, {} challenges",
1359+
completed_templates,
1360+
num_templates,
1361+
vals_ref_owned.len(),
1362+
challenges_final.len()
1363+
);
13481364

13491365
if completed_templates < num_templates {
1350-
eprintln!("⚠️ WARNING: Only {}/{} templates completed!", completed_templates, num_templates);
1366+
eprintln!(
1367+
"⚠️ WARNING: Only {}/{} templates completed!",
1368+
completed_templates, num_templates
1369+
);
13511370
for (idx, val) in vals_per_template.iter().enumerate() {
13521371
if val.is_none() {
13531372
eprintln!(" Missing: Template {}", idx);

expander_compiler/src/zkcuda/proving_system/expander_parallelized/client_utils.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ where
112112
let mpi_size = if allow_oversubscribe {
113113
max_parallel_count
114114
} else {
115-
// 支持通过环境变量 ZKML_NUM_CPUS 覆盖 CPU 数量(用于 Docker 等环境)
116115
let num_cpus = std::env::var("ZKML_NUM_CPUS")
117116
.ok()
118117
.and_then(|s| s.parse().ok())
@@ -167,19 +166,6 @@ where
167166
proof
168167
}
169168

170-
171-
pub fn client_send_witness_and_prove_nowait<C, ECCConfig>(
172-
device_memories: Vec<Vec<SIMDField<ECCConfig>>>,
173-
)
174-
where
175-
C: GKREngine,
176-
ECCConfig: Config<FieldConfig = C::FieldConfig>,
177-
{
178-
let timer = Timer::new("prove", true);
179-
180-
SharedMemoryEngine::write_witness_to_shared_memory::<C::FieldConfig>(device_memories);
181-
ClientHttpHelper::request_prove();
182-
}
183169
/// Run an async function in a blocking context.
184170
#[inline(always)]
185171
pub fn wait_async<F, T>(f: F) -> T

expander_compiler/src/zkcuda/proving_system/expander_parallelized/cmd_utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ pub fn start_server<C: GKREngine>(
2424
fn parse_config<C: GKREngine>(mpi_size: usize) -> (String, String, String, String)
2525
where
2626
{
27-
// 支持通过环境变量强制启用 oversubscribe(用于 Docker 等 CPU ID 不连续的环境)
2827
let force_oversubscribe = std::env::var("ZKML_FORCE_OVERSUBSCRIBE").is_ok();
2928

30-
// 支持通过环境变量 ZKML_NUM_CPUS 覆盖 CPU 数量
3129
let num_cpus = std::env::var("ZKML_NUM_CPUS")
3230
.ok()
3331
.and_then(|s| s.parse().ok())

expander_compiler/src/zkcuda/proving_system/expander_parallelized/prove_impl.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use gkr_engine::{
44
ExpanderDualVarChallenge, ExpanderSingleVarChallenge, FieldEngine, GKREngine, MPIConfig,
55
MPIEngine, Transcript,
66
};
7-
use std::collections::HashMap;
8-
use std::fs;
97

108
use crate::{
119
frontend::{Config, SIMDField},
@@ -222,4 +220,4 @@ pub fn partition_single_gkr_claim_and_open_pcs_mpi<C: GKREngine>(
222220
transcript,
223221
);
224222
}
225-
}
223+
}

expander_compiler/src/zkcuda/proving_system/expander_parallelized/server_ctrl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::sync::Mutex as SyncMutex;
2828
use tokio::sync::{oneshot, Mutex};
2929

3030
pub static SERVER_IP: &str = "127.0.0.1";
31-
pub static SERVER_PORT: Lazy<SyncMutex<u16>> = Lazy::new(|| SyncMutex::new(5555));
31+
pub static SERVER_PORT: Lazy<SyncMutex<u16>> = Lazy::new(|| SyncMutex::new(3000));
3232

3333
pub fn parse_port_number() -> u16 {
3434
let mut port = SERVER_PORT.lock().unwrap();
@@ -298,12 +298,12 @@ where
298298
if global_mpi_config.is_root() {
299299
let (tx, rx) = oneshot::channel::<()>();
300300
state.shutdown_tx.lock().await.replace(tx);
301-
301+
302302
let app = Router::new()
303303
.route("/", post(root_main::<C, ECCConfig, S>))
304304
.route("/", get(|| async { "Expander Server is running" }))
305305
.with_state(state.clone());
306-
306+
307307
let ip: IpAddr = SERVER_IP.parse().expect("Invalid SERVER_IP");
308308
let port_val = port_number.parse::<u16>().unwrap_or_else(|e| {
309309
eprintln!("Error: Invalid port number '{port_number}'. {e}.");
@@ -379,7 +379,7 @@ pub struct ExpanderExecArgs {
379379
pub poly_commit: String,
380380

381381
/// The port number for the server to listen on.
382-
#[arg(short, long, default_value = "5555")]
382+
#[arg(short, long, default_value = "3000")]
383383
pub port_number: String,
384384

385385
/// Whether to batch PCS opening in proving.

expander_compiler/src/zkcuda/proving_system/expander_parallelized/shared_memory_utils.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,6 @@ use shared_memory::{Shmem, ShmemConf};
99

1010
use crate::circuit::config::Config;
1111

12-
/// 获取所有 expander_server 进程的内存占用(单位:MB)
13-
/// 返回 (VmRSS物理内存, VmSize虚拟内存)
14-
fn get_total_expander_memory_mb() -> (usize, usize) {
15-
use std::fs;
16-
use std::io::{BufRead, BufReader};
17-
18-
let mut total_rss_kb = 0usize;
19-
let mut total_vmsize_kb = 0usize;
20-
21-
// 遍历 /proc 目录
22-
if let Ok(entries) = fs::read_dir("/proc") {
23-
for entry in entries.flatten() {
24-
if let Ok(file_name) = entry.file_name().into_string() {
25-
// 只处理数字目录(进程PID)
26-
if file_name.chars().all(|c| c.is_ascii_digit()) {
27-
// 读取 /proc/[pid]/comm 检查进程名
28-
let comm_path = format!("/proc/{}/comm", file_name);
29-
if let Ok(comm) = fs::read_to_string(&comm_path) {
30-
if comm.trim() == "expander_server" {
31-
// 读取 /proc/[pid]/status 获取内存信息
32-
let status_path = format!("/proc/{}/status", file_name);
33-
if let Ok(file) = fs::File::open(&status_path) {
34-
let reader = BufReader::new(file);
35-
for line in reader.lines().flatten() {
36-
if line.starts_with("VmRSS:") {
37-
// VmRSS: 12345 kB (物理内存)
38-
if let Some(rss_str) = line.split_whitespace().nth(1) {
39-
if let Ok(rss_kb) = rss_str.parse::<usize>() {
40-
total_rss_kb += rss_kb;
41-
}
42-
}
43-
} else if line.starts_with("VmSize:") {
44-
// VmSize: 12345 kB (虚拟内存)
45-
if let Some(size_str) = line.split_whitespace().nth(1) {
46-
if let Ok(size_kb) = size_str.parse::<usize>() {
47-
total_vmsize_kb += size_kb;
48-
}
49-
}
50-
}
51-
}
52-
}
53-
}
54-
}
55-
}
56-
}
57-
}
58-
}
59-
60-
(total_rss_kb / 1024, total_vmsize_kb / 1024) // 转换为MB
61-
}
62-
6312
use crate::zkcuda::proving_system::expander::structs::{
6413
ExpanderProverSetup, ExpanderVerifierSetup,
6514
};
@@ -247,7 +196,6 @@ impl SharedMemoryEngine {
247196

248197
global_mpi_config.barrier();
249198

250-
251199
let n_witness = usize::new_from_memory(&mut mpi_shared_mem_ptr);
252200
let witness = (0..n_witness)
253201
.map(|_| Vec::<F::SimdCircuitField>::new_from_memory(&mut mpi_shared_mem_ptr))

0 commit comments

Comments
 (0)