Ejemplo n.º 1
0
        public static async Task <List <AMDDevice> > TryQueryAMDDevicesAsync(List <VideoControllerData> availableVideoControllers)
        {
            var amdDevices = new List <AMDDevice>();

            Logger.Info(Tag, "TryQueryAMDDevicesAsync START");
            var openCLResult = await OpenCLDetector.TryQueryOpenCLDevicesAsync();

            Logger.Info(Tag, $"TryQueryOpenCLDevicesAsync RAW: '{openCLResult.rawOutput}'");


            OpenCLDeviceDetectionResult result = null;

            // check if we have duplicated platforms
            Logger.Info(Tag, "Checking duplicate devices...");
            if (DuplicatedDevices(openCLResult.parsed))
            {
                Logger.Info(Tag, "Found duplicate devices. Trying fallback detection");
                var openCLResult2 = await OpenCLDetector.TryQueryOpenCLDevicesAsyncFallback();

                Logger.Info(Tag, $"TryQueryOpenCLDevicesAsyncFallback RAW: '{openCLResult2.rawOutput}'");
                if (DuplicatedDevices(openCLResult2.parsed))
                {
                    Logger.Info(Tag, $"TryQueryOpenCLDevicesAsyncFallback has duplicate files as well... Taking filtering lower platform devices");
                    // #3 try merging both results and take lower platform unique devices
                    result = MergeResults(openCLResult.parsed, openCLResult2.parsed);
                }
                else
                {
                    // #2 try good
                    result = openCLResult2.parsed;
                }
            }
            else
            {
                // #1 try good
                result = openCLResult.parsed;
            }

            if (result?.Platforms?.Count > 0)
            {
                Platforms = result.Platforms;
                var amdPlatforms = result.Platforms.Where(platform => IsAMDPlatform(platform)).ToList();
                foreach (var platform in amdPlatforms)
                {
                    var platformNum = platform.PlatformNum;
                    foreach (var oclDev in platform.Devices)
                    {
                        var infSection   = "";
                        var name         = oclDev._CL_DEVICE_BOARD_NAME_AMD;
                        var codename     = oclDev._CL_DEVICE_NAME;
                        var gpuRAM       = oclDev._CL_DEVICE_GLOBAL_MEM_SIZE;
                        var infoToHashed = $"{oclDev.DeviceID}--{DeviceType.AMD}--{gpuRAM}--{codename}--{name}";
                        // cross ref info from vid controllers with bus id
                        var vidCtrl = availableVideoControllers?.Where(vid => vid.PCI_BUS_ID == oclDev.BUS_ID).FirstOrDefault() ?? null;
                        if (vidCtrl != null)
                        {
                            infSection    = vidCtrl.InfSection;
                            infoToHashed += vidCtrl.PnpDeviceID;
                        }
                        else
                        {
                            Logger.Info(Tag, $"TryQueryAMDDevicesAsync cannot find VideoControllerData with bus ID {oclDev.BUS_ID}");
                        }
                        var uuidHEX = UUID.GetHexUUID(infoToHashed);
                        var uuid    = $"AMD-{uuidHEX}";

                        var bd        = new BaseDevice(DeviceType.AMD, uuid, name, (int)oclDev.DeviceID);
                        var amdDevice = new AMDDevice(bd, oclDev.BUS_ID, gpuRAM, codename, infSection, platformNum);
                        amdDevices.Add(amdDevice);
                    }
                }
            }
            Logger.Info(Tag, "TryQueryAMDDevicesAsync END");

            return(amdDevices);
        }
Ejemplo n.º 2
0
        public static async Task <List <AMDDevice> > TryQueryAMDDevicesAsync(List <VideoControllerData> availableVideoControllers)
        {
            var amdDevices = new List <AMDDevice>();

            Logger.Info(Tag, "TryQueryAMDDevicesAsync START");
            var openCLResult = await OpenCLDetector.TryQueryOpenCLDevicesAsync();

            Logger.Info(Tag, $"TryQueryOpenCLDevicesAsync RAW: '{openCLResult.rawOutput}'");


            OpenCLDeviceDetectionResult result = null;

            // check if we have duplicated platforms
            Logger.Info(Tag, "Checking duplicate devices...");
            if (DuplicatedDevices(openCLResult.parsed))
            {
                Logger.Info(Tag, "Found duplicate devices. Trying fallback detection");
                var openCLResult2 = await OpenCLDetector.TryQueryOpenCLDevicesAsyncFallback();

                Logger.Info(Tag, $"TryQueryOpenCLDevicesAsyncFallback RAW: '{openCLResult2.rawOutput}'");
                IsOpenClFallback = true;
                if (DuplicatedDevices(openCLResult2.parsed))
                {
                    Logger.Info(Tag, $"TryQueryOpenCLDevicesAsyncFallback has duplicate files as well... Taking filtering lower platform devices");
                    // #3 try merging both results and take lower platform unique devices
                    result = MergeResults(openCLResult.parsed, openCLResult2.parsed);
                }
                else
                {
                    // #2 try good
                    result = openCLResult2.parsed;
                }
            }
            else
            {
                // #1 try good
                result = openCLResult.parsed;
            }

            if (result?.Platforms?.Count > 0)
            {
                Platforms = result.Platforms;
                var amdPlatforms = result.Platforms.Where(platform => IsAMDPlatform(platform)).ToList();
                foreach (var platform in amdPlatforms)
                {
                    var platformNum = platform.PlatformNum;
                    foreach (var oclDev in platform.Devices)
                    {
                        var infSection      = "";
                        var name            = oclDev._CL_DEVICE_BOARD_NAME_AMD;
                        var codename        = oclDev._CL_DEVICE_NAME;
                        var gpuRAM          = oclDev._CL_DEVICE_GLOBAL_MEM_SIZE;
                        var infoToHashedNew = $"{oclDev.DeviceID}--{oclDev.BUS_ID}--{DeviceType.AMD}--{codename}--{name}";
                        var infoToHashedOld = $"{oclDev.DeviceID}--{DeviceType.AMD}--{gpuRAM}--{codename}--{name}";
                        // cross ref info from vid controllers with bus id
                        var vidCtrl = availableVideoControllers?.Where(vid => vid.PCI_BUS_ID == oclDev.BUS_ID).FirstOrDefault() ?? null;
                        if (vidCtrl != null)
                        {
                            infSection       = vidCtrl.InfSection;
                            infoToHashedOld += vidCtrl.PnpDeviceID;
                            infoToHashedNew += vidCtrl.PnpDeviceID;
                        }
                        else
                        {
                            Logger.Info(Tag, $"TryQueryAMDDevicesAsync cannot find VideoControllerData with bus ID {oclDev.BUS_ID}");
                        }
                        var uuidHEXOld = UUID.GetHexUUID(infoToHashedOld);
                        var uuidHEXNew = UUID.GetHexUUID(infoToHashedNew);
                        var uuidOld    = $"AMD-{uuidHEXOld}";
                        var uuidNew    = $"AMD-{uuidHEXNew}";
                        // append VRAM to distinguish AMD GPUs

                        //transition from old uuid's to new
                        try
                        {
                            var cfgPathOld = Paths.ConfigsPath($"device_settings_{uuidOld}.json");
                            var cfgPathNew = Paths.ConfigsPath($"device_settings_{uuidNew}.json");
                            if (File.Exists(cfgPathOld) && !File.Exists(cfgPathNew))//rename file and rename first line
                            {
                                string configText = File.ReadAllText(cfgPathOld);
                                configText = configText.Replace(uuidOld, uuidNew);
                                File.WriteAllText(cfgPathNew, configText);
                                File.Delete(cfgPathOld);
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Info(Tag, $"Error when transitioning from old to new AMD GPU config file. " + e.Message);
                        }

                        var vramPart  = convertSize(gpuRAM);
                        var setName   = vramPart != null ? $"{name} {vramPart}" : name;
                        var bd        = new BaseDevice(DeviceType.AMD, uuidNew, setName, (int)oclDev.DeviceID);
                        var amdDevice = new AMDDevice(bd, oclDev.BUS_ID, gpuRAM, codename, infSection, platformNum);
                        var thisDeviceExtraADLResult = result.AMDBusIDVersionPairs.FirstOrDefault(ver => ver.BUS_ID == oclDev.BUS_ID);
                        if (thisDeviceExtraADLResult != null && thisDeviceExtraADLResult.BUS_ID == oclDev.BUS_ID)
                        {
                            amdDevice.ADLFunctionCall  = thisDeviceExtraADLResult.FunctionCall;
                            amdDevice.ADLReturnCode    = thisDeviceExtraADLResult.ADLRetCode;
                            amdDevice.RawDriverVersion = thisDeviceExtraADLResult.AdrenalinVersion;
                            if (Version.TryParse(thisDeviceExtraADLResult.AdrenalinVersion, out var parsedVer))
                            {
                                amdDevice.DEVICE_AMD_DRIVER = parsedVer;
                            }
                        }
                        amdDevices.Add(amdDevice);
                    }
                }
            }
            Logger.Info(Tag, "TryQueryAMDDevicesAsync END");

            return(amdDevices);
        }