Select fastest device.
This commit is contained in:
parent
1628831878
commit
36ba75b598
|
@ -221,6 +221,10 @@ Compressor::Compressor() : m(*new Compressor::Private())
|
||||||
|
|
||||||
if (m.cudaEnabled)
|
if (m.cudaEnabled)
|
||||||
{
|
{
|
||||||
|
// Select fastest CUDA device.
|
||||||
|
int device = cuda::getFastestDevice();
|
||||||
|
cuda::setDevice(device);
|
||||||
|
|
||||||
m.cuda = new CudaCompressor();
|
m.cuda = new CudaCompressor();
|
||||||
|
|
||||||
if (!m.cuda->isValid())
|
if (!m.cuda->isValid())
|
||||||
|
@ -247,6 +251,10 @@ void Compressor::enableCudaAcceleration(bool enable)
|
||||||
|
|
||||||
if (m.cudaEnabled && m.cuda == NULL)
|
if (m.cudaEnabled && m.cuda == NULL)
|
||||||
{
|
{
|
||||||
|
// Select fastest CUDA device.
|
||||||
|
int device = cuda::getFastestDevice();
|
||||||
|
cuda::setDevice(device);
|
||||||
|
|
||||||
m.cuda = new CudaCompressor();
|
m.cuda = new CudaCompressor();
|
||||||
|
|
||||||
if (!m.cuda->isValid())
|
if (!m.cuda->isValid())
|
||||||
|
|
|
@ -151,6 +151,36 @@ int nv::cuda::deviceCount()
|
||||||
return 0;
|
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.
|
/// Activate the given devices.
|
||||||
bool nv::cuda::setDevice(int i)
|
bool nv::cuda::setDevice(int i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace nv
|
||||||
{
|
{
|
||||||
bool isHardwarePresent();
|
bool isHardwarePresent();
|
||||||
int deviceCount();
|
int deviceCount();
|
||||||
|
int getFastestDevice();
|
||||||
bool setDevice(int i);
|
bool setDevice(int i);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user