Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[luci-interpreter] Add check for Reshape #14446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/luci-interpreter/src/kernels/Reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static void resolveUnknownDimension(const Shape &input_shape, Shape *output_shap
output_shape->dim(unknown_dim_index) = num_input_elements / num_output_elements;
num_output_elements *= output_shape->dim(unknown_dim_index);
}
assert(num_output_elements == num_input_elements);

LUCI_INTERPRETER_CHECK(num_output_elements == num_input_elements);
}

Reshape::Reshape(const Tensor *input, const Tensor *shape, Tensor *output)
Expand Down
16 changes: 16 additions & 0 deletions compiler/luci-interpreter/src/kernels/Reshape.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ TEST_F(ReshapeTest, SupportS16_NEG)
EXPECT_ANY_THROW(kernel.configure());
}

TEST_F(ReshapeTest, NumElementsMismatch_NEG)
{
Shape input_shape{1, 2, 3};
std::vector<float> input_data{1, 2, 3, 4, 5, 6};
Shape shape_shape{2};
std::vector<int32_t> shape_data{1, 7};
Tensor input_tensor =
makeInputTensor<DataType::FLOAT32>(input_shape, input_data, _memory_manager.get());
Tensor shape_tensor =
makeInputTensor<DataType::S32>(shape_shape, shape_data, _memory_manager.get());
Tensor output_tensor = makeOutputTensor(DataType::FLOAT32);

Reshape kernel(&input_tensor, &shape_tensor, &output_tensor);
EXPECT_ANY_THROW(kernel.configure());
}

} // namespace
} // namespace kernels
} // namespace luci_interpreter