Library/ManagedCuda/CudaContext.cs
/// <summary>
/// returns the best GPU (with maximum GFLOPS).
/// </summary>
/// <returns>Id of the best GPU</returns>
returns the best GPU (with maximum GFLOPS).
returns the best GPU ( with maximum GFLOPS ) .
public static int GetMaxGflopsDeviceId()
		{
			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;
			CudaDeviceProperties deviceProp;
			device_count = CudaContext.GetDeviceCount();
			while (current_device < device_count)
			{
				deviceProp = CudaContext.GetDeviceInfo(current_device);
				if (deviceProp.ComputeCapability.Major > 0 && deviceProp.ComputeCapability.Major < 9999)
				{
					best_SM_arch = Math.Max(best_SM_arch, deviceProp.ComputeCapability.Major);
				}
				current_device++;
			}
			current_device = 0;
			while (current_device < device_count)
			{
				deviceProp = CudaContext.GetDeviceInfo(current_device);
				if (deviceProp.ComputeCapability.Major == 9999 && deviceProp.ComputeCapability.Minor == 9999)
				{
					sm_per_multiproc = 1;
				}
				else
				{
					sm_per_multiproc = _ConvertSMVer2Cores(deviceProp.ComputeCapability.Major, deviceProp.ComputeCapability.Minor);
				}
				int compute_perf = deviceProp.MultiProcessorCount * sm_per_multiproc * deviceProp.ClockRate;
				if (compute_perf > max_compute_perf)
				{
					if (best_SM_arch > 2)
					{
						if (deviceProp.ComputeCapability.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;
		}
public static int GetMaxGflopsDeviceId ( ) { 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 ; CudaDeviceProperties deviceProp ; device_count = CudaContext . GetDeviceCount ( ) ; while ( current_device < device_count ) { deviceProp = CudaContext . GetDeviceInfo ( current_device ) ; if ( deviceProp . ComputeCapability . Major > 0 && deviceProp . ComputeCapability . Major < 9999 ) { best_SM_arch = Math . Max ( best_SM_arch , deviceProp . ComputeCapability . Major ) ; } current_device ++ ; } current_device = 0 ; while ( current_device < device_count ) { deviceProp = CudaContext . GetDeviceInfo ( current_device ) ; if ( deviceProp . ComputeCapability . Major == 9999 && deviceProp . ComputeCapability . Minor == 9999 ) { sm_per_multiproc = 1 ; } else { sm_per_multiproc = _ConvertSMVer2Cores ( deviceProp . ComputeCapability . Major , deviceProp . ComputeCapability . Minor ) ; } int compute_perf = deviceProp . MultiProcessorCount * sm_per_multiproc * deviceProp . ClockRate ; if ( compute_perf > max_compute_perf ) { if ( best_SM_arch > 2 ) { if ( deviceProp . ComputeCapability . 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 ; }
returns the best GPU (with maximum GFLOPS).
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
Id of the best GPU
Id of the best GPU