Skip to content

Commit 9a2d587

Browse files
authored
Merge pull request #48623 from fwyzard/better_range_check_150x
Improve SoA out-of-bounds error message [15.0.x]
2 parents 70cbfab + 59dc584 commit 9a2d587

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<use name="boost_header"/>
2+
<use name="fmt"/>
23
<use name="FWCore/Reflection" source_only="1"/>
34
<use name="FWCore/Utilities" source_only="1"/>

DataFormats/SoATemplate/interface/SoACommon.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#include <cstdint>
99
#include <cassert>
1010
#include <ostream>
11+
#include <sstream>
1112
#include <tuple>
1213
#include <type_traits>
1314

1415
#include <boost/preprocessor.hpp>
1516

17+
#include <fmt/format.h>
18+
1619
#include "FWCore/Utilities/interface/typedefs.h"
1720

1821
// CUDA attributes
@@ -30,20 +33,20 @@
3033

3134
// Exception throwing (or willful crash in kernels)
3235
#if defined(__CUDACC__) && defined(__CUDA_ARCH__)
33-
#define SOA_THROW_OUT_OF_RANGE(A) \
34-
{ \
35-
printf("%s\n", (A)); \
36-
__trap(); \
36+
#define SOA_THROW_OUT_OF_RANGE(A, I, R) \
37+
{ \
38+
printf("%s: index %d out of range %d\n", (A), (I), (R)); \
39+
__trap(); \
3740
}
3841
#elif defined(__HIPCC__) && defined(__HIP_DEVICE_COMPILE__)
39-
#define SOA_THROW_OUT_OF_RANGE(A) \
40-
{ \
41-
printf("%s\n", (A)); \
42-
abort(); \
42+
#define SOA_THROW_OUT_OF_RANGE(A, I, R) \
43+
{ \
44+
printf("%s: index %d out of range %d\n", (A), (I), (R)); \
45+
abort(); \
4346
}
4447
#else
45-
#define SOA_THROW_OUT_OF_RANGE(A) \
46-
{ throw std::out_of_range(A); }
48+
#define SOA_THROW_OUT_OF_RANGE(A, I, R) \
49+
{ throw std::out_of_range(fmt::format("{}: index {} out of range {}", (A), (I), (R))); }
4750
#endif
4851

4952
/* declare "scalars" (one value shared across the whole SoA) and "columns" (one value per element) */

DataFormats/SoATemplate/interface/SoAView.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ namespace cms::soa {
400400
LOCAL_NAME(size_type _soa_impl_index) { \
401401
if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
402402
if (_soa_impl_index >= base_type::elements_ or _soa_impl_index < 0) \
403-
SOA_THROW_OUT_OF_RANGE("Out of range index in mutable " #LOCAL_NAME "(size_type index)") \
403+
SOA_THROW_OUT_OF_RANGE("Out of range index in mutable " #LOCAL_NAME "(size_type index)", \
404+
_soa_impl_index, base_type::elements_) \
404405
} \
405406
return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
406407
template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
@@ -438,7 +439,8 @@ namespace cms::soa {
438439
LOCAL_NAME(size_type _soa_impl_index) const { \
439440
if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
440441
if (_soa_impl_index >= elements_ or _soa_impl_index < 0) \
441-
SOA_THROW_OUT_OF_RANGE("Out of range index in const " #LOCAL_NAME "(size_type index)") \
442+
SOA_THROW_OUT_OF_RANGE("Out of range index in const " #LOCAL_NAME "(size_type index)", \
443+
_soa_impl_index, elements_) \
442444
} \
443445
return typename cms::soa::SoAAccessors<typename BOOST_PP_CAT(Metadata::TypeOf_, LOCAL_NAME)>:: \
444446
template ColumnType<BOOST_PP_CAT(Metadata::ColumnTypeOf_, LOCAL_NAME)>::template AccessType< \
@@ -650,7 +652,7 @@ namespace cms::soa {
650652
element operator[](size_type _soa_impl_index) { \
651653
if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
652654
if (_soa_impl_index >= base_type::elements_ or _soa_impl_index < 0) \
653-
SOA_THROW_OUT_OF_RANGE("Out of range index in " #VIEW "::operator[]") \
655+
SOA_THROW_OUT_OF_RANGE("Out of range index in " #VIEW "::operator[]", _soa_impl_index, base_type::elements_) \
654656
} \
655657
return element{_soa_impl_index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_ELEMENT_CONSTR_CALL, ~, VALUE_LIST)}; \
656658
} \
@@ -811,7 +813,7 @@ namespace cms::soa {
811813
const_element operator[](size_type _soa_impl_index) const { \
812814
if constexpr (rangeChecking == cms::soa::RangeChecking::enabled) { \
813815
if (_soa_impl_index >= elements_ or _soa_impl_index < 0) \
814-
SOA_THROW_OUT_OF_RANGE("Out of range index in " #CONST_VIEW "::operator[]") \
816+
SOA_THROW_OUT_OF_RANGE("Out of range index in " #CONST_VIEW "::operator[]", _soa_impl_index, elements_) \
815817
} \
816818
return const_element{ \
817819
_soa_impl_index, _ITERATE_ON_ALL_COMMA(_DECLARE_VIEW_CONST_ELEMENT_CONSTR_CALL, ~, VALUE_LIST) \

DataFormats/SoATemplate/test/BuildFile.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<use name="boost"/>
44
<use name="cuda"/>
55
<use name="eigen"/>
6+
<use name="DataFormats/SoATemplate"/>
67
<use name="HeterogeneousCore/CUDAUtilities"/>
78
</bin>
89
</iftool>
@@ -12,19 +13,22 @@
1213
<use name="boost"/>
1314
<use name="eigen"/>
1415
<use name="rocm"/>
16+
<use name="DataFormats/SoATemplate"/>
1517
<use name="HeterogeneousCore/ROCmUtilities"/>
1618
</bin>
1719
</iftool>
1820

1921
<bin file="SoAUnitTests.cc" name="SoAUnitTests">
2022
<use name="boost"/>
2123
<use name="catch2"/>
24+
<use name="DataFormats/SoATemplate"/>
2225
</bin>
2326

2427

2528
<!-- This test triggers a bug in ROOT, so it's kept disabled
2629
<bin file="SoAStreamer_t.cpp" name="SoAStreamer_t">
2730
<use name="root"/>
31+
<use name="DataFormats/SoATemplate"/>
2832
</bin>
2933
-->
3034

0 commit comments

Comments
 (0)