Skip to content

Validate NCHWc reorder channel layout - #32552

Open
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
fix/reorder-output-channel-layout
Open

Validate NCHWc reorder channel layout#32552
Akshay Sonawane (apsonawane) wants to merge 1 commit into
mainfrom
fix/reorder-output-channel-layout

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request strengthens input validation in the ReorderOutput operator for NCHWc tensors and adds a new unit test to ensure correct error handling for misaligned input channels. The main focus is to enforce stricter requirements on input channel alignment and to verify this behavior with automated testing.

Operator input validation improvements:

  • Updated ReorderOutput::Compute in nchwc_ops.cc to enforce that the input channel count is a multiple of the NCHWc block size, and that the number of channels requested is properly aligned. The error message was also improved for clarity.

Testing enhancements:

  • Added a new unit test ReorderOutputRejectsUnalignedInputChannels in nchwc_ops_test.cc to verify that the operator correctly rejects inputs where the channel count is not NCHWc block-aligned, ensuring that the stricter validation is covered.

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.

🟡 Changes recommended

The test does not cover the newly added excessive-padding rejection condition.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Strengthens NCHWc ReorderOutput channel-layout validation.

Changes:

  • Validates block alignment and requested channel count.
  • Adds a rejection test for unaligned input channels.
File summaries
File Description
onnxruntime/contrib_ops/cpu/nchwc_ops.cc Enforces valid NCHWc channel padding.
onnxruntime/test/contrib_ops/nchwc_ops_test.cc Tests rejection of unaligned channels.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +13 to +31
TEST(NchwcOpsTest, ReorderOutputRejectsUnalignedInputChannels) {
const int64_t block_size = static_cast<int64_t>(MlasNchwcGetBlockSize());
if (block_size <= 1) {
GTEST_SKIP() << "NCHWc blocking is not enabled on this platform.";
}

const int64_t input_channels = block_size - 1;
OpTester test("ReorderOutput", 1, kMSNchwcDomain);
test.AddAttribute("channels", int64_t{1});
test.AddAttribute("channels_last", int64_t{0});
test.AddInput<float>("X", {1, input_channels, 2, 2},
std::vector<float>(static_cast<size_t>(input_channels) * 4, 0.0f));
test.AddOutput<float>("Y", {1, 1, 2, 2}, {0.0f, 0.0f, 0.0f, 0.0f});

test.Config(OpTester::ExpectResult::kExpectFailure,
"Input channels must match the NCHWc block-aligned channel count.")
.ConfigEp(DefaultCpuExecutionProvider())
.RunWithConfig();
}
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