Skip to content

Commit 97fc825

Browse files
committed
fix: reject padded 2D layouts until execution handles strides
CompiledRaw2DNode::execute treats (batch, n0, n1) as tightly packed and ignores idist/odist. The validation accepted idist >= n0*n1 which would silently corrupt data for padded batches. - Change idist/odist check from >= to == for rank-2 plans - Add PaddedDistRejected test case Ref: review comment on is_supported_2d_desc
1 parent 8d9154e commit 97fc825

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

ctest/test_plan.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ TEST(Plan2D, CustomStrideNotSupportedYet) {
8585
EXPECT_EQ(plan, nullptr);
8686
}
8787

88+
TEST(Plan2D, PaddedDistRejected) {
89+
// idist/odist > logical size must be rejected until 2D execution handles strides
90+
int n[2] = {64, 32};
91+
const int logical = n[0] * n[1];
92+
flagfftHandle plan = nullptr;
93+
EXPECT_EQ(flagfftPlanMany(&plan, 2, n, nullptr, 1, logical + 16, nullptr, 1, logical, FLAGFFT_C2C, 1),
94+
FLAGFFT_NOT_SUPPORTED);
95+
EXPECT_EQ(plan, nullptr);
96+
EXPECT_EQ(flagfftPlanMany(&plan, 2, n, nullptr, 1, logical, nullptr, 1, logical + 16, FLAGFFT_C2C, 1),
97+
FLAGFFT_NOT_SUPPORTED);
98+
EXPECT_EQ(plan, nullptr);
99+
}
100+
88101
TEST(Plan2D, InvalidParameters) {
89102
flagfftHandle plan = nullptr;
90103
EXPECT_EQ(flagfftPlan2d(&plan, 0, 32, FLAGFFT_C2C), FLAGFFT_INVALID_SIZE);

src/exec/c_api_internal.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ bool is_supported_2d_desc(const FlagFFTPlanDesc &desc) {
114114
const int64_t half_n1 = n1 / 2 + 1;
115115
const int64_t input_logical = real_inverse ? n0 * half_n1 : n0 * n1;
116116
const int64_t output_logical = real_forward ? n0 * half_n1 : n0 * n1;
117-
if (desc.idist < input_logical || desc.odist < output_logical) {
117+
// CompiledRaw2DNode::execute treats the entire (batch, n0, n1) block as
118+
// tightly packed and ignores idist/odist. Reject padded layouts until
119+
// the 2D execution path plumbs strides through.
120+
if (desc.idist != input_logical || desc.odist != output_logical) {
118121
return false;
119122
}
120123
return true;

0 commit comments

Comments
 (0)