1#ifndef ABACUS_SOURCE_HAMILT_MODULE_GINT_KERNEL_CUDA_MEM_WRAPPER_H
2#define ABACUS_SOURCE_HAMILT_MODULE_GINT_KERNEL_CUDA_MEM_WRAPPER_H
6#include <cuda_runtime.h>
19 this->
size_ = other.size_;
23 other.device_ptr_ =
nullptr;
24 other.host_ptr_ =
nullptr;
26 other.malloc_host_ =
false;
36 this->
size_ = other.size_;
40 other.device_ptr_ =
nullptr;
41 other.host_ptr_ =
nullptr;
43 other.malloc_host_ =
false;
49 CudaMemWrapper(
size_t size, cudaStream_t stream = 0,
bool malloc_host =
true)
117 CHECK_CUDA(cudaMemset(
device_ptr_, value, size *
sizeof(
T)));
135 CHECK_CUDA(cudaMemset(
host_ptr_, value, size *
sizeof(
T)));
T * get_host_ptr()
Definition cuda_mem_wrapper.h:147
void free()
Definition cuda_mem_wrapper.h:140
T * get_device_ptr()
Definition cuda_mem_wrapper.h:146
CudaMemWrapper & operator=(CudaMemWrapper &&other) noexcept
Definition cuda_mem_wrapper.h:30
void memset_device_sync(const int value=0)
Definition cuda_mem_wrapper.h:120
CudaMemWrapper(const CudaMemWrapper &other)=delete
cudaStream_t stream_
Definition cuda_mem_wrapper.h:157
void copy_device_to_host_sync(size_t size)
Definition cuda_mem_wrapper.h:93
T * host_ptr_
Definition cuda_mem_wrapper.h:154
void memset_device_sync(const size_t size, const int value=0)
Definition cuda_mem_wrapper.h:115
void copy_host_to_device_async(size_t size)
Definition cuda_mem_wrapper.h:82
size_t get_size() const
Definition cuda_mem_wrapper.h:150
const T * get_host_ptr() const
Definition cuda_mem_wrapper.h:149
~CudaMemWrapper()
Definition cuda_mem_wrapper.h:69
void copy_device_to_host_async()
Definition cuda_mem_wrapper.h:113
void memset_device_async(const size_t size, const int value=0)
Definition cuda_mem_wrapper.h:122
void copy_device_to_host_sync()
Definition cuda_mem_wrapper.h:102
CudaMemWrapper(size_t size, cudaStream_t stream=0, bool malloc_host=true)
Definition cuda_mem_wrapper.h:49
void copy_host_to_device_async()
Definition cuda_mem_wrapper.h:91
bool malloc_host_
Definition cuda_mem_wrapper.h:156
size_t size_
Definition cuda_mem_wrapper.h:155
void memset_host(const int value=0)
Definition cuda_mem_wrapper.h:138
T * device_ptr_
Definition cuda_mem_wrapper.h:153
void copy_host_to_device_sync(size_t size)
Definition cuda_mem_wrapper.h:71
CudaMemWrapper & operator=(const CudaMemWrapper &other)=delete
void copy_host_to_device_sync()
Definition cuda_mem_wrapper.h:80
void memset_host(const size_t size, const int value=0)
Definition cuda_mem_wrapper.h:129
void copy_device_to_host_async(size_t size)
Definition cuda_mem_wrapper.h:104
CudaMemWrapper(CudaMemWrapper &&other) noexcept
Definition cuda_mem_wrapper.h:15
const T * get_device_ptr() const
Definition cuda_mem_wrapper.h:148
void memset_device_async(const int value=0)
Definition cuda_mem_wrapper.h:127
#define T
Definition exp.cpp:237
void WARNING_QUIT(const std::string &, const std::string &)
Combine the functions of WARNING and QUIT.
Definition test_delley.cpp:15