7
7
*/
8
8
9
9
#include < c10/util/irange.h>
10
+ #include < array>
10
11
#include < cstring>
11
12
12
13
#include < executorch/kernels/portable/cpu/util/normalization_ops_util.h>
@@ -92,6 +93,11 @@ bool check_layer_norm_args(
92
93
" , ndim = %zu" ,
93
94
in.dim (),
94
95
ndim);
96
+ ET_CHECK_OR_RETURN_FALSE (
97
+ ndim <= kTensorDimensionLimit ,
98
+ " Expected normalized shape to have at most %zu dimensions but it had %zu" ,
99
+ kTensorDimensionLimit ,
100
+ ndim);
95
101
size_t shift = in.dim () - ndim;
96
102
for (const auto d : c10::irange (ndim)) {
97
103
ET_CHECK_OR_RETURN_FALSE (
@@ -103,20 +109,20 @@ bool check_layer_norm_args(
103
109
d,
104
110
normalized_shape[d]);
105
111
}
106
- executorch::aten::SizesType shape[ndim] ;
112
+ std::array< executorch::aten::SizesType, kTensorDimensionLimit > shape;
107
113
for (const auto i : c10::irange (ndim)) {
108
114
shape[i] = static_cast <executorch::aten::SizesType>(normalized_shape[i]);
109
115
}
110
116
111
117
if (weight.has_value ()) {
112
118
ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_dtype (in, weight.value ()));
113
119
ET_LOG_AND_RETURN_IF_FALSE (
114
- tensor_has_expected_size (weight.value (), {shape, ndim}));
120
+ tensor_has_expected_size (weight.value (), {shape. data () , ndim}));
115
121
}
116
122
if (bias.has_value ()) {
117
123
ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_dtype (in, bias.value ()));
118
124
ET_LOG_AND_RETURN_IF_FALSE (
119
- tensor_has_expected_size (bias.value (), {shape, ndim}));
125
+ tensor_has_expected_size (bias.value (), {shape. data () , ndim}));
120
126
}
121
127
ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_dtype (in, out));
122
128
ET_LOG_AND_RETURN_IF_FALSE (tensors_have_same_dtype (in, mean_out));
0 commit comments