Skip to content

Add C++ IR (Graph) entry point to the optimizer - #319

Open
take-cheeze wants to merge 1 commit into
onnx:mainfrom
onnxsim:claude/onnx-cpp-ir-optimizer-api-rrjtni
Open

Add C++ IR (Graph) entry point to the optimizer#319
take-cheeze wants to merge 1 commit into
onnx:mainfrom
onnxsim:claude/onnx-cpp-ir-optimizer-api-rrjtni

Conversation

@take-cheeze

Copy link
Copy Markdown
Member

Previously every public entry point required a ModelProto (or serialized bytes / file path); the in-memory ONNX C++ IR (Graph) was only ever built internally via ImportModelProto and torn down via ExportModelProto, never exposed as an input. A C++ caller already holding a Graph had to pay a full serialize/parse round-trip on both sides just to run the passes.

Add in-place Graph entry points that run the configured passes directly on the IR:

  • Optimizer::optimize(Graph&) overload that runs the pass manager on the graph in place; the existing optimize(ModelProto&) now reuses it.
  • Free functions OptimizeGraph / OptimizeGraphFixed mirroring Optimize / OptimizeFixed but operating on a Graph&.

Proto-level concerns (ir_version upgrade, function copying) stay on the ModelProto path since they have no Graph equivalent. The additions are purely additive with no ABI break. Add a gtest covering the Graph path.

Claude-Session: https://claude.ai/code/session_01U7PHiYF9q8Tv1KWV5w65Hq

@take-cheeze
take-cheeze requested review from a team as code owners July 26, 2026 03:07
Previously every public entry point required a ModelProto (or serialized
bytes / file path); the in-memory ONNX C++ IR (Graph) was only ever built
internally via ImportModelProto and torn down via ExportModelProto, never
exposed as an input. A C++ caller already holding a Graph had to pay a full
serialize/parse round-trip on both sides just to run the passes.

Add in-place Graph entry points that run the configured passes directly on
the IR:

- Optimizer::optimize(Graph&) overload that runs the pass manager on the
  graph in place; the existing optimize(ModelProto&) now reuses it.
- Free functions OptimizeGraph / OptimizeGraphFixed mirroring
  Optimize / OptimizeFixed but operating on a Graph&.

Proto-level concerns (ir_version upgrade, function copying) stay on the
ModelProto path since they have no Graph equivalent. The additions are
purely additive with no ABI break. Add a gtest covering the Graph path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U7PHiYF9q8Tv1KWV5w65Hq
Signed-off-by: take-cheeze <takechi101010@gmail.com>
@take-cheeze
take-cheeze force-pushed the claude/onnx-cpp-ir-optimizer-api-rrjtni branch from 91bbecc to 880ef9d Compare July 26, 2026 03:09
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.

2 participants