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
10
11#include <Kokkos_Core.hpp> // IWYU pragma: keep
12
13namespace NeoN
14{
15
24{
25 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
26
27public:
28
29 using exec = Kokkos::DefaultHostExecutionSpace;
30
32
33 CPUExecutor(std::unique_ptr<AllocatorStrategy> strategy);
34
36
37 template<typename T>
38 T* alloc(sizeType elements) const
39 {
40 if (!allocContext_)
41 {
42 NF_ERROR_EXIT("No allocator set");
43 }
44 return allocContext_->alloc<T>(elements);
45 }
46
47 template<typename T>
48 T* realloc(void* ptr, sizeType elements) const
49 {
50 if (!allocContext_)
51 {
52 NF_ERROR_EXIT("No allocator set");
53 }
54 return allocContext_->realloc<T>(ptr, elements);
55 }
56
57 void free(void* ptr) const noexcept { allocContext_->free(ptr); }
58
59 MemorySpace memorySpace() const noexcept { return MemorySpace::CPU; }
60
68 template<typename ValueType>
69 decltype(auto) createKokkosView(ValueType* ptr, sizeType size) const
70 {
71 return Kokkos::View<ValueType*, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(ptr, size);
72 }
73
74 std::string name() const { return "CPUExecutor"; };
75
76 exec underlyingExec() const { return exec {}; }
77};
78
79} // namespace NeoN
CPUExecutor(std::unique_ptr< AllocatorStrategy > strategy)
T * alloc(sizeType elements) const
exec underlyingExec() const
decltype(auto) createKokkosView(ValueType *ptr, sizeType size) const
create a Kokkos view for a given ptr
Kokkos::DefaultHostExecutionSpace exec
std::string name() const
T * realloc(void *ptr, sizeType elements) 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
std::size_t sizeType
Definition label.hpp:56
MemorySpace
Definition allocator.hpp:18