24 const char *file,
int line)
26 mfem::err <<
"\n\nCUDA error: (" << expr <<
") failed with error:\n --> "
27 << cudaGetErrorString(err)
28 <<
"\n ... in function: " << func
29 <<
"\n ... in file: " << file <<
':' << line <<
'\n';
37 #ifdef MFEM_TRACK_CUDA_MEM
38 mfem::out <<
"CuMemAlloc(): allocating " << bytes <<
" bytes ... "
41 MFEM_GPU_CHECK(cudaMalloc(dptr, bytes));
42 #ifdef MFEM_TRACK_CUDA_MEM
43 mfem::out <<
"done: " << *dptr << std::endl;
52 #ifdef MFEM_TRACK_CUDA_MEM
53 mfem::out <<
"CuMallocManaged(): allocating " << bytes <<
" bytes ... "
56 MFEM_GPU_CHECK(cudaMallocManaged(dptr, bytes));
57 #ifdef MFEM_TRACK_CUDA_MEM
58 mfem::out <<
"done: " << *dptr << std::endl;
67 #ifdef MFEM_TRACK_CUDA_MEM
68 mfem::out <<
"CuMemFree(): deallocating memory @ " << dptr <<
" ... "
71 MFEM_GPU_CHECK(cudaFree(dptr));
72 #ifdef MFEM_TRACK_CUDA_MEM
82 #ifdef MFEM_TRACK_CUDA_MEM
83 mfem::out <<
"CuMemcpyHtoD(): copying " << bytes <<
" bytes from "
84 << src <<
" to " << dst <<
" ... " << std::flush;
86 MFEM_GPU_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyHostToDevice));
87 #ifdef MFEM_TRACK_CUDA_MEM
97 MFEM_GPU_CHECK(cudaMemcpyAsync(dst, src, bytes, cudaMemcpyHostToDevice));
105 #ifdef MFEM_TRACK_CUDA_MEM
106 mfem::out <<
"CuMemcpyDtoD(): copying " << bytes <<
" bytes from "
107 << src <<
" to " << dst <<
" ... " << std::flush;
109 MFEM_GPU_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyDeviceToDevice));
110 #ifdef MFEM_TRACK_CUDA_MEM
120 MFEM_GPU_CHECK(cudaMemcpyAsync(dst, src, bytes, cudaMemcpyDeviceToDevice));
128 #ifdef MFEM_TRACK_CUDA_MEM
129 mfem::out <<
"CuMemcpyDtoH(): copying " << bytes <<
" bytes from "
130 << src <<
" to " << dst <<
" ... " << std::flush;
132 MFEM_GPU_CHECK(cudaMemcpy(dst, src, bytes, cudaMemcpyDeviceToHost));
133 #ifdef MFEM_TRACK_CUDA_MEM
143 MFEM_GPU_CHECK(cudaMemcpyAsync(dst, src, bytes, cudaMemcpyDeviceToHost));
151 MFEM_GPU_CHECK(cudaGetLastError());
159 MFEM_GPU_CHECK(cudaGetDeviceCount(&num_gpus));
void * CuMemcpyHtoD(void *dst, const void *src, size_t bytes)
Copies memory from Host to Device.
void * CuMemFree(void *dptr)
Frees device memory.
void CuCheckLastError()
Check the error code returned by cudaGetLastError(), aborting on error.
int CuGetDeviceCount()
Get the number of CUDA devices.
void * CuMallocManaged(void **dptr, size_t bytes)
Allocates managed device memory.
void mfem_cuda_error(cudaError_t err, const char *expr, const char *func, const char *file, int line)
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
void * CuMemcpyDtoD(void *dst, const void *src, size_t bytes)
Copies memory from Device to Device.
void * CuMemcpyDtoDAsync(void *dst, const void *src, size_t bytes)
Copies memory from Device to Device.
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
void * CuMemcpyDtoHAsync(void *dst, const void *src, size_t bytes)
Copies memory from Device to Host.
void * CuMemcpyHtoDAsync(void *dst, const void *src, size_t bytes)
Copies memory from Host to Device.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void * CuMemAlloc(void **dptr, size_t bytes)
Allocates device memory.
void * CuMemcpyDtoH(void *dst, const void *src, size_t bytes)
Copies memory from Device to Host.