Skip to content

Commit

Permalink
Use tensor_shape_to_c_string for error in check_glu_args
Browse files Browse the repository at this point in the history
Rolling out for #7902

ghstack-source-id: 25379114bb1af9572c61d4f9673805a471ea99c6
ghstack-comment-id: 2643883485
Pull Request resolved: #8316
  • Loading branch information
swolchok committed Feb 7, 2025
1 parent b9c056e commit 56cddf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions kernels/portable/cpu/util/activation_ops_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstring>

#include <executorch/kernels/portable/cpu/util/activation_ops_util.h>
#include <executorch/runtime/core/exec_aten/util/tensor_shape_to_c_string.h>

namespace torch {
namespace executor {
Expand Down Expand Up @@ -45,9 +46,22 @@ bool check_glu_args(const Tensor& in, int64_t dim, Tensor& out) {

for (size_t i = 0; i < in.dim(); ++i) {
if (i != non_negative_dim) {
ET_LOG_MSG_AND_RETURN_IF_FALSE(
out.size(i) == in.size(i),
"output tensor must have the same size as the input tensor in all dimensions except for the specified dimension.");
if (out.size(i) != in.size(i)) {
#ifdef ET_LOG_ENABLED
auto out_shape_str = executorch::runtime::tensor_shape_to_c_string(
executorch::runtime::Span<const Tensor::SizesType>(
out.sizes().data(), out.sizes().size()));
auto in_shape_str = executorch::runtime::tensor_shape_to_c_string(
executorch::runtime::Span<const Tensor::SizesType>(
in.sizes().data(), in.sizes().size()));
#endif // ET_LOG_ENABLED
ET_LOG(
Error,
"output tensor must have the same size as the input tensor in all dimensions except for the specified dimension. (output shape: %s input shape: %s)",
out_shape_str.data(),
in_shape_str.data());
return false;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions kernels/portable/cpu/util/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def define_common_targets():
],
compiler_flags = ["-Wno-missing-prototypes"],
deps = [
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
"//executorch/runtime/kernel:kernel_includes",
],
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/optimized/cpu/..."],
Expand Down

0 comments on commit 56cddf4

Please sign in to comment.