Skip to content

Add caching for MultiPodBuilder solutions#502

Open
robknight wants to merge 6 commits into
mainfrom
multi_pod_solver_cache
Open

Add caching for MultiPodBuilder solutions#502
robknight wants to merge 6 commits into
mainfrom
multi_pod_solver_cache

Conversation

@robknight
Copy link
Copy Markdown
Collaborator

@robknight robknight commented Apr 23, 2026

Closes #489

Uses the existing POD2 memory or disk cache to store solution layouts for MultiPodBuilder. This can avoid the overhead of repeatedly solving for the layout of PODs that only differ in their concrete inputs.

Many of the PODs we want to build in real-world applications have standard layouts: we know exactly which operations will be needed, in which order, and how many input PODs will be required. This means that we should be able to reuse multi-POD layout solutions in those cases.

@robknight robknight changed the title Add caching for MultiPodBuilder solves Add caching for MultiPodBuilder solutons Apr 23, 2026
@robknight robknight changed the title Add caching for MultiPodBuilder solutons Add caching for MultiPodBuilder solutions Apr 23, 2026
Comment thread src/frontend/multi_pod/mod.rs Outdated
/// disk) is logged and falls back to a direct solve, so callers always
/// get either a valid solution or a typed solver error - never a panic
/// from the cache layer.
#[cfg(any(feature = "mem_cache", feature = "disk_cache"))]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code-base assumes one cache is enabled. I don't think the crate compiles with no cache enabled, so this line seems redundant.

Comment thread src/frontend/multi_pod/layout.rs Outdated
/// [`MultiPodBuilder::layout_key`]: super::MultiPodBuilder::layout_key
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LayoutKey {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this PR we now have:

  • SolverInput: this defines the shape of the problem and is passed to the solver to find a solution
  • LayoutKey: this is the symbolic shape of the problem

LayoutKey is required because SolverInput has some values that are independent of the shape, like the hashes of input pods.
Then you have ways to move between the two.

The solver should be capable of finding a solution with a symbolic problem definition. So I would like to consider a slightly different implementation: instead of having LayoutKey and SolverInput, make SolverInput symbolic.
Then there's no need to make synthetic SolverInput from LayoutKey, and I think the implementation will be more straight forward.

It would look something like this:

  • MultiPod builds up the problem into MultiPodInput
  • From MultiPodInput we generate InputShape
  • The solver works with InputShape and returns OutputShape. This is cached (key: InputShape, value: OutputShape)
  • From OutputShape and MultiPodInput now we can build MultiPodOutput

Copy link
Copy Markdown
Collaborator

@ed255 ed255 Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A different way of expressing my proposal is: instead of adding layout.rs with new types and methods, try to rework the implementation of the solver and SolvedMultiPod so that they naturally connect with types that encode the sape without data (so the input and output of the solver is purely symbolic)

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.

Reuse work done by MultiPodBuilder's solver

2 participants