Skip to content

Commit 993cd49

Browse files
cyyeverfacebook-github-bot
authored andcommitted
Fix array-bounds error (pytorch#3798)
Summary: X-link: facebookresearch/FBGEMM#1485 Fix the following g++ error: ``` In member function ‘constexpr const std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](size_type) const [with _Tp = int; long unsigned int _Nm = 1]’, inlined from ‘fbgemm::GenConvKernelBase<SPATIAL_DIM, INST_SET>::GenConvKernelBase(const fbgemm::conv_param_t<kSpatialDim>&, int32_t, bool, bool, bool, bool, bool) [with int SPATIAL_DIM = 1; fbgemm::inst_set_t INST_SET = fbgemm::inst_set_t::avx512]’ at ../third_party/fbgemm/src/./GroupwiseConv.h:128:43: /usr/include/c++/14.2.1/array:219:24: error: array subscript 18446744073709551615 is above array bounds of ‘std::__array_traits<int, 1>::_Type’ {aka ‘const int [1]’} [-Werror=array-bounds=] 219 | return _M_elems[__n]; | ~~~~~~~~^ /usr/include/c++/14.2.1/array: In constructor ‘fbgemm::GenConvKernelBase<SPATIAL_DIM, INST_SET>::GenConvKernelBase(const fbgemm::conv_param_t<kSpatialDim>&, int32_t, bool, bool, bool, bool, bool) [with int SPATIAL_DIM = 1; fbgemm::inst_set_t INST_SET = fbgemm::inst_set_t::avx512]’: /usr/include/c++/14.2.1/array:115:55: note: while referencing ‘std::array<int, 1>::_M_elems’ 115 | typename __array_traits<_Tp, _Nm>::_Type _M_elems; | ^~~~~~~~ In member function ‘constexpr const std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](size_type) const [with _Tp = int; long unsigned int _Nm = 1]’, inlined from ‘fbgemm::GenConvKernelBase<SPATIAL_DIM, INST_SET>::GenConvKernelBase(const fbgemm::conv_param_t<kSpatialDim>&, int32_t, bool, bool, bool, bool, bool) [with int SPATIAL_DIM = 1; fbgemm::inst_set_t INST_SET = fbgemm::inst_set_t::avx512_vnni]’ at ../third_party/fbgemm/src/./GroupwiseConv.h:128:43: /usr/include/c++/14.2.1/array:219:24: error: array subscript 18446744073709551615 is above array bounds of ‘std::__array_traits<int, 1>::_Type’ {aka ‘const int [1]’} [-Werror=array-bounds=] 219 | return _M_elems[__n]; | ~~~~~~~~^ /usr/include/c++/14.2.1/array: In constructor ‘fbgemm::GenConvKernelBase<SPATIAL_DIM, INST_SET>::GenConvKernelBase(const fbgemm::conv_param_t<kSpatialDim>&, int32_t, bool, bool, bool, bool, bool) [with int SPATIAL_DIM = 1; fbgemm::inst_set_t INST_SET = fbgemm::inst_set_t::avx512_vnni]’: /usr/include/c++/14.2.1/array:115:55: note: while referencing ‘std::array<int, 1>::_M_elems’ 115 | typename __array_traits<_Tp, _Nm>::_Type _M_elems; | ^~~~~~~~ cc1plus: all warnings being treated as errors ``` There was an out of bound access before fix, and that access was shortcuted by ``and`` condition. Nevertheless, it's better to fix that. Pull Request resolved: pytorch#3798 Reviewed By: gchalump Differential Revision: D77493350 Pulled By: q10 fbshipit-source-id: 285200a3bc69ff42fb53ff4f05a60e3961927fdb
1 parent db4f7a3 commit 993cd49

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/GroupwiseConv.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ class GenConvKernelBase {
124124
H_PAD_ = conv_param.pad[0];
125125
W_PAD_ = conv_param.pad[1];
126126

127-
use_bottom_padding_ =
128-
!(STRIDE_ > 1 && conv_param.IN_DIM[SPATIAL_DIM - 2] % 2 == 0);
127+
if constexpr (SPATIAL_DIM >= 2) {
128+
use_bottom_padding_ =
129+
!(STRIDE_ > 1 && conv_param.IN_DIM[SPATIAL_DIM - 2] % 2 == 0);
130+
} else {
131+
use_bottom_padding_ = false;
132+
}
129133
use_right_padding_ =
130134
!(STRIDE_ > 1 && conv_param.IN_DIM[SPATIAL_DIM - 1] % 2 == 0);
131135
}

0 commit comments

Comments
 (0)