feat: cap shivini device-memory pool via env var and --max-device-allocation flag - #71
Open
error2215 wants to merge 1 commit into
Open
feat: cap shivini device-memory pool via env var and --max-device-allocation flag#71error2215 wants to merge 1 commit into
error2215 wants to merge 1 commit into
Conversation
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 ❔
Adds an opt-in cap on shivini's GPU device-memory pool, exposed two ways:
ZKOS_WRAPPER_MAX_DEVICE_ALLOCATION(Kubernetes-style sizes:32Gi,48GiB,64G, or raw bytes).--max-device-allocationon thewrapperbinary, which seeds the same value before any GPU code runs.When a cap is provided, both
ProverContext::create_with_configsites —wrapper/src/wrapper/gpu.rs::ensure_stark_context(the cachedstark_contextshared across phases 1+2) and the inline path inwrapper/src/lib.rs(prove_risc_wrapper_with_snark) — thread it throughProverContextConfig::with_maximum_device_allocation. When neither is set, behavior is identical to today (shivini grabs all free device memory).New modules:
wrapper/src/gpu_config.rs— env-var constant,parse_byte_size(K8s-style suffix parser),set_max_device_allocation/max_device_allocation(cached viaOnceLock), unit tests. Lives outside thegpufeature gate so non-GPU builds still parse the CLI value and so library callers can seed the cap without depending on shivini.wrapper/src/gpu/context.rs— single helperapply_env_overrides(base), gated behindgpu.The CLI setter takes precedence over the env var when both are provided; the resolved value is cached in a
OnceLockso the env var is parsed at most once.Why ❔
The default shivini pool grabs ~47 GB up front for the SNARK precomputation, and the subsequent
get_light_setup/gpu_setup_and_vk_from_base_setup_vk_params_and_hintsneeds another large device buffer for the LDE table and Merkle caps — total ~60–70 GB of free VRAM on a single contiguous device.This is fine on H200 (141 GB HBM3e), but breaks on:
2g.48gb— the pool itself barely fits and the next allocation OOMs in shivini withErrorMemoryAllocation.The failure surfaces as a panic out of shivini at the SNARK setup stage:
2g.48gb1g.24gbFRI proving fits comfortably on the smaller slices; only the SNARK pipeline trips this.
Capping the pool (e.g.
--max-device-allocation 21GiorZKOS_WRAPPER_MAX_DEVICE_ALLOCATION=21Gi) leaves headroom for the setup buffers, and SNARK proving completes on smaller GPUs / MIG slices. The flag is opt-in; operators running on a full H200 do not need to change anything.The two-channel design (env var + CLI) is deliberate: downstream services that embed
zkos-wrapperas a library (running outside the wrapper binary, e.g. in Kubernetes-managed snark-prover pods) need the env var; operators driving the binary directly want a flag. Both feed the sameOnceLock.Is this a breaking change?
gpu_config), one new submodule (gpu::context), one new global CLI flag, one new env var. Default behavior when both are absent is byte-identical to before.Checklist
parse_byte_sizeunit tests inwrapper/src/gpu_config.rs— 4 tests covering raw bytes, decimal suffixes, binary suffixes, and rejected garbage.)//!docs on both new modules;///help string on the CLI flag explaining unit formats and precedence.)cargo fmt --checkclean on the project-pinnednightly-2026-02-10toolchain.)