15#ifndef OPENJIJ_UTILITY_GPU_MEMORY_HPP__
16#define OPENJIJ_UTILITY_GPU_MEMORY_HPP__
23#include <cuda_runtime.h>
35 void operator()(
void *ptr)
const { HANDLE_ERROR_CUDA(cudaFree(ptr)); }
42 void operator()(
void *ptr)
const { HANDLE_ERROR_CUDA(cudaFreeHost(ptr)); }
50template <
typename T>
using unique_dev_ptr = std::unique_ptr<T, deleter_dev>;
57template <
typename T>
using unique_host_ptr = std::unique_ptr<T, deleter_host>;
67template <
typename T> cuda::unique_dev_ptr<T> make_dev_unique(std::size_t n) {
68 static_assert(std::is_array<T>::value,
"T must be an array.");
69 using U =
typename std::remove_extent<T>::type;
71 HANDLE_ERROR_CUDA(cudaMalloc(
reinterpret_cast<void **
>(&ptr),
sizeof(U) * n));
72 return cuda::unique_dev_ptr<T>{ptr};
83template <
typename T> cuda::unique_host_ptr<T> make_host_unique(std::size_t n) {
84 static_assert(std::is_array<T>::value,
"T must be an array.");
85 using U =
typename std::remove_extent<T>::type;
88 cudaMallocHost(
reinterpret_cast<void **
>(&ptr),
sizeof(U) * n));
89 return cuda::unique_host_ptr<T>{ptr};
Definition algorithm.hpp:24