CMS 3D CMS Logo

TestAlgo.dev.cc
Go to the documentation of this file.
1 // Check that ALPAKA_HOST_ONLY is not defined during device compilation:
2 #ifdef ALPAKA_HOST_ONLY
3 #error ALPAKA_HOST_ONLY defined in device compilation
4 #endif
5 
6 #include <alpaka/alpaka.hpp>
7 
12 
13 #include "TestAlgo.h"
14 
16 
17  using namespace cms::alpakatools;
18 
20  public:
21  template <typename TAcc, typename = std::enable_if_t<is_accelerator_v<TAcc>>>
22  ALPAKA_FN_ACC void operator()(TAcc const& acc, portabletest::TestDeviceCollection::View view, int32_t size) const {
23  // global index of the thread within the grid
24  const int32_t thread = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0u];
25  const portabletest::Matrix matrix{{1, 2, 3, 4, 5, 6}, {2, 4, 6, 8, 10, 12}, {3, 6, 9, 12, 15, 18}};
26 
27  // set this only once in the whole kernel grid
28  if (thread == 0) {
29  view.r() = 1.;
30  }
31 
32  // make a strided loop over the kernel grid, covering up to "size" elements
33  for (int32_t i : elements_with_stride(acc, size)) {
34  view[i] = {0., 0., 0., i, matrix * i};
35  }
36  }
37  };
38 
40  // use 64 items per group (this value is arbitrary, but it's a reasonable starting point)
41  uint32_t items = 64;
42 
43  // use as many groups as needed to cover the whole problem
44  uint32_t groups = divide_up_by(collection->metadata().size(), items);
45 
46  // map items to
47  // - threads with a single element per thread on a GPU backend
48  // - elements within a single thread on a CPU backend
49  auto workDiv = make_workdiv<Acc1D>(groups, items);
50 
51  alpaka::exec<Acc1D>(queue, workDiv, TestAlgoKernel{}, collection.view(), collection->metadata().size());
52  }
53 
54 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
size
Write out results.
constexpr Idx divide_up_by(Idx value, Idx divisor)
Definition: workdivision.h:20
void fill(Queue &queue, portabletest::TestDeviceCollection &collection) const
Definition: TestAlgo.dev.cc:39
Eigen::Matrix< double, 3, 6 > Matrix
Definition: TestSoA.h:13
ALPAKA_FN_ACC void operator()(TAcc const &acc, portabletest::TestDeviceCollection::View view, int32_t size) const
Definition: TestAlgo.dev.cc:22