When compiling CMSSW with GCC 14, several warnings are emitted due to a cast from unsigned int to std::atomic<unsigned int>&:
src/HeterogeneousCore/CUDAUtilities/interface/OneToManyAssoc.h: In instantiation of 'void cms::cuda::OneToManyAssoc<I, ONES, SIZE>::add(const CountersOnly&) [with I = short unsigned int; int ONES = 8; int SIZE = 8000; CountersOnly = cms::cuda::OneToManyAssoc<short unsigned int, 8, 0>]':
src/HeterogeneousCore/CUDAUtilities/test/OneToManyAssoc_t.h:45:17: required from here
45 | assoc->add(local);
| ~~~~~~~~~~^~~~~~~
src/HeterogeneousCore/CUDAUtilities/interface/OneToManyAssoc.h:196:21: warning: casting 'unsigned int' to 'std::atomic<unsigned int>&' does not use 'constexpr std::atomic<unsigned int>::atomic(__integral_type)' [-Wcast-user-defined]
196 | auto &a = (std::atomic<Counter> &)(off[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The issue originates from, e.g., this code in OneToManyAssoc.h
__host__ __device__ __forceinline__ void add(CountersOnly const &co) {
for (int32_t i = 0; i < totOnes(); ++i) {
#ifdef __CUDA_ARCH__
atomicAdd(off.data() + i, co.off[i]);
#else
auto &a = (std::atomic<Counter> &)(off[i]); // Warning: Unsafe cast
a += co.off[i];
#endif
}
}
This cast is not valid because the C++ standard does not guarantee that std::atomic<T> has the same memory layout as T.
When compiling CMSSW with GCC 14, several warnings are emitted due to a cast from
unsigned inttostd::atomic<unsigned int>&:The issue originates from, e.g., this code in OneToManyAssoc.h
This cast is not valid because the C++ standard does not guarantee that
std::atomic<T>has the same memory layout asT.