cms-sw / cmssw

CMS Offline Software
http://cms-sw.github.io/
Apache License 2.0
1.06k stars 4.26k forks source link

RecoTracker/PixelSeeding: array subscript ... is above array bounds in Alpaka/FlexiStorage #45179

Open iarspider opened 1 month ago

iarspider commented 1 month ago

In all IBs, GCC emits the following warnings:

>> Building alpaka/serial edm plugin tmp/el8_amd64_gcc12/src/RecoTracker/PixelSeeding/plugins/RecoTrackerPixelSeedingPortableSerialSync/libRecoTrackerPixelSeedingPortableSerialSync.so
(... gcc invocation ...)
In member function 'operator[]',
    inlined from 'size' at src/HeterogeneousCore/AlpakaInterface/interface/OneToManyAssoc.h:144:55,
    inlined from 'operator()' at src/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h:553:42,
    inlined from '__invoke_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:61:36,
    inlined from '__invoke' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:96:40,
    inlined from '__apply_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1852:27,
    inlined from 'apply' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1863:31,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:92:31,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:25:14,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:44:27,
    inlined from 'ndLoop' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:71:27,
    inlined from 'ndLoopIncIdx' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:83:15,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:86:31:
  src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:15:60: warning: array subscript 262145 is above array bounds of 'const unsigned int[262145]' [-Warray-bounds]
    15 |     constexpr const I& operator[](int i) const { return m_v[i]; }
      |                                                            ^
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h: In member function 'operator()':
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:21:7: note: while referencing 'm_v'
   21 |     I m_v[S];
      |       ^
In member function 'operator[]',
    inlined from 'size' at src/HeterogeneousCore/AlpakaInterface/interface/OneToManyAssoc.h:144:55,
    inlined from 'operator()' at src/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h:553:42,
    inlined from '__invoke_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:61:36,
    inlined from '__invoke' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:96:40,
    inlined from '__apply_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1852:27,
    inlined from 'apply' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1863:31,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:92:31,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:25:14,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:44:27,
    inlined from 'ndLoop' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:71:27,
    inlined from 'ndLoopIncIdx' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:83:15,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:86:31:
  src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:15:60: warning: array subscript 262145 is above array bounds of 'const unsigned int[262145]' [-Warray-bounds]
    15 |     constexpr const I& operator[](int i) const { return m_v[i]; }
      |                                                            ^
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h: In member function 'operator()':
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:21:7: note: while referencing 'm_v'
   21 |     I m_v[S];
      |       ^
In member function 'operator[]',
    inlined from 'size' at src/HeterogeneousCore/AlpakaInterface/interface/OneToManyAssoc.h:144:55,
    inlined from 'operator()' at src/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h:553:42,
    inlined from '__invoke_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:61:36,
    inlined from '__invoke' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/bits/invoke.h:96:40,
    inlined from '__apply_impl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1852:27,
    inlined from 'apply' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/gcc/12.3.1-40d504be6370b5a30e3947a6e575ca28/include/c++/12.3.1/tuple:1863:31,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:92:31,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:25:14,
    inlined from 'ndLoopImpl' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:44:27,
    inlined from 'ndLoop' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:71:27,
    inlined from 'ndLoopIncIdx' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/meta/NdLoop.hpp:83:15,
    inlined from 'operator()' at /data/cmsbld/jenkins/workspace/build-any-ib/w/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include/alpaka/kernel/TaskKernelCpuSerial.hpp:86:31:
  src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:15:60: warning: array subscript 32769 is above array bounds of 'const unsigned int[32769]' [-Warray-bounds]
    15 |     constexpr const I& operator[](int i) const { return m_v[i]; }
      |                                                            ^
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h: In member function 'operator()':
src/HeterogeneousCore/AlpakaInterface/interface/FlexiStorage.h:21:7: note: while referencing 'm_v'
   21 |     I m_v[S];
      |       ^
cmsbuild commented 1 month ago

cms-bot internal usage

cmsbuild commented 1 month ago

A new Issue was created by @iarspider.

@antoniovilela, @smuzaffar, @makortel, @rappoccio, @sextonkennedy, @Dr15Jones can you please review it and eventually sign/assign? Thanks.

cms-bot commands are listed here

iarspider commented 1 month ago

assign HeterogeneousCore/AlpakaInterface,RecoTracker/PixelSeeding

cmsbuild commented 1 month ago

New categories assigned: heterogeneous,reconstruction

@fwyzard,@jfernan2,@makortel,@mandrenguyen you have been requested to review this Pull request/Issue and eventually sign? Thanks

iarspider commented 1 month ago

First occurrence in CMSSW_14_1_X_2024-06-05-2300

slava77 commented 1 month ago

@AdrianoDee in case you haven't received this already

Dr15Jones commented 3 weeks ago

This is probably not a real issue. [I think I was wrong initially] https://github.com/cms-sw/cmssw/blob/64d4f3b087ce5832f186bc811757c17e16fb9ddd/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernelsImpl.h#L552-L553

with the final line calls

https://github.com/cms-sw/cmssw/blob/64d4f3b087ce5832f186bc811757c17e16fb9ddd/HeterogeneousCore/AlpakaInterface/interface/OneToManyAssoc.h#L144

notice the b+1. The documentation for uniform_elements has

https://github.com/cms-sw/cmssw/blob/64d4f3b087ce5832f186bc811757c17e16fb9ddd/HeterogeneousCore/AlpakaInterface/interface/workdivision.h#L254-L255

so the b+1 will be the size of the container so off[b+1] at first glance seems to be off the end of the container.

However, looking at the definition of nOnes()

https://github.com/cms-sw/cmssw/blob/64d4f3b087ce5832f186bc811757c17e16fb9ddd/HeterogeneousCore/CUDAUtilities/interface/OneToManyAssoc.h#L167

and

https://github.com/cms-sw/cmssw/blob/64d4f3b087ce5832f186bc811757c17e16fb9ddd/HeterogeneousCore/CUDAUtilities/interface/OneToManyAssoc.h#L166

then assuming capacity is the true size of the container, than off[b+1] for the end condition should be off[ (nOnes()-1) +1] ==off[( (totOnes()-1)-1 ) +1 ] == off[totOnes() -1]

fwyzard commented 3 weeks ago

@Dr15Jones thanks for looking into this issue 👍🏻

VinInn commented 3 weeks ago

yep. All that was indeed intentional (at least in the CUDA version).

smuzaffar commented 3 weeks ago

I have opened https://github.com/cms-sw/cmssw/pull/45340 to suppress this error

Dr15Jones commented 3 weeks ago

One more item, if I add

assert(static_cast<decltype(tracks_view.hitIndices().nOnes())>(idx) < tracks_view.hitIndices().nOnes());

right before the call to size the warning goes away. Evidently that helped the link time optimizer to see the index can not go out of bounds. The question is why the optimizer thinks uniform_elements can go out of bounds when given nOnes() as the end point.

Dr15Jones commented 3 weeks ago

A bit more investigation, if I change the loop condition to actually be on the end, i.e.

for (auto idx : cms::alpakatools::uniform_elements(acc, tracks_view.hitIndices().totOnes()))

the warning states that the value goes 1 beyond the end, instead of just the end (which is what is actually going on). So the compiler really thinks that cms::alpakatools::uniform_elements end condition is inclusive instead of exclusive.