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
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
19
27{
28
29 std::shared_ptr<AllocatorContext> allocContext_ = nullptr;
30
31public:
32
33 using exec = Kokkos::DefaultExecutionSpace;
34
36
37 GPUExecutor(std::unique_ptr<AllocatorStrategy> strategy);
38
40
41 /*@brief allocation of size elements of sizeof(T) bytes */
42 template<typename T>
43 T* alloc(sizeType elements) const
44 {
45 if (!allocContext_)
46 {
47 NF_ERROR_EXIT("No allocator set");
48 }
49 return allocContext_->alloc<T>(elements);
50 }
51
52 template<typename T>
53 T* realloc(void* ptr, sizeType elements) const
54 {
55 if (!allocContext_)
56 {
57 NF_ERROR_EXIT("No allocator set");
58 }
59 return allocContext_->realloc<T>(ptr, elements);
60 }
61
62 void free(void* ptr) const noexcept
63 {
64 if (!allocContext_)
65 {
66 NF_ERROR_EXIT("No allocator set");
67 }
68 allocContext_->free(ptr);
69 }
70
71 MemorySpace memorySpace() const noexcept { return MemorySpace::GPU; }
72
80 template<typename ValueType>
81 decltype(auto) createKokkosView(ValueType* ptr, sizeType size) const
82 {
83 return Kokkos::View<ValueType*, Kokkos::DefaultExecutionSpace, Kokkos::MemoryUnmanaged>(
84 ptr, size
85 );
86 }
87
88 std::string name() const { return "GPUExecutor"; };
89
90 exec underlyingExec() const { return exec {}; }
91};
92
93} // namespace NeoN
decltype(auto) createKokkosView(ValueType *ptr, sizeType size) const
create a Kokkos view for a given ptr
GPUExecutor(std::unique_ptr< AllocatorStrategy > strategy)
T * realloc(void *ptr, sizeType elements) const
T * alloc(sizeType elements) const
Kokkos::DefaultExecutionSpace exec
MemorySpace memorySpace() const noexcept
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:208
#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