Skip to content

Commit 56cddf4

Browse files
committed
Use tensor_shape_to_c_string for error in check_glu_args
Rolling out for #7902 ghstack-source-id: 25379114bb1af9572c61d4f9673805a471ea99c6 ghstack-comment-id: 2643883485 Pull Request resolved: #8316
1 parent b9c056e commit 56cddf4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

kernels/portable/cpu/util/activation_ops_util.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cstring>
1010

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

1314
namespace torch {
1415
namespace executor {
@@ -45,9 +46,22 @@ bool check_glu_args(const Tensor& in, int64_t dim, Tensor& out) {
4546

4647
for (size_t i = 0; i < in.dim(); ++i) {
4748
if (i != non_negative_dim) {
48-
ET_LOG_MSG_AND_RETURN_IF_FALSE(
49-
out.size(i) == in.size(i),
50-
"output tensor must have the same size as the input tensor in all dimensions except for the specified dimension.");
49+
if (out.size(i) != in.size(i)) {
50+
#ifdef ET_LOG_ENABLED
51+
auto out_shape_str = executorch::runtime::tensor_shape_to_c_string(
52+
executorch::runtime::Span<const Tensor::SizesType>(
53+
out.sizes().data(), out.sizes().size()));
54+
auto in_shape_str = executorch::runtime::tensor_shape_to_c_string(
55+
executorch::runtime::Span<const Tensor::SizesType>(
56+
in.sizes().data(), in.sizes().size()));
57+
#endif // ET_LOG_ENABLED
58+
ET_LOG(
59+
Error,
60+
"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)",
61+
out_shape_str.data(),
62+
in_shape_str.data());
63+
return false;
64+
}
5165
}
5266
}
5367

kernels/portable/cpu/util/targets.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def define_common_targets():
4444
],
4545
compiler_flags = ["-Wno-missing-prototypes"],
4646
deps = [
47+
"//executorch/runtime/core/exec_aten/util:tensor_shape_to_c_string",
4748
"//executorch/runtime/kernel:kernel_includes",
4849
],
4950
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/optimized/cpu/..."],

0 commit comments

Comments
 (0)