NeoN
A framework for CFD software
Loading...
Searching...
No Matches
serialExecutor.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>
11
12namespace NeoN
13{
14
22{
23 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
24
25public:
26
27 using exec = Kokkos::Serial;
28
30
31 SerialExecutor(std::unique_ptr<AllocatorStrategy> strategy);
32
34
35 template<typename T>
36 T* alloc(sizeType elements) const
37 {
38 if (!allocContext_)
39 {
40 NF_ERROR_EXIT("No allocator set");
41 }
42 return allocContext_->alloc<T>(elements);
43 }
44
45 template<typename T>
46 T* realloc(void* ptr, sizeType elements) const
47 {
48 if (!allocContext_)
49 {
50 NF_ERROR_EXIT("No allocator set");
51 }
52 return allocContext_->realloc<T>(ptr, elements);
53 }
54
55 void free(void* ptr) const noexcept
56 {
57 if (!allocContext_)
58 {
59 NF_ERROR_EXIT("No allocator set");
60 }
61 allocContext_->free(ptr);
62 }
63
64 MemorySpace memorySpace() const noexcept { return MemorySpace::CPU; }
65
73 template<typename ValueType>
74 decltype(auto) createKokkosView(ValueType* ptr, sizeType size) const
75 {
76 return Kokkos::View<ValueType*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(ptr, size);
77 }
78
79 std::string name() const { return "SerialExecutor"; };
80
81 exec underlyingExec() const { return exec {}; }
82};
83
84} // namespace NeoN
a Logging Mixin class that allows to attach logger to certain classes
Definition logging.hpp:229
T * alloc(sizeType elements) const
SerialExecutor(std::unique_ptr< AllocatorStrategy > strategy)
MemorySpace memorySpace() const noexcept
void free(void *ptr) const noexcept
T * realloc(void *ptr, sizeType elements) const
std::string name() const
exec underlyingExec() const
decltype(auto) createKokkosView(ValueType *ptr, sizeType size) const
create a Kokkos view for a given ptr
#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
std::size_t sizeType
Definition label.hpp:56
MemorySpace
Definition allocator.hpp:18