Make CPU fallback type policy compile-time#29647
Open
GopalakrishnanN wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the CPU-fallback “unsupported type” policy used by GetCpuPreferredNodes to be represented as a compile-time constexpr table instead of repeated runtime lookups into ONNX’s global type registry, and adds targeted compile-time/runtime validation in tests.
Changes:
- Introduces a
constexpr std::array<std::string_view>table of unsupported CPU fallback type IDs with compile-time validation (non-empty, unique, sorted). - Updates
GetCpuPreferredNodesto use a compact predicate (IsUnsupportedCpuFallbackType) instead of multipleDataTypeUtils::ToType(...)lookups. - Adds a focused unit test with both compile-time (
static_assert) and runtime checks, including coverage for thefloat16vstensor(float16)distinction.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxruntime/core/framework/fallback_cpu_capability.h | Adds the compile-time unsupported-type table and validation predicate. |
| onnxruntime/core/framework/fallback_cpu_capability.cc | Replaces repeated ONNX type-registry lookups with the new table-based predicate in GetCpuPreferredNodes. |
| onnxruntime/test/framework/fallback_cpu_capability_test.cc | Adds compile-time coverage checks and a small runtime classification test for type-name behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GetCpuPreferredNodeswhile preserving the existing full type-ID semantics.float16andtensor(float16).Motivation and Context
GetCpuPreferredNodesevaluated each candidate input against seven calls toDataTypeUtils::ToType, which accesses ONNX's global type registry. The capability policy is fixed metadata, so it can be represented and validated at compile time and queried without registry access.This PR deliberately preserves the current string-ID behavior. It does not reinterpret the policy as tensor element-type matching; that would be a separate behavioral change.
Local Windows RelWithDebInfo measurements, using a stabilized build and forcing only
fallback_cpu_capability.ccstale:fallback_cpu_capability.objonnxruntime_framework.libThese measurements are toolchain-specific; the compile-time policy validation and removal of registry lookups are the primary benefits.
Validation
lintrunner -a onnxruntime/core/framework/fallback_cpu_capability.h onnxruntime/core/framework/fallback_cpu_capability.cc onnxruntime/test/framework/fallback_cpu_capability_test.cccmake --build build/Windows/RelWithDebInfo --config RelWithDebInfo --target onnxruntime_test_all --parallel 8onnxruntime_test_all.exe --gtest_filter="FallbackCpuCapabilityTest.*"(1/1 passed)