alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
alignedAlloc.hpp
Go to the documentation of this file.
1/* Copyright 2022 René Widera, Bernhard Manfred Gruber
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
9
10#include <cstddef>
11#include <new>
12
13namespace alpaka::core
14{
15 ALPAKA_FN_INLINE ALPAKA_FN_HOST auto alignedAlloc(size_t alignment, size_t size) -> void*
16 {
17 if(size == 0u)
18 {
19 return nullptr;
20 }
21 else
22 {
23 return ::operator new(size, std::align_val_t{alignment});
24 }
25 }
26
27 ALPAKA_FN_INLINE ALPAKA_FN_HOST void alignedFree(size_t alignment, auto ptr)
28 requires(std::is_pointer_v<ALPAKA_TYPEOF(ptr)>)
29 {
30 if(ptr != nullptr)
31 {
32 ::operator delete(toVoidPtr(ptr), std::align_val_t{alignment});
33 }
34 }
35} // namespace alpaka::core
#define ALPAKA_FN_HOST
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
Definition common.hpp:33
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
#define ALPAKA_FN_INLINE
Macro defining the inline function attribute.
Definition common.hpp:88
ALPAKA_FN_INLINE ALPAKA_FN_HOST void alignedFree(size_t alignment, auto ptr)
ALPAKA_FN_INLINE ALPAKA_FN_HOST auto alignedAlloc(size_t alignment, size_t size) -> void *
auto * toVoidPtr(T inPtr)
Cast a pointer that may or may not point to volatile memory to a (void*) or (void const*).
Definition util.hpp:34