GPU Workshop Sample Code
 All Data Structures Namespaces Files Functions Variables Macros Pages
Data Structures | Namespaces | Constant Groups | Macros | Functions
mycuda.h File Reference
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <cassert>
#include <cuda.h>
#include <cuda_runtime.h>

Go to the source code of this file.

Data Structures

class  mycuda::exception
 Exception class for CUDA errors. More...
 

Namespaces

 mycuda
 Core macros and utilities.
 

Constant Groups

 mycuda
 Core macros and utilities.
 

Macros

#define CUDA_TRACE()   fprintf( stderr, "%s(%i): CUDA_TRACE\n", __FILE__, __LINE__)
 
#define CUDA_SYNC_TRACE()   mycuda::device_synchronize(); CUDA_TRACE();
 
#define CUDA_DEBUG(_msg)   fprintf( stderr, "%s(%i): CUDA_DEBUG :: %s\n", __FILE__, __LINE__, _msg )
 
#define CUDA_DEBUG_PRINTF(_fmt,...)   fprintf( stderr, "%s(%i): CUDA_DEBUG :: " _fmt "\n", __FILE__, __LINE__, __VA_ARGS__ )
 
#define CUDA_LOGGER(_msg)   fprintf( stderr, "%s(%i): CUDA_LOGGER :: %s\n", __FILE__, __LINE__, _msg )
 
#define CUDA_LOGGER_PRINTF(_fmt,...)   fprintf( stderr, "%s(%i): CUDA_LOGGER :: " _fmt "\n", __FILE__, __LINE__, __VA_ARGS__ )
 
#define CUDA_CHECK_ERROR()   mycuda::check_error( __FILE__, __LINE__ )
 
#define CUDA_ASYNC_CHECK_ERROR()   mycuda::async_check_error( __FILE__, __LINE__ )
 
#define CUDA_SAFE_CALL(err)   mycuda::safe_call(err, __FILE__, __LINE__)
 
#define CUDA_CATCH()   catch( std::exception& e) { mycuda::handler( e, __FILE__, __LINE__ ); }
 
#define CUDA_HANDLER(e)   mycuda::handler( e, __FILE__, __LINE__ )
 

Functions

void mycuda::check_error (const char *file, const int line)
 Terminate if cudaGetLastError() returns error. More...
 
void mycuda::async_check_error (const char *file, const int line)
 Terminate if cudaGetLastError() returns error. More...
 
void mycuda::safe_call (cudaError_t err, const char *file, const int line)
 Wrapper to check error code for any cuda call that returns one. Terminates if error is returned. More...
 
void mycuda::handler (std::exception &e, const char *file, const int line)
 Simple exception handler. More...
 
template<typename T >
T * mycuda::device_malloc (int n) throw (exception)
 Allocate memory on device. More...
 
template<typename T >
T * mycuda::mapped_malloc (int n) throw (exception)
 Allocate mapped memory on host. More...
 
template<typename T >
T * mycuda::host_malloc (int n) throw ( exception )
 Allocate host memory. More...
 
template<typename T >
void mycuda::device_free (T *ptr) throw ( exception )
 Free device memory. More...
 
template<typename T >
void mycuda::mapped_free (T *ptr) throw ( exception )
 Free mapped memory. More...
 
template<typename T >
void mycuda::host_free (T *ptr)
 Free host memory (included just for consistency). More...
 
template<typename T >
void mycuda::copy_device_to_host (T *dest, T *src, int n) throw ( exception )
 Copy from device to host. More...
 
template<typename T >
void mycuda::copy_host_to_device (T *dest, T *src, int n) throw ( exception )
 Copy from host to device. More...
 
template<typename T >
void mycuda::copy_device_to_device (T *dest, T *src, int n) throw ( exception )
 Copy from device to device. More...
 
template<typename T >
void mycuda::copy_host_to_host (T *dest, T *src, int n) throw ( exception )
 Copy from host to host. More...
 
void mycuda::device_synchronize () throw ( exception )
 Wrapper for cudaDeviceSynchronize() More...
 
void mycuda::get_memory_info () throw ( exception )
 Wrapper for cudaMemGetInfo() More...
 
template<typename T1 , typename T2 >
__global__ void mycuda::fill (T1 *z, T2 a, int n)
 Fill device array z with constant a. More...
 
template<typename T1 , typename T2 >
__global__ void mycuda::seq (T1 *z, T2 first, int n)
 Fill device array z with sequence. More...
 
template<typename T1 , typename T2 >
__global__ void mycuda::seq (T1 *z, T2 first, T2 inc, int n)
 Fill device array z with sequence. More...
 
template<typename T1 , typename T2 >
__global__ void mycuda::rep (T1 *z, int n, T2 *x, int nx, int ncopies)
 Fill device array z with values from x, repeated ncopies times. More...
 
template<typename T1 , typename T2 >
__global__ void mycuda::tile (T1 *z, int n, T2 *x, int nx, int ncopies)
 Fill device array z with values from x, tiled ncopies times. More...
 
__global__ void mycuda::aX_plus_bY (float *z, float a, float *x, float b, float *y, int n)
 Elementwise operation, z = a*x + b*y. More...
 
__global__ void mycuda::max_X_Y (float *z, float *x, float *y, int n)
 Elementwise operation, z = max( x, y ) More...
 
__global__ void mycuda::min_X_Y (float *z, float *x, float *y, int n)
 Elementwise operation, z = min( x, y) More...
 
__global__ void mycuda::log_X (float *z, float *x, int n)
 Elementwise operation, z = log( x ) More...
 
__global__ void mycuda::exp_X (float *z, float *x, int n)
 Elementwise operation, z = exp( x ) More...
 

Macro Definition Documentation

#define CUDA_ASYNC_CHECK_ERROR ( )    mycuda::async_check_error( __FILE__, __LINE__ )

Definition at line 27 of file mycuda.h.

#define CUDA_CATCH ( )    catch( std::exception& e) { mycuda::handler( e, __FILE__, __LINE__ ); }

Definition at line 29 of file mycuda.h.

#define CUDA_CHECK_ERROR ( )    mycuda::check_error( __FILE__, __LINE__ )

Definition at line 26 of file mycuda.h.

#define CUDA_DEBUG (   _msg)    fprintf( stderr, "%s(%i): CUDA_DEBUG :: %s\n", __FILE__, __LINE__, _msg )

Definition at line 21 of file mycuda.h.

#define CUDA_DEBUG_PRINTF (   _fmt,
  ... 
)    fprintf( stderr, "%s(%i): CUDA_DEBUG :: " _fmt "\n", __FILE__, __LINE__, __VA_ARGS__ )

Definition at line 22 of file mycuda.h.

#define CUDA_HANDLER (   e)    mycuda::handler( e, __FILE__, __LINE__ )

Definition at line 30 of file mycuda.h.

#define CUDA_LOGGER (   _msg)    fprintf( stderr, "%s(%i): CUDA_LOGGER :: %s\n", __FILE__, __LINE__, _msg )

Definition at line 24 of file mycuda.h.

#define CUDA_LOGGER_PRINTF (   _fmt,
  ... 
)    fprintf( stderr, "%s(%i): CUDA_LOGGER :: " _fmt "\n", __FILE__, __LINE__, __VA_ARGS__ )

Definition at line 25 of file mycuda.h.

#define CUDA_SAFE_CALL (   err)    mycuda::safe_call(err, __FILE__, __LINE__)

Definition at line 28 of file mycuda.h.

#define CUDA_SYNC_TRACE ( )    mycuda::device_synchronize(); CUDA_TRACE();

Definition at line 20 of file mycuda.h.

#define CUDA_TRACE ( )    fprintf( stderr, "%s(%i): CUDA_TRACE\n", __FILE__, __LINE__)

Definition at line 19 of file mycuda.h.