Skip to content

Keep compiled kernels in an on-disk pipeline cache and report it (crucible#1949) - #66

Open
anxuanng wants to merge 1 commit into
mainfrom
1949-pipeline-cache
Open

anxuanng wants to merge 1 commit into
mainfrom
1949-pipeline-cache

Conversation

@anxuanng

Copy link
Copy Markdown
Contributor

Part of codepawl/crucible#1949.

What

  • New src/host/disk_pipeline_cache.rs: the driver's pipeline cache (wgpu PipelineCache, requested as an optional device feature) is loaded from and stored to one file per user, adapter and Cook version. %LOCALAPPDATA%\codepawl\cook\pipeline-cache on Windows, $XDG_CACHE_HOME/cook/pipeline-cache (else ~/.cache/cook/pipeline-cache) elsewhere. COOK_PIPELINE_CACHE_DIR moves it, COOK_PIPELINE_CACHE=off switches it off.
  • The file has a magic, a length and a checksum, checked before the blob reaches the driver. It is capped at 64 MiB, written to a temporary name and renamed, and a damaged, truncated or oversized file is deleted and rebuilt. Writes are best effort.
  • traceNative and session renders return pipelineCache: warm, cold, off or unsupported. compileSeconds and tracedSeconds were already separate fields (the timings object in the issue's repro does not exist); the README now says so.
  • Scenes without emitters keep tracing (tests/gpu/pipeline-cache.test.mjs traces one).

How I checked it

  • node --test tests/gpu/pipeline-cache.test.mjs on the RTX 3060 (release addon built on this branch): 3 pass (two processes cold then warm with the same pixels, a flipped byte is refused and replaced, off writes nothing).
  • Rust unit tests for the file format, size cap, directory choice and file name are in the module and run in CI (cargo test); I did not run cargo test locally.

Evidence

Measured, RTX 3060, 160x90, 16 spp, a variant no process had compiled before, separate processes, compileSeconds:

Run cache on cache off
process 1 9.9 s (cold) 5.3 s
process 2, same variant 0.033 s (warm) 0.044 s

The NVIDIA driver on Windows keeps its own disk cache per executable, so the second process is already fast with Cook's cache off. On this card the Cook cache therefore shows no measurable gain; it matters on drivers that keep no cache of their own. The first compile of a new variant (5 to 26 s here: 5 to 7 s without emitters, 26 s with one) is not removed by any cache.

…cible#1949)

Cook compiles one kernel per scene variant, and the first trace of a variant
spends seconds in the driver compile. Keep the driver's pipeline cache in one
file per user, adapter and Cook version so a second process can skip the
compile, and report its state as pipelineCache (warm, cold, off, unsupported)
beside compileSeconds and tracedSeconds.

The file carries a length and a checksum checked before the driver sees it,
is capped at 64 MiB, is written through a temporary file and a rename, and a
damaged or oversized file is deleted and rebuilt. COOK_PIPELINE_CACHE=off
switches it off and COOK_PIPELINE_CACHE_DIR moves it.
@anxuanng

Copy link
Copy Markdown
Contributor Author

Lead: holding this one. On the RTX 3060, the first compile was slower with the cache on (9.9 s) than with it off (5.3 s), and the warm runs were the same either way (0.033 s vs 0.044 s), because the driver already keeps its own cache across processes. Before this merges, it needs either a measurement where it wins (another driver, Linux or lavapipe) or the cold slowdown explained and fixed. The compile-time reporting in crucible#2006 can land on its own, without the cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant