alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
concurrent.hpp
Go to the documentation of this file.
1/* Copyright 2025 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include "alpaka/Vec.hpp"
9#include "alpaka/functor.hpp"
10#include "alpaka/onAcc/Acc.hpp"
14#include "alpaka/trait.hpp"
15
16namespace alpaka::onHost::internal
17{
18 struct SimdConcurrentKernel
19 {
20 ALPAKA_FN_ACC void operator()(
21 onAcc::concepts::Acc auto const& acc,
22 alpaka::concepts::VectorOrScalar auto const& extents,
23 auto const& func,
24 alpaka::concepts::IDataSource auto&&... inputs) const
25 {
26 Vec const extentMd = extents;
27 auto simdGrid = onAcc::SimdAlgo{onAcc::worker::threadsInGrid};
28
29 return simdGrid.concurrent(
30 acc,
31 extentMd,
32 [&func](auto const& acc, auto&&... in)
33 {
34 static_assert(
35 std::same_as<decltype(callFunctor(acc, func, ALPAKA_FORWARD(in)...)), void>,
36 "The return type for a stencil concurrent functor should be void.");
37 callFunctor(acc, func, ALPAKA_FORWARD(in)...);
38 },
39 ALPAKA_FORWARD(inputs)...);
40 }
41 };
42
43 template<typename T_DataType>
44 inline void concurrent(
45 auto const& queue,
46 alpaka::concepts::Executor auto const exec,
47 alpaka::concepts::VectorOrScalar auto const& extents,
48 auto&& fn,
49 alpaka::concepts::IDataSource auto&&... in)
50 {
51 Vec const extentMd = extents;
52 auto frameSpec = getFrameSpec<T_DataType>(queue.getDevice(), exec, extentMd);
53
56 [&]()
57 {
58 std::stringstream ss;
59 ss << "concurrent{ extents=" << extentMd << ", value_type=" << onHost::demangledName<T_DataType>()
60 << ", " << frameSpec << ", fn=" << onHost::demangledName(fn) << " }";
61 return ss.str();
62 });
63
64 queue.enqueue(
65 frameSpec,
66 KernelBundle{SimdConcurrentKernel{}, extentMd, ALPAKA_FORWARD(fn), ALPAKA_FORWARD(in)...});
67 }
68} // namespace alpaka::onHost::internal
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
Definition common.hpp:30
#define ALPAKA_FORWARD(instance)
Perfectly forward an instance as argument.
Definition common.hpp:147
#define ALPAKA_LOG_INFO(logLvl, callable)
Write a meta data message to the output.
Definition logger.hpp:106
constexpr auto threadsInGrid
constexpr auto queue
Definition lvl.hpp:127
constexpr auto memory
Definition lvl.hpp:112
constexpr auto demangledName()
ALPAKA_FN_HOST_ACC Vec(T_1, T_Args...) -> Vec< T_1, uint32_t(sizeof...(T_Args)+1u), ArrayStorage< T_1, uint32_t(sizeof...(T_Args)+1u)> >
ALPAKA_FN_HOST KernelBundle(TKernelFn const &, TArgs &&...) -> KernelBundle< TKernelFn, TArgs... >
User defined deduction guide with trailing return type. For CTAD during the construction.
constexpr auto callFunctor(T_Acc const &acc, T_Functor &&functor, T_Args &&... args)
Execute the functor with or without an accelerator as first argument.
Definition functor.hpp:58