Select fastest device.

This commit is contained in:
castano
2008-10-30 04:50:41 +00:00
parent 1628831878
commit 36ba75b598
3 changed files with 42 additions and 3 deletions

View File

@ -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)

View File

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