|
|
|
@ -41,11 +41,11 @@ using namespace cuda;
|
|
|
|
|
|
|
|
|
|
static bool isWindowsVista()
|
|
|
|
|
{
|
|
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
|
|
|
|
|
|
::GetVersionEx(&osvi);
|
|
|
|
|
return osvi.dwMajorVersion >= 6;
|
|
|
|
|
::GetVersionEx(&osvi);
|
|
|
|
|
return osvi.dwMajorVersion >= 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -53,20 +53,20 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
|
|
|
|
|
|
|
|
|
|
static bool isWow32()
|
|
|
|
|
{
|
|
|
|
|
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
|
|
|
|
|
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
|
|
|
|
|
|
|
|
|
|
BOOL bIsWow64 = FALSE;
|
|
|
|
|
BOOL bIsWow64 = FALSE;
|
|
|
|
|
|
|
|
|
|
if (NULL != fnIsWow64Process)
|
|
|
|
|
{
|
|
|
|
|
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
|
|
|
|
|
{
|
|
|
|
|
// Assume 32 bits.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (NULL != fnIsWow64Process)
|
|
|
|
|
{
|
|
|
|
|
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
|
|
|
|
|
{
|
|
|
|
|
// Assume 32 bits.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !bIsWow64;
|
|
|
|
|
return !bIsWow64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
@ -158,6 +158,8 @@ bool nv::cuda::isHardwarePresent()
|
|
|
|
|
|
|
|
|
|
// @@ Make sure that warp size == 32
|
|
|
|
|
|
|
|
|
|
// @@ Make sure available GPU is faster than the CPU.
|
|
|
|
|
|
|
|
|
|
return count > 0;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
@ -180,30 +182,59 @@ int nv::cuda::deviceCount()
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure device meets requirements:
|
|
|
|
|
// - Not an emulation device.
|
|
|
|
|
// - Not an integrated device?
|
|
|
|
|
// - Faster than CPU.
|
|
|
|
|
bool nv::cuda::isValidDevice(int i)
|
|
|
|
|
{
|
|
|
|
|
#if defined HAVE_CUDA
|
|
|
|
|
|
|
|
|
|
cudaDeviceProp device_properties;
|
|
|
|
|
cudaGetDeviceProperties(&device_properties, i);
|
|
|
|
|
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
|
|
|
|
|
|
|
|
|
|
if (device_properties.major == -1 || device_properties.minor == -1) {
|
|
|
|
|
// Emulation device.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if CUDART_VERSION >= 2030 // 2.3
|
|
|
|
|
/*if (device_properties.integrated)
|
|
|
|
|
{
|
|
|
|
|
// Integrated devices.
|
|
|
|
|
return false;
|
|
|
|
|
}*/
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nv::cuda::getFastestDevice()
|
|
|
|
|
{
|
|
|
|
|
int max_gflops_device = 0;
|
|
|
|
|
int max_gflops_device = -1;
|
|
|
|
|
#if defined HAVE_CUDA
|
|
|
|
|
int max_gflops = 0;
|
|
|
|
|
|
|
|
|
|
const int device_count = deviceCount();
|
|
|
|
|
int current_device = 0;
|
|
|
|
|
while (current_device < device_count)
|
|
|
|
|
for (int i = 0; i < device_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cudaDeviceProp device_properties;
|
|
|
|
|
cudaGetDeviceProperties(&device_properties, current_device);
|
|
|
|
|
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
|
|
|
|
|
|
|
|
|
|
if (device_properties.major != -1 && device_properties.minor != -1)
|
|
|
|
|
if (isValidDevice(i))
|
|
|
|
|
{
|
|
|
|
|
if( gflops > max_gflops )
|
|
|
|
|
cudaDeviceProp device_properties;
|
|
|
|
|
cudaGetDeviceProperties(&device_properties, i);
|
|
|
|
|
int gflops = device_properties.multiProcessorCount * device_properties.clockRate;
|
|
|
|
|
|
|
|
|
|
if (gflops > max_gflops)
|
|
|
|
|
{
|
|
|
|
|
max_gflops = gflops;
|
|
|
|
|
max_gflops_device = current_device;
|
|
|
|
|
max_gflops_device = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_device++;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return max_gflops_device;
|
|
|
|
@ -211,23 +242,53 @@ int nv::cuda::getFastestDevice()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Activate the given devices.
|
|
|
|
|
bool nv::cuda::setDevice(int i)
|
|
|
|
|
bool nv::cuda::initDevice(int * device_ptr)
|
|
|
|
|
{
|
|
|
|
|
nvCheck(i < deviceCount());
|
|
|
|
|
nvDebugCheck(device_ptr != NULL);
|
|
|
|
|
#if defined HAVE_CUDA
|
|
|
|
|
cudaError_t result = cudaSetDevice(i);
|
|
|
|
|
|
|
|
|
|
if (result != cudaSuccess) {
|
|
|
|
|
#if CUDART_VERSION >= 2030 // 2.3
|
|
|
|
|
|
|
|
|
|
// Set device flags to yield in order to play nice with other threads and to find out if CUDA was already active.
|
|
|
|
|
cudaError_t resul = cudaSetDeviceFlags(cudaDeviceScheduleYield);
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int device = getFastestDevice();
|
|
|
|
|
|
|
|
|
|
if (device == -1)
|
|
|
|
|
{
|
|
|
|
|
// No device is fast enough.
|
|
|
|
|
*device_ptr = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Select CUDA device.
|
|
|
|
|
cudaError_t result = cudaSetDevice(device);
|
|
|
|
|
|
|
|
|
|
if (result == cudaErrorSetOnActiveProcess)
|
|
|
|
|
{
|
|
|
|
|
int device;
|
|
|
|
|
result = cudaGetDevice(&device);
|
|
|
|
|
|
|
|
|
|
*device_ptr = -1; // No device to cleanup.
|
|
|
|
|
return isValidDevice(device); // Return true if device is valid.
|
|
|
|
|
}
|
|
|
|
|
else if (result != cudaSuccess)
|
|
|
|
|
{
|
|
|
|
|
nvDebug("*** CUDA Error: %s\n", cudaGetErrorString(result));
|
|
|
|
|
*device_ptr = -1;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result == cudaSuccess;
|
|
|
|
|
*device_ptr = device;
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nv::cuda::exit()
|
|
|
|
|
void nv::cuda::exitDevice()
|
|
|
|
|
{
|
|
|
|
|
#if defined HAVE_CUDA
|
|
|
|
|
cudaError_t result = cudaThreadExit();
|
|
|
|
|