Select fastest device.

pull/216/head
castano 16 years ago
parent 1628831878
commit 36ba75b598

@ -221,8 +221,12 @@ Compressor::Compressor() : m(*new Compressor::Private())
if (m.cudaEnabled)
{
// Select fastest CUDA device.
int device = cuda::getFastestDevice();
cuda::setDevice(device);
m.cuda = new CudaCompressor();
if (!m.cuda->isValid())
{
m.cudaEnabled = false;
@ -247,6 +251,10 @@ void Compressor::enableCudaAcceleration(bool enable)
if (m.cudaEnabled && m.cuda == NULL)
{
// Select fastest CUDA device.
int device = cuda::getFastestDevice();
cuda::setDevice(device);
m.cuda = new CudaCompressor();
if (!m.cuda->isValid())

@ -149,7 +149,37 @@ int nv::cuda::deviceCount()
}
#endif
return 0;
}
}
int nv::cuda::getFastestDevice()
{
const int device_count = deviceCount();
int max_gflops_device = 0;
int max_gflops = 0;
int current_device = 0;
while (current_device < device_count)
{
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( gflops > max_gflops )
{
max_gflops = gflops;
max_gflops_device = current_device;
}
}
current_device++;
}
return max_gflops_device;
}
/// Activate the given devices.
bool nv::cuda::setDevice(int i)

@ -30,7 +30,8 @@ namespace nv
namespace cuda
{
bool isHardwarePresent();
int deviceCount();
int deviceCount();
int getFastestDevice();
bool setDevice(int i);
};

Loading…
Cancel
Save