Select fastest CUDA device. Merged from trunk.
This commit is contained in:
parent
cc4741ed03
commit
d787b30379
@ -3,7 +3,7 @@ NVIDIA Texture Tools version 2.0.5
|
||||
* Detect mismatch between CUDA runtime and driver, and disable CUDA in that case.
|
||||
* Fix cmake files when compiling NVTT as a shared library.
|
||||
* When linking nvtt dynamically on unix, link all libraries dynamically.
|
||||
* Merge fixes from trunk.
|
||||
* Select fastest CUDA device.
|
||||
|
||||
NVIDIA Texture Tools version 2.0.4
|
||||
* Fix error in RGB format output; reported by jonsoh. See issue 49.
|
||||
|
@ -211,6 +211,10 @@ 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())
|
||||
@ -237,6 +241,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())
|
||||
|
@ -151,6 +151,35 @@ int nv::cuda::deviceCount()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nv::cuda::getFastestDevice()
|
||||
{
|
||||
int max_gflops_device = 0;
|
||||
#if defined HAVE_CUDA
|
||||
int max_gflops = 0;
|
||||
|
||||
const int device_count = deviceCount();
|
||||
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++;
|
||||
}
|
||||
#endif
|
||||
return max_gflops_device;
|
||||
}
|
||||
|
||||
/// Activate the given devices.
|
||||
bool nv::cuda::setDevice(int i)
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ namespace nv
|
||||
{
|
||||
bool isHardwarePresent();
|
||||
int deviceCount();
|
||||
int getFastestDevice();
|
||||
bool setDevice(int i);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user