tests/cuda4.1sdk/tests/simpleMultiGPU/simpleMultiGPU.cpp
int gpuGetMaxGflopsDeviceId()
{
    int current_device   = 0, sm_per_multiproc = 0;
    int max_compute_perf = 0, max_perf_device  = 0;
    int device_count     = 0, best_SM_arch     = 0;
    cudaDeviceProp deviceProp;
    
    cudaGetDeviceCount( &device_count );
    // Find the best major SM Architecture GPU device
    while ( current_device < device_count ) {
        cudaGetDeviceProperties( &deviceProp, current_device );
        if (deviceProp.major > 0 && deviceProp.major < 9999) {
            best_SM_arch = MAX(best_SM_arch, deviceProp.major);
        }
        current_device++;
    }
    
    // Find the best CUDA capable GPU device
    current_device = 0;
    while( current_device < device_count ) {
        cudaGetDeviceProperties( &deviceProp, current_device );
        if (deviceProp.major == 9999 && deviceProp.minor == 9999) {
            sm_per_multiproc = 1;
        } else {
            sm_per_multiproc = _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor);
        }
        
        int compute_perf  = deviceProp.multiProcessorCount * sm_per_multiproc * deviceProp.clockRate;
        if( compute_perf  > max_compute_perf ) {
            // If we find GPU with SM major > 2, search only these
            if ( best_SM_arch > 2 ) {
                // If our device==dest_SM_arch, choose this, or else pass
                if (deviceProp.major == best_SM_arch) {	
                    max_compute_perf  = compute_perf;
                    max_perf_device   = current_device;
                }
            } else {
                max_compute_perf  = compute_perf;
                max_perf_device   = current_device;
            }
        }
        ++current_device;
    }
    return max_perf_device;
}
// This function returns the best GPU (with maximum GFLOPS)
This function returns the best GPU (with maximum GFLOPS)
This function returns the best GPU ( with maximum GFLOPS )
int gpuGetMaxGflopsDeviceId()
{
    int current_device   = 0, sm_per_multiproc = 0;
    int max_compute_perf = 0, max_perf_device  = 0;
    int device_count     = 0, best_SM_arch     = 0;
    cudaDeviceProp deviceProp;
    cudaGetDeviceCount( &device_count );
    while ( current_device < device_count ) {
        cudaGetDeviceProperties( &deviceProp, current_device );
        if (deviceProp.major > 0 && deviceProp.major < 9999) {
            best_SM_arch = MAX(best_SM_arch, deviceProp.major);
        }
        current_device++;
    }
    current_device = 0;
    while( current_device < device_count ) {
        cudaGetDeviceProperties( &deviceProp, current_device );
        if (deviceProp.major == 9999 && deviceProp.minor == 9999) {
            sm_per_multiproc = 1;
        } else {
            sm_per_multiproc = _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor);
        }
        int compute_perf  = deviceProp.multiProcessorCount * sm_per_multiproc * deviceProp.clockRate;
        if( compute_perf  > max_compute_perf ) {
            if ( best_SM_arch > 2 ) {
                if (deviceProp.major == best_SM_arch) {	
                    max_compute_perf  = compute_perf;
                    max_perf_device   = current_device;
                }
            } else {
                max_compute_perf  = compute_perf;
                max_perf_device   = current_device;
            }
        }
        ++current_device;
    }
    return max_perf_device;
}
int gpuGetMaxGflopsDeviceId ( ) { int current_device = 0 , sm_per_multiproc = 0 ; int max_compute_perf = 0 , max_perf_device = 0 ; int device_count = 0 , best_SM_arch = 0 ; cudaDeviceProp deviceProp ; cudaGetDeviceCount ( & device_count ) ; while ( current_device < device_count ) { cudaGetDeviceProperties ( & deviceProp , current_device ) ; if ( deviceProp . major > 0 && deviceProp . major < 9999 ) { best_SM_arch = MAX ( best_SM_arch , deviceProp . major ) ; } current_device ++ ; } current_device = 0 ; while ( current_device < device_count ) { cudaGetDeviceProperties ( & deviceProp , current_device ) ; if ( deviceProp . major == 9999 && deviceProp . minor == 9999 ) { sm_per_multiproc = 1 ; } else { sm_per_multiproc = _ConvertSMVer2Cores ( deviceProp . major , deviceProp . minor ) ; } int compute_perf = deviceProp . multiProcessorCount * sm_per_multiproc * deviceProp . clockRate ; if ( compute_perf > max_compute_perf ) { if ( best_SM_arch > 2 ) { if ( deviceProp . major == best_SM_arch ) { max_compute_perf = compute_perf ; max_perf_device = current_device ; } } else { max_compute_perf = compute_perf ; max_perf_device = current_device ; } } ++ current_device ; } return max_perf_device ; }
This function returns the best GPU (with maximum GFLOPS)
This function returns the best GPU ( with maximum GFLOPS )
// Find the best major SM Architecture GPU device // Find the best CUDA capable GPU device // If we find GPU with SM major > 2, search only these // If our device==dest_SM_arch, choose this, or else pass