NeoN
A framework for CFD software
Loading...
Searching...
No Matches
CPUExecutor.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2026 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
10#include <Kokkos_Core.hpp> // IWYU pragma: keep
11
12namespace NeoN
13{
14
23{
24 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
25
26public:
27
28 using exec = Kokkos::DefaultHostExecutionSpace;
29
31
32 CPUExecutor(std::unique_ptr<AllocatorStrategy> strategy);
33
35
36 template<typename T>
37 T* alloc(size_t elements) const
38 {
39 if (!allocContext_)
40 {
41 NF_ERROR_EXIT("No allocator set");
42 }
43 return allocContext_->alloc<T>(elements);
44 }
45
46 template<typename T>
47 T* realloc(void* ptr, size_t elements) const
48 {
49 if (!allocContext_)
50 {
51 NF_ERROR_EXIT("No allocator set");
52 }
53 return allocContext_->realloc<T>(ptr, elements);
54 }
55
56 void free(void* ptr) const noexcept { allocContext_->free(ptr); }
57
59
67 template<typename ValueType>
68 decltype(auto) createKokkosView(ValueType* ptr, size_t size) const
69 {
70 return Kokkos::View<ValueType*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(ptr, size);
71 }
72
73 std::string name() const { return "CPUExecutor"; };
74
75 exec underlyingExec() const { return exec {}; }
76};
77
78} // namespace NeoN
Executor for handling multicore CPU based parallelization.
T * realloc(void *ptr, size_t elements) const
CPUExecutor(std::unique_ptr< AllocatorStrategy > strategy)
T * alloc(size_t elements) const
exec underlyingExec() const
decltype(auto) createKokkosView(ValueType *ptr, size_t size) const
create a Kokkos view for a given ptr
Kokkos::DefaultHostExecutionSpace exec
std::string name() const
MemorySpace memorySpace() const noexcept
void free(void *ptr) const noexcept
a Logging Mixin class that allows to attach logger to certain classes
Definition logging.hpp:229
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
Definition error.hpp:90
Integer types used throughout NeoN.
Definition array.hpp:18
MemorySpace
Definition allocator.hpp:17