Add --threads N to run-c/run-cu (sets HVM_THREADS on the spawned hvm) - #763
Open
SiliconState wants to merge 1 commit into
Open
Add --threads N to run-c/run-cu (sets HVM_THREADS on the spawned hvm)#763SiliconState wants to merge 1 commit into
SiliconState wants to merge 1 commit into
Conversation
Plumbs an optional worker-thread count through CliRunOpts -> RunOpts -> run_hvm, exported as the HVM_THREADS environment variable on the spawned hvm process. Inert until the HVM2 runtime reads HVM_THREADS (and against older hvm binaries, which ignore the unknown env var); run-rs is unaffected. No flag means no env var: behavior is byte-for-byte unchanged.
SiliconState
force-pushed
the
pr/threads-flag
branch
from
June 11, 2026 01:02
59ef025 to
391617e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A
--threads Nflag on the run subcommands that setsHVM_THREADS=Non the spawnedhvmprocess. Companion to HigherOrderCO/HVM2#441, which makes the HVM C runtime read that variable at startup and clamp to the compiledTPC.Why
HVM2's parallel C runtime fixes its worker count at compile time, so today there is no way to measure parallel scaling (speedup vs N threads) through Bend — tools can only compare whole backends (run-rs vs run-c vs run-cu), which conflates runtime quality with parallelism. A runtime thread count also lets users on shared machines / CI cap cores, and lets benchmarking tools pin a count for reproducibility.
bend run-c fileinvokeshvm run-c <file>with no thread argument, so there is nothing to thread a value through today.Patch
CliRunOptsgains--threads: Option<usize>; it flows throughRunOpts(new publicthreadsfield,Noneby default) intorun_hvm, which setsHVM_THREADSon the child when present.run-rsis unaffected (the Rust interpreter ignores the variable).Backward compatibility
hvmbinaries ignore the unknown env var, so a new Bend works against an old HVM (no scaling, but no breakage). With the HVM2 patch,-sadditionally shows aTHREADS: Nreadback so tools can confirm the count took effect.Testing
threads: Nonedefault means existingRunOpts { .. }literals and golden tests are untouched).HVM_THREADS-aware hvm:bend run-c parallel_sum.bend --threads {1,4,16} -s→ identical Result/ITRS at every count,THREADS: Nreadback, 37 → 98 MIPS from 1 → 4 threads on a 16-core machine. Measured efficiency curve on depth-16parallel_sum.bend: 1.00x/1.55x/2.43x/3.27x at 1/2/4/8 threads (ITRS identical at every count), requested 32 clamped to 16.