static void Main(string[] args) { var gpus = NvidiaGPU.EnumGPUs(); if (gpus == null || gpus.Count == 0) { Console.WriteLine("Nvidia gpu is not found."); return; } Console.WriteLine("gpumap v{0} by emminer, inspired by leenoox's gpumap in nvOC.", GetVersion()); Console.WriteLine("gpumap will help you physically map your GPU's by spinning single GPU fan(s) only, one at a time."); Console.WriteLine("It will also show some info about the GPU. Please follow prompts."); Console.WriteLine("gpumap has detected {0} GPU's.", gpus.Count); Console.WriteLine("To continue make sure you've stoped all mining processes."); Console.WriteLine("Continue(y / n) ? "); var key = Console.ReadKey(); Console.WriteLine(); if (key.KeyChar == 'y') { var cuda_drvice_order_env = Environment.GetEnvironmentVariable("CUDA_DEVICE_ORDER"); if (!"PCI_BUS_ID".Equals(cuda_drvice_order_env, StringComparison.Ordinal)) { Console.WriteLine("Fixing the CUDA_DEVICE_ORDER=PCI_BUS_ID in order to properly map GPU's."); Console.WriteLine("Please reboot for the changes to take effect."); Environment.SetEnvironmentVariable("CUDA_DEVICE_ORDER", "PCI_BUS_ID", EnvironmentVariableTarget.User); } else { Run(gpus); } } }
public static List <NvidiaGPU> EnumGPUs() { NvStatus status; var gpus = new List <NvidiaGPU>(); if (!NVAPI.IsAvailable) { return(gpus); } var gpuHandles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS]; status = NVAPI.NvAPI_EnumPhysicalGPUs(gpuHandles, out int count); if (status != NvStatus.OK) { return(gpus); } for (int i = 0; i < count; i++) { var handle = gpuHandles[i]; var sb = new StringBuilder(NVAPI.SHORT_STRING_MAX); status = NVAPI.NvAPI_GPU_GetFullName(handle, sb); if (status != NvStatus.OK) { continue; } NvGPUCoolerSettings settings = new NvGPUCoolerSettings { Version = NVAPI.GPU_COOLER_SETTINGS_VER, Count = 1, Coolers = new NvCooler[NVAPI.MAX_COOLER_PER_GPU] }; status = NVAPI.NvAPI_GPU_GetCoolerSettings(handle, 0, ref settings); if (status != NvStatus.OK) { continue; } status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle, out uint deviceId, out uint subSystemId, out uint revisionId, out uint extDeviceId); if (status != NvStatus.OK) { continue; } status = NVAPI.NvAPI_GPU_GetBusId(handle, out uint busId); if (status != NvStatus.OK) { continue; } var gpu = new NvidiaGPU(handle, settings) { BusId = busId, Name = sb.ToString(), Index = i, SubDeviceId = subSystemId }; gpus.Add(gpu); } return(gpus); }