7#include <Kokkos_Core.hpp>
15#define NEON_LAMBDA KOKKOS_LAMBDA
16#define NEON_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
20using Kokkos::atomic_add;
21using Kokkos::atomic_sub;
24#define NEON_LAMBDA [&]
36template<
typename ValueType>
41template<
typename Kernel>
45 } -> std::same_as<void>;
50template<
typename ExecutorType>
54 if (logger !=
nullptr)
61template<
typename ExecutorType, parallelForKernel Kernel>
63 const ExecutorType&, std::pair<localIdx, localIdx> range,
const Kernel& kernel, std::string
name
66 auto [start, end] = range;
68 if constexpr (std::is_same<std::remove_reference_t<ExecutorType>,
SerialExecutor>::value)
70 for (
localIdx i = start; i < end; i++)
77 using runOn =
typename ExecutorType::exec;
85 name, Kokkos::RangePolicy<runOn, Kokkos::IndexType<localIdx>>(start, end), kernel
92template<parallelForKernel Kernel>
95 std::pair<localIdx, localIdx> range,
97 std::string
name =
"parallelFor"
100 std::visit([&](
const auto& e) {
parallelFor(e, range, kernel,
name); }, exec);
104template<
typename Kernel,
typename ValueType>
108 } -> std::same_as<ValueType>;
119 ContType<ValueType>& container,
120 const Kernel& kernel,
121 std::string
name =
"parallelFor"
124 auto view = container.view();
125 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
127 for (
localIdx i = 0; i < view.size(); i++)
134 using runOn =
typename Executor::exec;
135 Kokkos::parallel_for(
137 Kokkos::RangePolicy<runOn>(0, view.size()),
147 parallelForContainerKernel<ValueType> Kernel>
148void parallelFor(ContType<ValueType>& cont,
const Kernel& kernel, std::string
name =
"parallelFor")
150 std::visit([&](
const auto& e) {
parallelFor(e, cont, kernel,
name); }, cont.exec());
153template<
typename Executor,
typename Kernel,
typename T>
155 [[maybe_unused]]
const Executor& exec,
156 std::pair<localIdx, localIdx> range,
157 const Kernel& kernel,
161 auto [start, end] = range;
162 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
164 for (
localIdx i = start; i < end; i++)
166 if constexpr (Kokkos::is_reducer<T>::value)
168 kernel(i, value.reference());
178 using runOn =
typename Executor::exec;
179 Kokkos::parallel_reduce(
180 "parallelReduce", Kokkos::RangePolicy<runOn>(start, end), kernel, value
185template<
typename Kernel,
typename T>
187 const NeoN::Executor& exec, std::pair<localIdx, localIdx> range,
const Kernel& kernel, T& value
190 std::visit([&](
const auto& e) {
parallelReduce(e, range, kernel, value); }, exec);
194template<
typename Executor,
typename ValueType,
typename Kernel,
typename T>
199 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
202 for (
localIdx i = 0; i < fieldSize; i++)
204 if constexpr (Kokkos::is_reducer<T>::value)
206 kernel(i, value.reference());
216 using runOn =
typename Executor::exec;
217 Kokkos::parallel_reduce(
218 "parallelReduce", Kokkos::RangePolicy<runOn>(0, field.
size()), kernel, value
223template<
typename ValueType,
typename Kernel,
typename T>
226 std::visit([&](
const auto& e) {
parallelReduce(e, field, kernel, value); }, field.
exec());
229template<
typename Executor,
typename Kernel>
231 [[maybe_unused]]
const Executor& exec, std::pair<localIdx, localIdx> range,
const Kernel& kernel
234 auto [start, end] = range;
235 using runOn =
typename Executor::exec;
236 Kokkos::parallel_scan(
"parallelScan", Kokkos::RangePolicy<runOn>(start, end), kernel);
239template<
typename Kernel>
241 const NeoN::Executor& exec, std::pair<localIdx, localIdx> range,
const Kernel& kernel
244 std::visit([&](
const auto& e) {
parallelScan(e, range, kernel); }, exec);
247template<
typename Executor,
typename Kernel,
typename ReturnType>
249 [[maybe_unused]]
const Executor& exec,
250 std::pair<localIdx, localIdx> range,
251 const Kernel& kernel,
252 ReturnType& returnValue
255 auto [start, end] = range;
256 using runOn =
typename Executor::exec;
257 Kokkos::parallel_scan(
258 "parallelScan", Kokkos::RangePolicy<runOn>(start, end), kernel, returnValue
262template<
typename Kernel,
typename ReturnType>
265 std::pair<localIdx, localIdx> range,
266 const Kernel& kernel,
267 ReturnType& returnValue
270 std::visit([&](
const auto& e) {
parallelScan(e, range, kernel, returnValue); }, exec);
Reference executor for serial CPU execution.
A class to contain the data and executors for a field and define some basic operations.
localIdx size() const
Gets the size of the field.
const Executor & exec() const
Gets the executor associated with the field.
Integer types used throughout NeoN.
void fenceIfLogger(const ExecutorType &exec)
void fence(const Executor &exec)
std::shared_ptr< const Logging::BaseLogger > getLogger(const Executor &exec)
void parallelScan(const Executor &exec, std::pair< localIdx, localIdx > range, const Kernel &kernel)
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.
void parallelReduce(const Executor &exec, std::pair< localIdx, localIdx > range, const Kernel &kernel, T &value)