Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function for "for each element loop" #170

Open
makortel opened this issue Feb 2, 2021 · 0 comments
Open

Add a helper function for "for each element loop" #170

makortel opened this issue Feb 2, 2021 · 0 comments
Labels

Comments

@makortel
Copy link
Collaborator

makortel commented Feb 2, 2021

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);
  ...
}
@makortel makortel added the alpaka label Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant