QTrk
Classes | Macros | Functions
gpu_utils.h File Reference
#include <cuda_runtime.h>
#include <vector>
#include <cstdarg>
#include "cufft.h"
#include "LsqQuadraticFit.h"

Go to the source code of this file.

Classes

class  device_vec< T >
 
struct  MeasureTime
 
class  pinned_array< T, flags >
 

Macros

#define CUDA_SUPPORTED_FUNC   __device__ __host__
 
#define CUBOTH   __device__ __host__
 Kernel is callable from both device and host code. More...
 

Functions

void outputTotalGPUMemUse (std::string info="")
 
void CheckCUDAError (cufftResult_t err)
 
void CheckCUDAError (cudaError_t err)
 
void CheckCUDAError ()
 
void dbgCUDAErrorCheck (cudaError_t e)
 
void DbgCopyResult (device_vec< float2 > src, std::vector< std::complex< float > > &dst)
 
void DbgCopyResult (device_vec< float > src, std::vector< float > &dst)
 
void DbgOutputVectorToFile (std::string loc, device_vec< float > &src, bool append)
 

Macro Definition Documentation

§ CUBOTH

#define CUBOTH   __device__ __host__

Kernel is callable from both device and host code.

Definition at line 16 of file gpu_utils.h.

§ CUDA_SUPPORTED_FUNC

#define CUDA_SUPPORTED_FUNC   __device__ __host__

Definition at line 12 of file gpu_utils.h.

Function Documentation

§ CheckCUDAError() [1/3]

void CheckCUDAError ( cufftResult_t  err)
inline

Definition at line 36 of file gpu_utils.h.

37 {
38  if (err != CUFFT_SUCCESS) {
39  outputTotalGPUMemUse("CUFFT Error");
40  throw std::runtime_error(SPrintf("CUDA error: CUFFT failed (%d)\n",err));
41  }
42 }
void outputTotalGPUMemUse(std::string info="")
Definition: gpu_utils.h:18
std::string SPrintf(const char *fmt,...)
Definition: utils.cpp:132

§ CheckCUDAError() [2/3]

void CheckCUDAError ( cudaError_t  err)
inline

Definition at line 44 of file gpu_utils.h.

45 {
46  if (err != cudaSuccess) {
47  const char* errstr = cudaGetErrorString(err);
48  throw std::runtime_error(SPrintf("CUDA error: %s\n" ,errstr).c_str());
49  }
50 }
std::string SPrintf(const char *fmt,...)
Definition: utils.cpp:132

§ CheckCUDAError() [3/3]

void CheckCUDAError ( )
inline

Definition at line 52 of file gpu_utils.h.

53 {
54  cudaError_t err = cudaGetLastError();
55  if (err != cudaSuccess) {
56  const char* errstr = cudaGetErrorString(err);
57  dbgprintf("CUDA error: %s\n" ,errstr);
58  }
59 }
void dbgprintf(const char *fmt,...)
Definition: utils.cpp:149

§ DbgCopyResult() [1/2]

void DbgCopyResult ( device_vec< float2 >  src,
std::vector< std::complex< float > > &  dst 
)
inline

Definition at line 268 of file gpu_utils.h.

268 {}

§ DbgCopyResult() [2/2]

void DbgCopyResult ( device_vec< float >  src,
std::vector< float > &  dst 
)
inline

Definition at line 269 of file gpu_utils.h.

269 {}

§ dbgCUDAErrorCheck()

void dbgCUDAErrorCheck ( cudaError_t  e)
inline

Definition at line 63 of file gpu_utils.h.

63 {}

§ DbgOutputVectorToFile()

void DbgOutputVectorToFile ( std::string  loc,
device_vec< float > &  src,
bool  append 
)
inline

Definition at line 270 of file gpu_utils.h.

270 {}

§ outputTotalGPUMemUse()

void outputTotalGPUMemUse ( std::string  info = "")
inline

Definition at line 18 of file gpu_utils.h.

19 {
20  // show total memory usage of GPU
21  size_t free_byte;
22  size_t total_byte;
23  cudaError_t cuda_status = cudaMemGetInfo( &free_byte, &total_byte );
24  if ( cudaSuccess != cuda_status ){
25  dbgprintf("Error: cudaMemGetInfo fails, %s \n", cudaGetErrorString(cuda_status) );
26  exit(1);
27  }
28  double free_db = (double)free_byte;
29  double total_db = (double)total_byte;
30  double used_db = total_db - free_db;
31  dbgprintf("%sused = %2.2f MB, free = %2.2f MB, total = %2.2f MB\n",
32  info != "" ? (info+": ").c_str() : "",
33  used_db/1024.0/1024.0, free_db/1024.0/1024.0, total_db/1024.0/1024.0);
34 }
void dbgprintf(const char *fmt,...)
Definition: utils.cpp:149