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
7#include <Kokkos_Core.hpp>
8#include <memory>
9#include <string>
10
11#include "NeoN/core/logging.hpp"
13#include "NeoN/core/error.hpp"
15
16namespace NeoN
17{
18
26{
27 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
28
29public:
30
31 using exec = Kokkos::Serial;
32
34
35 SerialExecutor(std::unique_ptr<AllocatorStrategy> strategy);
36
38
39 template<typename T>
40 T* alloc(sizeType elements) const
41 {
42 if (!allocContext_)
43 {
44 NF_ERROR_EXIT("No allocator set");
45 }
46 return allocContext_->alloc<T>(elements);
47 }
48
49 template<typename T>
50 T* realloc(void* ptr, sizeType elements) const
51 {
52 if (!allocContext_)
53 {
54 NF_ERROR_EXIT("No allocator set");
55 }
56 return allocContext_->realloc<T>(ptr, elements);
57 }
58
59 void free(void* ptr) const noexcept
60 {
61 if (!allocContext_)
62 {
63 NF_ERROR_EXIT("No allocator set");
64 }
65 allocContext_->free(ptr);
66 }
67
68 MemorySpace memorySpace() const noexcept { return MemorySpace::CPU; }
69
77 template<typename ValueType>
78 decltype(auto) createKokkosView(ValueType* ptr, sizeType size) const
79 {
80 return Kokkos::View<ValueType*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(ptr, size);
81 }
82
83 std::string name() const { return "SerialExecutor"; };
84
85 exec underlyingExec() const { return exec {}; }
86};
87
88} // namespace NeoN
a Logging Mixin class that allows to attach logger to certain classes
Definition logging.hpp:208
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