Skip to content

Add optimal graph coloring to minimize shared FIFO buffer allocations#7

Merged
christophe0606 merged 1 commit into
ARM-software:mainfrom
potatoeeh:optimal-graph-coloring
Apr 22, 2026
Merged

Add optimal graph coloring to minimize shared FIFO buffer allocations#7
christophe0606 merged 1 commit into
ARM-software:mainfrom
potatoeeh:optimal-graph-coloring

Conversation

@potatoeeh
Copy link
Copy Markdown
Contributor

The CMSIS-Stream scheduler uses nx.coloring.greedy_color() to assign shared buffers to FIFOs via graph coloring. This greedy heuristic can use more colors (buffers) than the graph's chromatic number.

This adds an exact backtracking-based coloring algorithm (optimal_coloring) that finds the minimum number of colors. Because the solver is expensive on large graphs, it includes a configurable visit budget (max_visits, default 131072). If the budget is exceeded, the function returns None, allowing the caller to fall back to the existing greedy algorithm.

Two-tier coloring strategy:

  1. Try exact backtracking (optimal, but potentially expensive)
  2. If budget exceeded, fall back to greedy (suboptimal, but fast)

Also adds Tests/test_optimal_coloring.py exercising correctness, greedy-vs-optimal gap, and budget fallback behavior.

The CMSIS-Stream scheduler uses nx.coloring.greedy_color() to assign
shared buffers to FIFOs via graph coloring. This greedy heuristic can
use more colors (buffers) than the graph's chromatic number.

This adds an exact backtracking-based coloring algorithm
(optimal_coloring) that finds the minimum number of colors. Because
the solver is expensive on large graphs, it includes a configurable
visit budget (max_visits, default 131072). If the budget is exceeded,
the function returns None, allowing the caller to fall back to the
existing greedy algorithm.

Two-tier coloring strategy:
1. Try exact backtracking (optimal, but potentially expensive)
2. If budget exceeded, fall back to greedy (suboptimal, but fast)

Also adds Tests/test_optimal_coloring.py exercising correctness,
greedy-vs-optimal gap, and budget fallback behavior.
@christophe0606 christophe0606 added the review Under review label Apr 15, 2026
@christophe0606
Copy link
Copy Markdown
Contributor

@potatoeeh Thanks for this very interesting PR. I'll be slow to merge it because I have currently lots of ongoing other tasks. So be very patient but I'll look at it and merge it.

Memory optimization in CMSIS Stream is something that can be improved with more work. There are a few places in the code where I could relax some constraints or use better algorithm so definitely this PR is appreciated.

Thanks.

I am curious to know in what kind of applications you use CMSIS-Stream ?

@christophe0606 christophe0606 merged commit 92e6f0e into ARM-software:main Apr 22, 2026
@christophe0606
Copy link
Copy Markdown
Contributor

Merged. I'll update the package on PyPI soon.

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

Labels

review Under review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants