Skip to content

Commit 69a6764

Browse files
Cover each new dim order check independently and drop cat's dead input loop
1 parent a3e70ee commit 69a6764

3 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎kernels/portable/cpu/op_cat.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ Tensor& cat_out(
2828

2929
ET_KERNEL_CHECK(ctx, check_cat_args(tensors, dim, out), InvalidArgument, out);
3030

31+
// check_cat_args already requires every input to share out's dim order, so
32+
// checking out is enough to force all of them to the default.
3133
ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(out), InvalidArgument, out);
32-
for (size_t i = 0; i < tensors.size(); ++i) {
33-
ET_KERNEL_CHECK(
34-
ctx, tensor_is_default_dim_order(tensors[i]), InvalidArgument, out);
35-
}
3634

3735
Tensor::SizesType expected_out_size[kTensorDimensionLimit];
3836
size_t expected_out_dim = 0;

‎kernels/test/op_pixel_unshuffle_test.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,19 @@ TEST_F(OpPixelUnshuffleOutTest, NonDefaultDimOrderDies) {
141141

142142
ET_EXPECT_KERNEL_FAILURE(context_, op_pixel_unshuffle_out(a, 2, out));
143143
}
144+
145+
TEST_F(OpPixelUnshuffleOutTest, MixedDimOrderDies) {
146+
TensorFactory<ScalarType::Float> tf;
147+
148+
// Only out has a non-default dim order, so the same dim order check shall be
149+
// what rejects it.
150+
Tensor a = tf.make(
151+
{1, 1, 4, 4}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
152+
Tensor out = tf.zeros_channels_last({1, 4, 2, 2});
153+
154+
ET_SKIP_IF(
155+
torch::executor::testing::SupportedFeatures::get()->is_aten,
156+
"ATen kernel can handle non-default dim order");
157+
158+
ET_EXPECT_KERNEL_FAILURE(context_, op_pixel_unshuffle_out(a, 2, out));
159+
}

‎kernels/test/op_topk_test.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,27 @@ TEST_F(OpTopkValuesTest, NonDefaultDimOrderDies) {
197197

198198
EXPECT_NE(context.failure_state(), torch::executor::Error::Ok);
199199
}
200+
201+
TEST_F(OpTopkValuesTest, MixedDimOrderDies) {
202+
TensorFactory<ScalarType::Float> tf;
203+
TensorFactory<ScalarType::Long> tf_long;
204+
205+
// Only values has a non-default dim order, so the same dim order check shall
206+
// be what rejects it.
207+
Tensor in = tf.make(
208+
{1, 4, 2, 2}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
209+
Tensor values = tf.zeros_channels_last({1, 2, 2, 2});
210+
Tensor indices = tf_long.zeros({1, 2, 2, 2});
211+
212+
ET_SKIP_IF(
213+
torch::executor::testing::SupportedFeatures::get()->is_aten,
214+
"ATen kernel can handle non-default dim order");
215+
216+
TempMemoryAllocator allocator = TempMemoryAllocator();
217+
executorch::ET_RUNTIME_NAMESPACE::KernelRuntimeContext context(
218+
nullptr, &allocator);
219+
torch::executor::aten::topk_outf(
220+
context, in, 2, 1, true, true, values, indices);
221+
222+
EXPECT_NE(context.failure_state(), torch::executor::Error::Ok);
223+
}

0 commit comments

Comments
 (0)