Skip to content

Commit

Permalink
#0: add fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarafdar committed Sep 27, 2024
1 parent 0288d8a commit 4ca0502
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ttnn/cpp/ttnn/operations/data_movement/reshape_view/reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ttnn::Tensor host_reshape(const ttnn::Tensor& tensor, const ttnn::Shape& shape)
ttnn::Tensor slice_input;
std::vector<uint32_t> begins;
std::vector<uint32_t> ends;
TT_FATAL(tensor_shape.rank() <= 4, "Only up to 4D tensors");
auto host_tensor_4d = unsqueeze_to_4D(rm_tensor);
auto tensor_shape_4d = host_tensor_4d.shape();
begins = std::vector<uint32_t>({0, 0, 0, 0});
Expand Down Expand Up @@ -98,14 +99,19 @@ ttnn::Tensor row_major_reshape(const ttnn::Tensor& tensor, const ttnn::Shape& sh

}

ttnn::Shape get_shape_from_vector(const ttnn::Tensor& tensor, const std::vector<int32_t> & shape) {
ttnn::Shape get_shape_from_vector_with_possible_negative_values(const ttnn::Tensor& tensor, const std::vector<int32_t> & shape) {
std::int64_t new_volume = 1;
std::int64_t index_of_negative_1 = -1;

for (auto index = 0; index < shape.size(); ++index) {
if (shape[index] == -1) {
if (index_of_negative_1 != -1) {
TT_THROW("Shape cannot have more than 1 elements that is set to -1!");
std::string error_msg = "Shape cannot have more than 1 elements that is set to -1! Shape used: (";
for(auto & s: shape) {
error_msg += std::to_string(s) + ",";
}
error_msg += ")";
TT_THROW(error_msg.c_str());
}
index_of_negative_1 = index;
}
Expand Down Expand Up @@ -153,7 +159,7 @@ ttnn::Tensor ReshapeViewOperation::invoke(
const std::vector<int32_t> & shape_vector
) {

auto shape = detail::get_shape_from_vector(tensor, shape_vector);
auto shape = detail::get_shape_from_vector_with_possible_negative_values(tensor, shape_vector);
return invoke(tensor, shape);
}

Expand Down

0 comments on commit 4ca0502

Please sign in to comment.