TAPs 0.7.7.3
TAPsCUDA_GlobalFns_Def.cu File Reference
Include dependency graph for TAPsCUDA_GlobalFns_Def.cu:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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)
 Check error and exit the program if the action flag is true.
const char * GetErrorString (cudaError_t error)
 Convert cudaError_t to const char *.

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.

References GetDeviceProperties().

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 call graph for this function:

Here is the caller graph for this function:

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

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.

References GetErrorString().

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 call graph for this function:

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.

References GetErrorString().

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 call graph for this function:

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.

Initialize CUDA.

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.

References CanDeviceMapHostMemory(), GetDevice(), and SetDevice().

{
    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);
    }
}

Here is the call graph for this function:

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.

References GetErrorString().

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 call graph for this function:

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines