CUDA_MODULE/cuda_module.c
/**
 *
 * \brief   cuda init to check props and prhibs.
 *
 * \param   void                            user_data   : User data passed.
 * \return  error type SAMPLE_RET_OK;
 * \author  mohamet.jaafar\@gmail.com
 * \date    2016
 */
\brief   cuda init to check props and prhibs.
\param   void                            user_data   : User data passed.
\ brief cuda init to check props and prhibs . \ param void user_data : User data passed .
SAMPLE_Error_t CUDA_MODULE_Init_Cuda_GPU(void)
{
    cudaError_t             zCuda_ret        = cudaSuccess;
    int                     devID            = CUDA_MODULE_DEVICE_ID;
    SAMPLE_Error_t          z_ret            = SAMPLE_RET_OK;
    struct cudaDeviceProp   cudaDeviceProp;
    u_int16_t               cudaDevCaps      = 0x0;
    int                     deviceIndex      = 0;
    SAMPLE_LOG_INFO("[CUDA_MODULE - module Using CUDA] - Starting...\n");
    zCuda_ret = cudaGetDevice(&deviceIndex);
    if( cudaSuccess != zCuda_ret)
    {
        SAMPLE_LOG_WARNING("CUDA - error when setting device ID %s :: %d \n", cudaGetErrorString(zCuda_ret), zCuda_ret);
    }
    else
    {
        SAMPLE_LOG_MSG("CUDA - Device count on the workstation %d  :: %s \n", deviceIndex, cudaGetErrorString(zCuda_ret));
    }
    zCuda_ret = cudaSetDevice(devID);
    if (cudaSuccess != zCuda_ret)
    {
        SAMPLE_LOG_WARNING("CUDA - error when setting device ID %s :: %d \n", cudaGetErrorString(zCuda_ret), zCuda_ret);
    }
    zCuda_ret = cudaGetDevice(&devID);
    if (cudaSuccess != zCuda_ret)
    {
        SAMPLE_LOG_WARNING("cudaGetDevice returned error %s :: %d \n", cudaGetErrorString(zCuda_ret), zCuda_ret);
    }
    zCuda_ret = cudaGetDeviceProperties(&cudaDeviceProp, devID);
    if(cudaSuccess != zCuda_ret)
    {
        SAMPLE_LOG_ERROR("cudaGetDeviceProperties returned error %s :: %d \n", cudaGetErrorString(zCuda_ret), zCuda_ret);
    }
    else
    {
        SAMPLE_LOG_INFO("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, cudaDeviceProp.name, cudaDeviceProp.major, cudaDeviceProp.minor);
    }
    if (cudaComputeModeProhibited == cudaDeviceProp.computeMode)
    {
        SAMPLE_LOG_ERROR("Error: device is running in <Compute Mode Prohibited>, no threads can be used ::cudaSetDevice().\n");
        z_ret = SAMPLE_RET_CUDA_INIT_ERROR;
        goto error;
    }
    cudaDevCaps |= (CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD);
    cudaDevCaps |= (CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD);
    CUDA_MODULE_DEVICE_CAPA_UPDATE(cudaDeviceProp, cudaDevCaps);
    if ((CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD) != \
        (cudaDevCaps & ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD)))
    {
        SAMPLE_LOG_INFO("cuda driver memory caps = 0x%x \n", cudaDevCaps & CUDA_MODULE_MEM_CAPS_MASK);
    }
    else
    {
        SAMPLE_LOG_INFO("cuda driver :: unable to  catch memory caps 0x%x \n", cudaDevCaps);
    }
    if ((CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD) != \
        (cudaDevCaps & ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD)))
    {
        SAMPLE_LOG_INFO("cuda driver kernel exec caps present = 0x%x \n", cudaDevCaps & CUDA_MODULE_KERN_EXEC_CAPS_MASK);
    }
    else
    {
        SAMPLE_LOG_INFO("cuda driver :: unable to  catch kernel exec caps 0x%x \n", cudaDevCaps);
    }
error:
    return z_ret;
}
SAMPLE_Error_t CUDA_MODULE_Init_Cuda_GPU ( void ) { cudaError_t zCuda_ret = cudaSuccess ; int devID = CUDA_MODULE_DEVICE_ID ; SAMPLE_Error_t z_ret = SAMPLE_RET_OK ; struct cudaDeviceProp cudaDeviceProp ; u_int16_t cudaDevCaps = 0x0 ; int deviceIndex = 0 ; SAMPLE_LOG_INFO ( " \n " ) ; zCuda_ret = cudaGetDevice ( & deviceIndex ) ; if ( cudaSuccess != zCuda_ret ) { SAMPLE_LOG_WARNING ( " \n " , cudaGetErrorString ( zCuda_ret ) , zCuda_ret ) ; } else { SAMPLE_LOG_MSG ( " \n " , deviceIndex , cudaGetErrorString ( zCuda_ret ) ) ; } zCuda_ret = cudaSetDevice ( devID ) ; if ( cudaSuccess != zCuda_ret ) { SAMPLE_LOG_WARNING ( " \n " , cudaGetErrorString ( zCuda_ret ) , zCuda_ret ) ; } zCuda_ret = cudaGetDevice ( & devID ) ; if ( cudaSuccess != zCuda_ret ) { SAMPLE_LOG_WARNING ( " \n " , cudaGetErrorString ( zCuda_ret ) , zCuda_ret ) ; } zCuda_ret = cudaGetDeviceProperties ( & cudaDeviceProp , devID ) ; if ( cudaSuccess != zCuda_ret ) { SAMPLE_LOG_ERROR ( " \n " , cudaGetErrorString ( zCuda_ret ) , zCuda_ret ) ; } else { SAMPLE_LOG_INFO ( " \" \" \n \n " , devID , cudaDeviceProp . name , cudaDeviceProp . major , cudaDeviceProp . minor ) ; } if ( cudaComputeModeProhibited == cudaDeviceProp . computeMode ) { SAMPLE_LOG_ERROR ( " \n " ) ; z_ret = SAMPLE_RET_CUDA_INIT_ERROR ; goto error ; } cudaDevCaps |= ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD ) ; cudaDevCaps |= ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD ) ; CUDA_MODULE_DEVICE_CAPA_UPDATE ( cudaDeviceProp , cudaDevCaps ) ; if ( ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD ) != ( cudaDevCaps & ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_MEMORY_CAPA_FIELD ) ) ) { SAMPLE_LOG_INFO ( " \n " , cudaDevCaps & CUDA_MODULE_MEM_CAPS_MASK ) ; } else { SAMPLE_LOG_INFO ( " \n " , cudaDevCaps ) ; } if ( ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD ) != ( cudaDevCaps & ( CUDA_MODULE_DEVICE_CAPA_IS_PRESENT << CUDA_DEVICE_KERNEL_EXEC_CAPA_FIELD ) ) ) { SAMPLE_LOG_INFO ( " \n " , cudaDevCaps & CUDA_MODULE_KERN_EXEC_CAPS_MASK ) ; } else { SAMPLE_LOG_INFO ( " \n " , cudaDevCaps ) ; } error : return z_ret ; }
\brief   cuda init to check props and prhibs.
\ brief cuda init to check props and prhibs .
/* ignore the error use the default */ /* else : continue */ /* ignore the error try to get it anyway */ /* else : continue */ /*
    ** get GPU memory props.
    */