TAPs 0.7.7.3
TAPsCUDA_GlobalFns.cu File Reference

A list of CUDA global functions. More...

Include dependency graph for TAPsCUDA_GlobalFns.cu:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TAPs_CUDA_GLOBAL_FNS_HPP

Functions

BEGIN_NAMESPACE_TAPs__CUDA void Host__Init (int argc, char **argv)
 Initialize CUDA Device.
void Host__Init_withPLHM (int argc, char **argv)
 Initialize CUDA (with Page-Locked Host Memory)
int DeviceCount ()
 Get number of devices.
bool GetDevice (int &device)
 Get the device on which the active host thread executes the device code.
bool SetDevice (int device)
bool GetDeviceProperties (cudaDeviceProp *prop, int device)
 Get Device's Properties.
bool CanDeviceMapHostMemory (int device)
 Can Map Host Memory (i.e. can utilize CUDA's Page-Locked Host Memory)
bool CheckError (cudaError_t error, const char *msg, bool bExitProgram=false)
 Check error and exit the program if the action flag is true.
const char * GetErrorString (cudaError_t error)
 Convert cudaError_t to const char *.

Detailed Description

A list of CUDA global functions.

"CUDA/TAPsCUDA_GlobalFns.cu"

From CUDA Programming Guide
Any call to a __global__ function must specify the execution configuration for that call.
The execution configuration defines the dimension of the grid and blocks that will be used to execute the function on the device, as well as the associated stream (see Section 4.5.1.5 for a description of streams). It is specified by inserting an expression of the form <<< Dg, Db, Ns, S >>> between the function name and the parenthesized argument list, where:
  • Dg is of type dim3 (see Section 4.3.1.2) and specifies the dimension and size of the grid, such that Dg.x * Dg.y equals the number of blocks being launched; Dg.z is unused;
  • Db is of type dim3 (see Section 4.3.1.2) and specifies the dimension and size of each block, such that Db.x * Db.y * Db.z equals the number of threads per block;
  • Ns is of type size_t and specifies the number of bytes in shared memory that is dynamically allocated per block for this call in addition to the statically allocated memory; this dynamically allocated memory is used by any of the variables declared as an external array as mentioned in Section 4.2.2.3; Ns is an optional argument which defaults to 0;
  • S is of type cudaStream_t and specifies the associated stream; S is an optional argument which defaults to 0.

Definition in file TAPsCUDA_GlobalFns.cu.


Define Documentation

#define TAPs_CUDA_GLOBAL_FNS_HPP

Definition at line 40 of file TAPsCUDA_GlobalFns.cu.


Function Documentation

bool CanDeviceMapHostMemory ( int  device)

Can Map Host Memory (i.e. can utilize CUDA's Page-Locked Host Memory)

Definition at line 86 of file TAPsCUDA_GlobalFns_Def.cu.

Referenced by ElasticRod_CompByCUDA< T >::CreateCUDA(), and Host__Init_withPLHM().

{
    //if ( !SetDevice( device ) )   return false;
    cudaDeviceProp prop;
    if ( !GetDeviceProperties( &prop, device ) )    return false;
    return prop.canMapHostMemory == 1;
}

Here is the caller graph for this function:

bool CheckError ( cudaError_t  error,
const char *  msg,
bool  bExitProgram = false 
)

Check error and exit the program if the action flag is true.

Definition at line 98 of file TAPsCUDA_GlobalFns_Def.cu.

{
    if ( error == cudaSuccess ) return true;
    if ( msg ) {
        printf ( "ERROR: %s -- %s\n", msg, cudaGetErrorString( error ) );
    }
    else {
        printf ( "ERROR: %s\n", cudaGetErrorString( error ) );
    }
    if ( bExitProgram ) exit( -555 );
    return false;
}
int DeviceCount ( )

Get number of devices.

Definition at line 48 of file TAPsCUDA_GlobalFns_Def.cu.

{
    int count;
    cudaGetDeviceCount( &count );
    return count;
}
bool GetDevice ( int &  device)

Get the device on which the active host thread executes the device code.

Definition at line 56 of file TAPsCUDA_GlobalFns_Def.cu.

Referenced by ElasticRod_CompByCUDA< T >::CreateCUDA(), and Host__Init_withPLHM().

{
    cudaError_t err = cudaGetDevice( & device );
    if ( err == cudaSuccess ) return true;
    printf( "FAILED: GetDevice(%i) -- %s\n", device, GetErrorString( err ) );
    return false;
}

Here is the caller graph for this function:

bool GetDeviceProperties ( cudaDeviceProp *  prop,
int  device 
)

Get Device's Properties.

Definition at line 77 of file TAPsCUDA_GlobalFns_Def.cu.

Referenced by CanDeviceMapHostMemory().

{
    cudaError_t err = cudaGetDeviceProperties( prop, device );
    if ( err == cudaSuccess ) return true;
    printf( "FAILED: GetDeviceProperties( ..., %i) -- %s\n", device, GetErrorString( err ) );
    return false;
}

Here is the caller graph for this function:

const char* GetErrorString ( cudaError_t  error)

Convert cudaError_t to const char *.

Definition at line 112 of file TAPsCUDA_GlobalFns_Def.cu.

Referenced by GetDevice(), GetDeviceProperties(), and SetDevice().

{
    return cudaGetErrorString( error );
}

Here is the caller graph for this function:

BEGIN_NAMESPACE_TAPs__CUDA void Host__Init ( int  argc,
char **  argv 
)

Initialize CUDA Device.

Definition at line 17 of file TAPsCUDA_GlobalFns_Def.cu.

{
    printf( "START: CUT_DEVICE_INIT\n" );
    CUT_DEVICE_INIT(argc, argv);
    printf( "END:   CUT_DEVICE_INIT\n" );
}
void Host__Init_withPLHM ( int  argc,
char **  argv 
)

Initialize CUDA (with Page-Locked Host Memory)

Definition at line 25 of file TAPsCUDA_GlobalFns_Def.cu.

{
    if ( !SetDevice( 0 ) ) {
        printf( "FAILED: setting the device 0! -- File: %s Line: %i\n", __FILE__, __LINE__ );
        exit(-501);
    }
    int device;
    if ( !GetDevice( device ) ) {
        printf( "FAILED: getting the current device! -- File: %s Line: %i\n", __FILE__, __LINE__ );
        exit(-501);
    }
    if ( !CanDeviceMapHostMemory( device ) ) {
        printf( "FAILED: the current device cannot map host memory! -- File: %s Line: %i\n", __FILE__, __LINE__ );
        exit(-502);
    }
    cudaError_t err = cudaSetDeviceFlags( cudaDeviceMapHost );
    if ( err != cudaSuccess ) {
        printf( "FAILED: cannot set device's map host memory flag! (%s) -- File: %s Line: %i\n", cudaGetErrorString( err ), __FILE__, __LINE__ );
        exit(-503);
    }
}
bool SetDevice ( int  device)

Set the device on which the active host thread executes the device code If the host thread has already initialized the CUDA runtime by calling non-device management runtime functions, this call results in cudaErrorSetOnActiveProcess.

Definition at line 68 of file TAPsCUDA_GlobalFns_Def.cu.

Referenced by Host__Init_withPLHM().

{
    cudaError_t err = cudaSetDevice( device );
    if ( err == cudaSuccess ) return true;
    printf( "FAILED: SetDevice(%i) -- %s\n", device, GetErrorString( err ) );
    return false;
}

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines