Esempio n. 1
0
        // We check only missing from inital detection. Case like device poping back is not covered (ultra rare case)
        public static async Task <bool> CheckIfMissingGPUs()
        {
            async Task <bool> anyMissingCUDA_Devices()
            {
                try
                {
                    if (!DetectionResult.HasCUDADevices)
                    {
                        return(false);
                    }
                    var cudaQueryResult = await CUDADetector.TryQueryCUDADevicesAsync();

                    var supportedCudaDevices = cudaQueryResult.parsed.CudaDevices
                                               .Select(CUDADetector.Transform)
                                               .Where(IsCUDADeviceSupported)
                                               .Select(dev => dev.UUID)
                                               .ToArray();
                    var missing = DetectionResult.CUDADevices.Where(detected => !supportedCudaDevices.Contains(detected.UUID));
                    if (missing.Any())
                    {
                        Logger.Error(Tag, $"CUDA missing devices:\n{string.Join("\n", missing.Select(dev => $"\t{dev.UUID}"))}");
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(Tag, $"CUDA CheckIfMissingDevices error: {e}");
                }
                return(false);
            }

            async Task <bool> anyMissingAMD_Devices()
            {
                try
                {
                    if (!DetectionResult.HasAMDDevices)
                    {
                        return(false);
                    }
                    var amdDevices = await AMD.AMDDetector.TryQueryAMDDevicesAsync(DetectionResult.AvailableVideoControllers.ToList());

                    var amdDevicesUUIDs = amdDevices
                                          .Select(dev => dev.UUID)
                                          .ToArray();
                    var missing = DetectionResult.AMDDevices.Where(detected => !amdDevicesUUIDs.Contains(detected.UUID));
                    if (missing.Any())
                    {
                        Logger.Error(Tag, $"AMD missing devices:\n{string.Join("\n", missing.Select(dev => $"\t{dev.UUID}"))}");
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(Tag, $"AMD CheckIfMissingDevices error: {e}");
                }
                return(false);
            }

            return(await anyMissingCUDA_Devices() || await anyMissingAMD_Devices());
        }
Esempio n. 2
0
        public static async Task <int> CUDADevicesNumCheck()
        {
            var cudaQueryResult = await CUDADetector.TryQueryCUDADevicesAsync();

            var result = cudaQueryResult.parsed;

            return(result?.CudaDevices?.Count ?? 0);
        }
Esempio n. 3
0
        private static async Task DetectCUDADevices()
        {
            var cudaQueryResult = await CUDADetector.TryQueryCUDADevicesAsync();

            Logger.Info(Tag, $"TryQueryCUDADevicesAsync RAW: '{cudaQueryResult.rawOutput}'");
            var result     = cudaQueryResult.parsed;
            var unsuported = new List <CUDADevice>();

            if (result?.CudaDevices?.Count > 0)
            {
                // we got NVIDIA devices
                var cudaDevices = result.CudaDevices.Select(dev => CUDADetector.Transform(dev)).ToList();
                // filter out no supported SM versions
                // SM 3.0+
                DetectionResult.CUDADevices = cudaDevices.Where(cudaDev => cudaDev.SM_major >= 3).OrderBy(cudaDev => cudaDev.PCIeBusID).ToList();
                unsuported = cudaDevices.Where(cudaDev => cudaDev.SM_major < 3).ToList();
                // NVIDIA drivers
                var nvmlLoaded = result?.NvmlLoaded ?? -1;
                DetectionResult.IsDCHDriver = nvmlLoaded == 1;
                if (nvmlLoaded == 1 && result.DriverVersion.Contains('.'))
                {
                    var driverVer = result.DriverVersion.Split('.').Select(s => int.Parse(s)).ToArray();
                    if (driverVer.Count() >= 2)
                    {
                        DetectionResult.NvidiaDriver = new Version(driverVer[0], driverVer[1]);
                    }
                }
                else
                {
                    // TODO PROBLEM IF NO NVML LOADED
                }
            }

            // set NVIDIA driver version here
            if (DetectionResult.NvidiaDriver != null)
            {
                // from cuda detect
                Logger.Info(Tag, "DetectCUDADevices Setting Nvidia Driver");
                CUDADevice.INSTALLED_NVIDIA_DRIVERS = DetectionResult.NvidiaDriver;
            }
            else if (DetectionResult.NvidiaDriverWMI != null)
            {
                // from WMI
                Logger.Info(Tag, "DetectCUDADevices Setting Nvidia Driver Fallback (WMI)");
                CUDADevice.INSTALLED_NVIDIA_DRIVERS = DetectionResult.NvidiaDriverWMI;
            }

            // log result
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("");
            stringBuilder.AppendLine("DetectCUDADevices:");
            CUDADetector.LogDevices(stringBuilder, unsuported, false);
            CUDADetector.LogDevices(stringBuilder, DetectionResult.CUDADevices, true);
            Logger.Info(Tag, stringBuilder.ToString());
        }
Esempio n. 4
0
        private static async Task DetectCUDADevices()
        {
            var cudaQueryResult = await CUDADetector.TryQueryCUDADevicesAsync();

            Logger.Info(Tag, $"TryQueryCUDADevicesAsync RAW: '{cudaQueryResult.rawOutput}'");
            var result = cudaQueryResult.parsed;

            if (result?.CudaDevices?.Count > 0)
            {
                // we got NVIDIA devices
                var cudaDevices = result.CudaDevices.Select(dev => CUDADetector.Transform(dev)).ToList();
                // filter out no supported SM versions
                DetectionResult.CUDADevices            = cudaDevices.Where(IsCUDADeviceSupported).OrderBy(cudaDev => cudaDev.PCIeBusID).ToList();
                DetectionResult.UnsupportedCUDADevices = cudaDevices.Where(cudaDev => IsCUDADeviceSupported(cudaDev) == false).ToList();
                // NVIDIA drivers
                var nvmlLoaded = result?.NvmlLoaded ?? -1;
                DetectionResult.IsDCHDriver                  = nvmlLoaded == 1;
                DetectionResult.IsNvidiaNVMLLoadedError      = nvmlLoaded == -1;
                DetectionResult.IsNvidiaNVMLInitializedError = result?.NvmlInitialized != 0;
                var smiVersion = NvidiaSmiDriver.ToNvidiaSmiDriver(result.DriverVersion);
                if (smiVersion.IsValid)
                {
                    DetectionResult.NvidiaDriver = smiVersion.Version;
                }
            }

            // set NVIDIA driver version here
            if (DetectionResult.NvidiaDriver != null)
            {
                // from cuda detect
                Logger.Info(Tag, "DetectCUDADevices Setting Nvidia Driver");
                CUDADevice.INSTALLED_NVIDIA_DRIVERS = DetectionResult.NvidiaDriver;
            }
            else if (DetectionResult.NvidiaDriverWMI != null)
            {
                // from WMI
                Logger.Info(Tag, "DetectCUDADevices Setting Nvidia Driver Fallback (WMI)");
                CUDADevice.INSTALLED_NVIDIA_DRIVERS = DetectionResult.NvidiaDriverWMI;
            }

            // log result
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("");
            stringBuilder.AppendLine("DetectCUDADevices:");
            CUDADetector.LogDevices(stringBuilder, DetectionResult.UnsupportedCUDADevices, false);
            CUDADetector.LogDevices(stringBuilder, DetectionResult.CUDADevices, true);
            Logger.Info(Tag, stringBuilder.ToString());
        }