NeoN
A framework for CFD software
Loading...
Searching...
No Matches
GPUExecutor.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
15
23{
24
25 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
26
27public:
28
29 using exec = Kokkos::DefaultExecutionSpace;
30
32
33 GPUExecutor(std::unique_ptr<AllocatorStrategy> strategy);
34
36
37 /*@brief allocation of size elements of sizeof(T) bytes */
38 template<typename T>
39 T* alloc(size_t elements) const
40 {
41 if (!allocContext_)
42 {
43 NF_ERROR_EXIT("No allocator set");
44 }
45 return allocContext_->alloc<T>(elements);
46 }
47
48 template<typename T>
49 T* realloc(void* ptr, size_t elements) const
50 {
51 if (!allocContext_)
52 {
53 NF_ERROR_EXIT("No allocator set");
54 }
55 return allocContext_->realloc<T>(ptr, elements);
56 }
57
58 void free(void* ptr) const noexcept
59 {
60 if (!allocContext_)
61 {
62 NF_ERROR_EXIT("No allocator set");
63 }
64 allocContext_->free(ptr);
65 }
66
68
76 template<typename ValueType>
77 decltype(auto) createKokkosView(ValueType* ptr, size_t size) const
78 {
79 return Kokkos::View<ValueType*, Kokkos::DefaultExecutionSpace, Kokkos::MemoryUnmanaged>(
80 ptr, size
81 );
82 }
83
84 std::string name() const { return "GPUExecutor"; };
85
86 exec underlyingExec() const { return exec {}; }
87};
88
89} // namespace NeoN
Executor for GPU offloading.
T * alloc(size_t elements) const
T * realloc(void *ptr, size_t elements) const
GPUExecutor(std::unique_ptr< AllocatorStrategy > strategy)
Kokkos::DefaultExecutionSpace exec
MemorySpace memorySpace() const noexcept
decltype(auto) createKokkosView(ValueType *ptr, size_t size) const
create a Kokkos view for a given ptr
exec underlyingExec() const
void free(void *ptr) const noexcept
std::string name() const
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