40#include "../linear_algebra/GPUComms.cuh"
51inline constexpr size_t round_up(
size_t multiple,
size_t x) {
return ((x + multiple - 1) / multiple) * multiple; }
60template <
class T,
bool ZeroInit = false>
64 if (alignment <
alignof(
void*)) alignment =
alignof(
void*);
72 if (::posix_memalign(&ptr, alignment, size) != 0) {
76 ptr = _aligned_malloc(size, alignment);
80 if (ZeroInit) memset(ptr, 0, size);
82 return static_cast<T*
>(ptr);
107template <
class T,
bool ZeroInit = false>
111#if defined(HAVE_CUDA)
112 gpuErrChk(cudaMalloc((
void**)(&ptr), size));
113 if (ZeroInit)
gpuErrChk(cudaMemset((
void*)(ptr), 0.0, size));
118 return static_cast<T*
>(ptr);
141 gpuErrChk(cudaMalloc((
void**)(&ptr), size));
142 gpuErrChk(cudaMemcpy((
void*)(ptr), (
void*)src_ptr, size, cudaMemcpyHostToDevice));
145 return static_cast<T*
>(ptr);
158template <
class T,
bool ZeroInit = false>
162#if defined(HAVE_CUDA)
163 gpuErrChk(cudaMallocHost((
void**)(&ptr), size));
164 if (ZeroInit) memset(ptr, 0, size);
169 return static_cast<T*
>(ptr);
#define gpuErrChk(ans)
Definition GPUComms.cuh:58
Definition allocation_toolbox.hpp:100
T * gpu_alloc(size_t size) noexcept
Memory allocation for variables on the GPU.
Definition allocation_toolbox.hpp:108
void pinned_free(T *ptr) noexcept
Free memory allocated with pinned_alloc.
Definition allocation_toolbox.hpp:177
T * pinned_alloc(size_t size) noexcept
Page-locked ("pinned") host memory allocation.
Definition allocation_toolbox.hpp:159
void gpu_free(T *ptr) noexcept
Free memory allocated on the GPU with gpu_alloc.
Definition allocation_toolbox.hpp:126
T * gpu_alloc_cpy(const T *src_ptr, size_t size) noexcept
Memory allocation for variables on the GPU along with initialization from a source host array.
Definition allocation_toolbox.hpp:137
Definition allocation_toolbox.hpp:47
void aligned_free(T *ptr) noexcept
Free memory allocated with su2::aligned_alloc.
Definition allocation_toolbox.hpp:90
constexpr bool is_power_of_two(size_t x)
Definition allocation_toolbox.hpp:49
constexpr size_t round_up(size_t multiple, size_t x)
Definition allocation_toolbox.hpp:51
T * aligned_alloc(size_t alignment, size_t size) noexcept
Aligned memory allocation compatible across platforms.
Definition allocation_toolbox.hpp:61