COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
carma_utils.h File Reference

this file provides tools to CarmaObj More...

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <driver_types.h>
#include <vector_types.h>
#include <chrono>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cuda.h>
#include <cuda_fp16.h>
#include <cuda_runtime_api.h>
#include <cufft.h>
Include dependency graph for carma_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  doubleint
 
struct  tuple_t< T >
 
class  carma_utils::ProgressBar
 

Namespaces

 carma_utils
 

Macros

#define CARMA_PI   3.1415926535897932384626433832
 
#define DEBUG_TRACE(fmt, args...)   fprintf(stderr, "[%s@%d]: " fmt "\n", __FILE__, __LINE__, ##args)
 
#define CAST(type, new_var, var)   type new_var = dynamic_cast<type>(var)
 
#define SCAST(type, new_var, var)   type new_var = static_cast<type>(var)
 
#define carma_safe_call_no_sync(err)   err
 
#define carma_safe_call(err)   err
 
#define carma_safe_device_synchronize()   cudaDeviceSynchronize()
 
#define carmafft_safe_call(err)   err
 
#define cutil_check_error(err)   err
 
#define carma_check_msg(msg)
 
#define cutil_safe_malloc(mallocCall)   (mallocCall)
 
#define MIN(a, b)   ((a < b) ? a : b)
 
#define MAX(a, b)   ((a > b) ? a : b)
 

Functions

template<typename T >
std::string carma_utils::to_string (const T &n)
 
template<typename T >
carma_utils::from_string (const std::string &myString)
 
void carma_utils::split (std::vector< std::string > &tokens, const std::string &text, char sep)
 
unsigned int next_pow2 (unsigned int x)
 
bool is_pow2 (unsigned int x)
 
void get_num_blocks_and_threads (CarmaDevice *device, int n, int &blocks, int &threads)
 
void sum_get_num_blocks_and_threads (int n, CarmaDevice *device, int &blocks, int &threads)
 
template<class T_data >
int find_nnz (T_data *d_data, int *tmp_colind, int N, int *d_nnz, int &h_nnz, CarmaDevice *device)
 
template<class T_data >
int fill_sparse_vect (T_data *dense_data, int *colind_sorted, T_data *values, int *colind, int *rowind, int nnz, CarmaDevice *device)
 
int float_to_double (float *idata, double *odata, int N, CarmaDevice *device)
 
int double_to_float (double *idata, float *odata, int N, CarmaDevice *device)
 
int print_mem_info ()
 
template<typename T_data >
int fill_array_with_value (T_data *d_data, T_data value, int N, CarmaDevice *device)
 
void carma_start_profile ()
 
void carma_stop_profile ()
 
void __carma_safe_call_no_sync (cudaError err, const char *file, const int line)
 
void __carma_safe_call (cudaError err, const char *code, const char *file, const int line)
 
void __carma_safe_device_synchronize (const char *file, const int line)
 
void __carmafft_safe_call (cufftResult err, const char *file, const int line)
 
void __carma_check_msg (const char *error_message, const char *file, const int line)
 
void __carma_safe_malloc (void *pointer, const char *file, const int line)
 

Detailed Description

this file provides tools to CarmaObj

Author
COMPASS Team https://github.com/ANR-COMPASS
Version
5.0.0
Date
2011/01/28

Definition in file carma_utils.h.

Macro Definition Documentation

◆ carma_check_msg

#define carma_check_msg (   msg)

Definition at line 150 of file carma_utils.h.

◆ CARMA_PI

#define CARMA_PI   3.1415926535897932384626433832

Definition at line 68 of file carma_utils.h.

◆ carma_safe_call

#define carma_safe_call (   err)    err

Definition at line 146 of file carma_utils.h.

◆ carma_safe_call_no_sync

#define carma_safe_call_no_sync (   err)    err

Definition at line 145 of file carma_utils.h.

◆ carma_safe_device_synchronize

#define carma_safe_device_synchronize ( )    cudaDeviceSynchronize()

Definition at line 147 of file carma_utils.h.

◆ carmafft_safe_call

#define carmafft_safe_call (   err)    err

Definition at line 148 of file carma_utils.h.

◆ CAST

#define CAST (   type,
  new_var,
  var 
)    type new_var = dynamic_cast<type>(var)

Definition at line 129 of file carma_utils.h.

◆ cutil_check_error

#define cutil_check_error (   err)    err

Definition at line 149 of file carma_utils.h.

◆ cutil_safe_malloc

#define cutil_safe_malloc (   mallocCall)    (mallocCall)

Definition at line 151 of file carma_utils.h.

◆ DEBUG_TRACE

#define DEBUG_TRACE (   fmt,
  args... 
)    fprintf(stderr, "[%s@%d]: " fmt "\n", __FILE__, __LINE__, ##args)

Definition at line 125 of file carma_utils.h.

◆ MAX

#define MAX (   a,
 
)    ((a > b) ? a : b)

Definition at line 158 of file carma_utils.h.

◆ MIN

#define MIN (   a,
 
)    ((a < b) ? a : b)

Definition at line 155 of file carma_utils.h.

◆ SCAST

#define SCAST (   type,
  new_var,
  var 
)    type new_var = static_cast<type>(var)

Definition at line 130 of file carma_utils.h.

Function Documentation

◆ __carma_check_msg()

void __carma_check_msg ( const char *  error_message,
const char *  file,
const int  line 
)

