From f1185caa2ea0d7d5abffe36e740b593d7383e70c Mon Sep 17 00:00:00 2001 From: tignear Date: Sat, 28 Nov 2026 23:38:19 +0900 Subject: [PATCH] perf: optimize independent units on the compile threads The SIR optimizer optimizes the independent execution units, processes and function units on as many threads as `OptimizeOptions::compile_threads` allows (by default the available parallelism), instead of at most four. Each unit is optimized in place on its own, as before, so the result is the same for every count. AVIP axi4_base_test (nocb copy, heliodor-dev, 16 cores), before -> after: - the `optimize` phase 3.65 s -> 2.29 s; its 18,787 function units 2.71 s -> 1.30 s - wall (quiet lock, two runs each) 1:15.7 / 1:12.7 -> 1:13.9 / 1:11.5 - stdout identical; the UVM cases 18.10, 16.10 and uvm_scoreboard_env give identical output (182.6 / 247.0 / 288.8 G instructions:u, as before); the 16.9 elaboration exits 0 - VeeR-EL2: compile 90.5 / 90.5 s -> 90.3 / 90.3 s, instructions:u 1198.57 / 1198.64 G -> 1198.67 / 1198.67 G, the simulation's instructions equal Change-Id: I01f35cfb8ee9b58d19aaa94ff9d311c7607ee002 --- .../celox-sir-opt/src/optimizer/pipeline/pass_manager.rs | 7 +++---- crates/celox-sir-opt/src/policy.rs | 6 +++--- crates/celox/src/bin/celox/runner.rs | 6 +++--- crates/celox/src/simulator/builder/host.rs | 7 ++++--- docs/guide/parallel-simulation.md | 5 +++-- docs/ja/guide/parallel-simulation.md | 3 ++- packages/celox/src/types.ts | 5 +++-- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/celox-sir-opt/src/optimizer/pipeline/pass_manager.rs b/crates/celox-sir-opt/src/optimizer/pipeline/pass_manager.rs index 53c03eb2927..1147013bff6 100644 --- a/crates/celox-sir-opt/src/optimizer/pipeline/pass_manager.rs +++ b/crates/celox-sir-opt/src/optimizer/pipeline/pass_manager.rs @@ -168,14 +168,13 @@ impl ExecutionUnitPassManager { run: impl Fn(&Self, &mut ExecutionUnit, &PassOptions) + Sync, options: &PassOptions, ) { - #[cfg(not(target_arch = "wasm32"))] - const MAX_PARALLEL_UNITS: usize = 4; - + // As many workers as compiling may use (see + // `OptimizeOptions::compile_threads`), no more than the host has. #[cfg(not(target_arch = "wasm32"))] let worker_count = items.len().min( std::thread::available_parallelism() .map_or(1, usize::from) - .min(MAX_PARALLEL_UNITS), + .min(options.optimize_options.compile_threads()), ); #[cfg(target_arch = "wasm32")] let worker_count = 1; diff --git a/crates/celox-sir-opt/src/policy.rs b/crates/celox-sir-opt/src/policy.rs index e902661b5b5..14ea785cd20 100644 --- a/crates/celox-sir-opt/src/policy.rs +++ b/crates/celox-sir-opt/src/policy.rs @@ -314,9 +314,9 @@ impl OptimizeOptions { } /// Compile with at most `threads` threads (at least one): the frontend - /// lowers independent modules on them, and native code generation - /// compiles independent units on as many of them as its memory budget - /// allows. One compiles everything on the calling thread. They are not + /// lowers independent modules on them, the optimizer optimizes + /// independent units on them, and native code generation compiles + /// independent units on as many of them as its memory budget allows. One compiles everything on the calling thread. They are not /// simulation lanes (see [`Self::set_parallel_lanes`]); the result is the /// same for every count. The default is the available parallelism of /// the host. diff --git a/crates/celox/src/bin/celox/runner.rs b/crates/celox/src/bin/celox/runner.rs index 68145ac4d64..dfc4a740605 100644 --- a/crates/celox/src/bin/celox/runner.rs +++ b/crates/celox/src/bin/celox/runner.rs @@ -111,9 +111,9 @@ pub(super) struct ExecutionArgs { /// Simulation threads, including the calling thread. #[arg(long, default_value_t = 1, value_parser = clap::value_parser!(u32).range(1..=64))] pub threads: u32, - /// Compile threads: the SystemVerilog frontend and native code - /// generation compile independent modules and units on up to this many - /// threads. The compiled program is the same for every count. Default: + /// Compile threads: the SystemVerilog frontend, the SIR optimizer and + /// native code generation compile independent modules and units on up + /// to this many threads. The compiled program is the same for every count. Default: /// the available parallelism of the host. #[arg(long, value_name = "N", value_parser = clap::value_parser!(u32).range(1..))] pub compile_threads: Option, diff --git a/crates/celox/src/simulator/builder/host.rs b/crates/celox/src/simulator/builder/host.rs index 5a03fc8d756..802f895e3a5 100644 --- a/crates/celox/src/simulator/builder/host.rs +++ b/crates/celox/src/simulator/builder/host.rs @@ -473,9 +473,10 @@ impl<'a, Target> SimulatorBuilder<'a, Target> { } /// Compile with at most `threads` host threads (at least one). The - /// SystemVerilog frontend lowers independent modules on them, and - /// native code generation compiles independent units on as many as its - /// memory budget allows. One compiles on the calling thread only. The + /// SystemVerilog frontend lowers independent modules on them, the SIR + /// optimizer optimizes independent units on them, and native code + /// generation compiles independent units on as many as its memory + /// budget allows. One compiles on the calling thread only. The /// compiled program is the same for every count; these are not the /// simulation threads of [`Self::threads`]. The default is the /// available parallelism of the host. diff --git a/docs/guide/parallel-simulation.md b/docs/guide/parallel-simulation.md index 40011e4b333..fd6c38b9f97 100644 --- a/docs/guide/parallel-simulation.md +++ b/docs/guide/parallel-simulation.md @@ -67,8 +67,9 @@ trigger clock events, stay ordered exactly as in sequential simulation. Compilation has its own thread count, separate from the simulation threads above. The SystemVerilog frontend lowers independent modules (such as the -state modules of packages) on these threads, and native code generation -compiles independent units on as many of them as its memory budget allows. +state modules of packages) on these threads, the SIR optimizer optimizes +independent units on them, and native code generation compiles independent +units on as many of them as its memory budget allows. The compiled program is the same for every count. ```rust diff --git a/docs/ja/guide/parallel-simulation.md b/docs/ja/guide/parallel-simulation.md index 54cc7923b20..9508cfe1baa 100644 --- a/docs/ja/guide/parallel-simulation.md +++ b/docs/ja/guide/parallel-simulation.md @@ -64,7 +64,8 @@ Celox は次の 2 段階で、並列化によって遅くなることを防ぎ コンパイルには、上記のシミュレーションスレッドとは別のスレッド数があります。 SystemVerilog フロントエンドは独立したモジュール(パッケージの状態モジュール -など)をこれらのスレッドで変換し、ネイティブコード生成は独立したユニットを +など)をこれらのスレッドで変換し、SIR オプティマイザーは独立したユニットを +これらのスレッドで最適化し、ネイティブコード生成は独立したユニットを メモリ予算の許す数のスレッドでコンパイルします。生成されるプログラムは スレッド数によらず同じです。 diff --git a/packages/celox/src/types.ts b/packages/celox/src/types.ts index d6f8c5ed46d..28915178aa9 100644 --- a/packages/celox/src/types.ts +++ b/packages/celox/src/types.ts @@ -590,8 +590,9 @@ export interface SimulatorOptions { */ threads?: number; /** - * Compile threads: the SystemVerilog frontend and native code generation - * compile independent modules and units on up to this many threads. + * Compile threads: the SystemVerilog frontend, the SIR optimizer and + * native code generation compile independent modules and units on up to + * this many threads. * The compiled program is the same for every count. These are not the * simulation `threads`. Default: the available parallelism of the host. */