-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
From https://github.com/cms-patatrack/pixeltrack-standalone/pull/165/files#r565486352
A pattern
const auto gridDim = ...;
const auto [firstNoStride, endNoStride] = ...;
for (auto threadIdx = firstNoStride, endElementIdx = endNoStride; threadIdx < MAX; threadIdx += gridDimension, endElementIdx += gridDimension) {
for (auto i = threadIdx; i < std::min(endElementIdx, MAX); ++i ) {
<body>
}
}seems to repeat often. The pattern could be abstracted along
namespace cms::alpakatools {
// the name should be more descriptive...
template <typename T_Acc, typename N, typename Func>
inline void for_each_element(const T_Acc& acc, const N nitems, Func func) {
const auto gridDim = ...;
const auto [firstNoStride, endNoStride] = ...;
for (auto threadIdx = firstNoStride, endElementIdx = endNoStride; threadIdx < nitems; threadIdx += gridDimension, endElementIdx += gridDimension) {
for (auto i = threadIdx; i < std::min(endElementIdx, nitems); ++i ) {
func(i);
}
}
}
}that could be called along
const uint32_t nt = offsets[nh];
cms::alpakatools::for_each_element(acc, nt, [&](uint32_t i) {
auto off = alpaka_std::upper_bound(offsets, offsets + nh + 1, i);
...
}