Definition at line 246 of file carma_utils.h.

247  {
248  cudaError_t err = cudaGetLastError();
249  if (cudaSuccess != err) {
250  fprintf(stderr, "(%s:%i) : carma_check_msg() CUTIL CUDA error : %s : %s.\n",
251  file, line, error_message, cudaGetErrorString(err));
252  throw cudaGetErrorString(err);
253  }
254 #ifdef DEBUG
255  err = cudaDeviceSynchronize();
256  if (cudaSuccess != err) {
257  fprintf(stderr,
258  "(%s:%i) : carma_check_msg cudaDeviceSynchronize error: %s : %s.\n",
259  file, line, error_message, cudaGetErrorString(err));
260  throw cudaGetErrorString(err);
261  }
262 #endif
263 }

◆ __carma_safe_call()

void __carma_safe_call ( cudaError  err,
const char *  code,
const char *  file,
const int  line 
)

Definition at line 216 of file carma_utils.h.

217  {
218  if (cudaSuccess != err) {
219  fprintf(stderr, "[%s:%i] %s\n carma_safe_call() Runtime API error : %s.\n",
220  file, line, code, cudaGetErrorString(err));
221  // exit(EXIT_FAILURE);
222  throw cudaGetErrorString(err);
223  }
224 }

◆ __carma_safe_call_no_sync()

void __carma_safe_call_no_sync ( cudaError  err,
const char *  file,
const int  line 
)

Definition at line 206 of file carma_utils.h.

207  {
208  if (cudaSuccess != err) {
209  fprintf(stderr, "(%s:%i) : carma_safe_call_no_sync() Runtime API error : %s.\n",
210  file, line, cudaGetErrorString(err));
211  // exit(EXIT_FAILURE);
212  throw cudaGetErrorString(err);
213  }
214 }

◆ __carma_safe_device_synchronize()

void __carma_safe_device_synchronize ( const char *  file,
const int  line 
)

Definition at line 226 of file carma_utils.h.

226  {
227  cudaError err = cudaDeviceSynchronize();
228  if (cudaSuccess != err) {
229  fprintf(stderr,
230  "(%s:%i) : cudaDeviceSynchronize() Driver API error : %s.\n", file,
231  line, cudaGetErrorString(err));
232  // exit(EXIT_FAILURE);
233  throw cudaGetErrorString(err);
234  }
235 }

◆ __carma_safe_malloc()

void __carma_safe_malloc ( void *  pointer,
const char *  file,
const int  line 
)

Definition at line 264 of file carma_utils.h.

264  {
265  if (!(pointer)) {
266  fprintf(stderr, "(%s:%i) : cutil_safe_malloc host malloc failure\n", file,
267  line);
268  throw "cutil_safe_malloc() cutil_safe_malloc host malloc failure";
269  }
270 }

◆ __carmafft_safe_call()

void __carmafft_safe_call ( cufftResult  err,
const char *  file,
const int  line 
)

Definition at line 237 of file carma_utils.h.

238  {
239  if (CUFFT_SUCCESS != err) {
240  fprintf(stderr, "(%s:%i) : carmafft_safe_call() CUFFT error.\n", file, line);
241  // exit(EXIT_FAILURE);
242  throw "carmafft_safe_call() CUFFT error";
243  }
244 }

◆ carma_start_profile()

void carma_start_profile ( )

◆ carma_stop_profile()

void carma_stop_profile ( )

◆ double_to_float()

int double_to_float ( double *  idata,
float *  odata,
int  N,
CarmaDevice device 
)

◆ fill_array_with_value()

template<typename T_data >
int fill_array_with_value ( T_data *  d_data,
T_data  value,
int  N,
CarmaDevice device 
)
Here is the caller graph for this function:

◆ fill_sparse_vect()

template<class T_data >
int fill_sparse_vect ( T_data *  dense_data,
int *  colind_sorted,
T_data *  values,
int *  colind,
int *  rowind,
int  nnz,
CarmaDevice device 
)

◆ find_nnz()

template<class T_data >
int find_nnz ( T_data *  d_data,
int *  tmp_colind,
int  N,
int *  d_nnz,
int &  h_nnz,
CarmaDevice device 
)

◆ float_to_double()

int float_to_double ( float *  idata,
double *  odata,
int  N,
CarmaDevice device 
)

◆ get_num_blocks_and_threads()

void get_num_blocks_and_threads ( CarmaDevice device,
int  n,
int &  blocks,
int &  threads 
)

◆ is_pow2()

bool is_pow2 ( unsigned int  x)

Definition at line 170 of file carma_utils.h.

170 { return ((x & (x - 1)) == 0); }

◆ next_pow2()

unsigned int next_pow2 ( unsigned int  x)

Definition at line 160 of file carma_utils.h.

160  {
161  --x;
162  x |= x >> 1;
163  x |= x >> 2;
164  x |= x >> 4;
165  x |= x >> 8;
166  x |= x >> 16;
167  return ++x;
168 }

◆ print_mem_info()

int print_mem_info ( )

◆ sum_get_num_blocks_and_threads()

void sum_get_num_blocks_and_threads ( int  n,
CarmaDevice device,
int &  blocks,
int &  threads 
)
layers_test.err
err
Definition: layers_test.py:83
correlation_bokeh.x
x
Definition: correlation_bokeh.py:321