Skip to content

Move PropagateCastOps metadata to compile time#29648

Open
GopalakrishnanN wants to merge 3 commits into
mainfrom
GopalakrishnanN/constexpr-operator-metadata
Open

Move PropagateCastOps metadata to compile time#29648
GopalakrishnanN wants to merge 3 commits into
mainfrom
GopalakrishnanN/constexpr-operator-metadata

Conversation

@GopalakrishnanN

Copy link
Copy Markdown
Contributor

Description

  • Replace the two function-local InlinedHashMap tables used by PropagateCastOps with one constexpr operator argument descriptor table.
  • Store explicit active input/output counts so the compact fixed-capacity arrays preserve the existing policy exactly.
  • Validate sorted unique operator names, non-empty argument sets, in-range counts, non-negative indices, and duplicate indices with consteval checks.
  • Add an independent exhaustive compile-time truth table for all seven operators, plus a runtime lookup test.

Motivation and Context

The relevant input/output policy is fixed program metadata, but it was represented by two separately initialized runtime hash maps. Consolidating it removes duplicate operator keys, makes policy drift a compile-time failure, and avoids runtime hash-table initialization and allocation.

Unknown operators still use the existing fallback where every input/output is relevant.

Measurement

Windows RelWithDebInfo, MSVC 19.51, touched-file rebuild of propagate_cast_ops.cc:

Artifact Before After Delta
propagate_cast_ops.obj 7,196,523 B 6,353,108 B -843,415 B
onnxruntime_optimizer.lib 255,830,720 B 254,651,324 B -1,179,396 B

The single baseline rebuild was 10.83 s; post-change samples were 13.45 s, 12.37 s, and 12.06 s. Build timing is noisy and this PR does not claim a compile-time improvement.

Testing

  • cmake --build build/Windows/RelWithDebInfo --config RelWithDebInfo --target onnxruntime_test_all --parallel 8
  • onnxruntime_test_all.exe --gtest_filter=PropagateCastOpsMetadataTest.*:GraphTransformationTests.PropagateCastOpsTests* from the test output directory: 2 tests from 2 suites passed.
  • lintrunner -a on all three changed files: no lint issues.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR moves PropagateCastOps operator argument metadata from runtime-initialized hash maps to a single compile-time (constexpr) descriptor table, enforcing metadata consistency via compile-time validation and adding targeted tests to prevent policy drift.

Changes:

  • Replaced runtime InlinedHashMap metadata tables in PropagateCastOps with a constexpr kRelevantOpArgs table and a FindRelevantOpArgs lookup helper.
  • Added consteval/static_assert validation of metadata invariants (sorted unique op names, valid non-empty index sets, no duplicate indices).
  • Added a new unit test that performs an exhaustive compile-time truth-table check plus a small runtime lookup test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
onnxruntime/core/optimizer/propagate_cast_ops.cc Switches relevance checks to use the new compile-time metadata lookup.
onnxruntime/core/optimizer/propagate_cast_ops_metadata.h Introduces the compile-time metadata table, validation, and lookup helper for relevant input/output indices.
onnxruntime/test/optimizer/propagate_cast_ops_metadata_test.cc Adds compile-time and runtime tests to lock in the expected metadata behavior.

Comment thread onnxruntime/core/optimizer/propagate_cast_ops.cc Outdated
Comment thread onnxruntime/core/optimizer/propagate_cast_ops.cc Outdated
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