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); }
private List <AmdComputeDevice> ProcessDevices(OpenCLDeviceDetectionResult openCLData) { var amdOclDevices = new List <OpenCLDevice>(); var amdDevices = new List <OpenCLDevice>(); var amdPlatformNumFound = false; foreach (var oclEl in openCLData.Platforms) { if (!oclEl.PlatformName.Contains("AMD") && !oclEl.PlatformName.Contains("amd")) { continue; } amdPlatformNumFound = true; var amdOpenCLPlatformStringKey = oclEl.PlatformName; AvailableDevices.AmdOpenCLPlatformNum = oclEl.PlatformNum; amdOclDevices = oclEl.Devices; Helpers.ConsolePrint(Tag, $"AMD platform found: Key: {amdOpenCLPlatformStringKey}, Num: {AvailableDevices.AmdOpenCLPlatformNum}"); break; } if (!amdPlatformNumFound) { return(null); } // get only AMD gpus { foreach (var oclDev in amdOclDevices) { if (oclDev._CL_DEVICE_TYPE.Contains("GPU")) { amdDevices.Add(oclDev); } } } if (amdDevices.Count == 0) { Helpers.ConsolePrint(Tag, "AMD GPUs count is 0"); return(null); } Helpers.ConsolePrint(Tag, "AMD GPUs count : " + amdDevices.Count); Helpers.ConsolePrint(Tag, "AMD Getting device name and serial from ADL"); // ADL var isAdlInit = AdlQuery.TryQuery(out var busIdInfos, out var numDevs); var isBusIDOk = true; // check if buss ids are unique and different from -1 { var busIDs = new HashSet <int>(); // Override AMD bus IDs var overrides = ConfigManager.GeneralConfig.OverrideAMDBusIds.Split(','); for (var i = 0; i < amdDevices.Count; i++) { var amdOclDev = amdDevices[i]; if (overrides.Count() > i && int.TryParse(overrides[i], out var overrideBus) && overrideBus >= 0) { amdOclDev.AMD_BUS_ID = overrideBus; } if (amdOclDev.AMD_BUS_ID < 0 || !busIdInfos.ContainsKey(amdOclDev.AMD_BUS_ID)) { isBusIDOk = false; break; } busIDs.Add(amdOclDev.AMD_BUS_ID); } // check if unique isBusIDOk = isBusIDOk && busIDs.Count == amdDevices.Count; } // print BUS id status Helpers.ConsolePrint(Tag, isBusIDOk ? "AMD Bus IDs are unique and valid. OK" : "AMD Bus IDs IS INVALID. Using fallback AMD detection mode"); /////// // AMD device creation (in NHM context) AmdDeviceCreation devCreator; if (isAdlInit && isBusIDOk) { devCreator = new AmdDeviceCreationPrimary(busIdInfos); } else { devCreator = new AmdDeviceCreationFallback(); } return(devCreator.CreateDevices(_numDevs, amdDevices, _noNeoscryptLyra2)); }
// take lower platform private static OpenCLDeviceDetectionResult MergeResults(OpenCLDeviceDetectionResult a, OpenCLDeviceDetectionResult b) { var addedDevicesWithBusID = new HashSet <int>(); var platformDevices = new Dictionary <int, OpenCLPlatform>(); Action <OpenCLDeviceDetectionResult> fillUniquePlatformDevices = (OpenCLDeviceDetectionResult r) => { if (r?.Platforms?.Count > 0) { var amdPlatforms = r.Platforms .Where(platform => IsAMDPlatform(platform)) .OrderBy(p => p.PlatformNum) .ToList(); foreach (var platform in amdPlatforms) { if (!platformDevices.ContainsKey(platform.PlatformNum)) { platformDevices[platform.PlatformNum] = new OpenCLPlatform { PlatformNum = platform.PlatformNum, //Devices = WE ADD DEVICES, PlatformName = platform.PlatformName, PlatformVendor = platform.PlatformVendor, }; } var curPlatform = platformDevices[platform.PlatformNum]; foreach (var oclDev in platform.Devices) { if (!addedDevicesWithBusID.Contains(oclDev.BUS_ID)) { addedDevicesWithBusID.Add(oclDev.BUS_ID); curPlatform.Devices.Add(oclDev); } } } } }; fillUniquePlatformDevices(a); fillUniquePlatformDevices(b); var ret = new OpenCLDeviceDetectionResult { Platforms = platformDevices.Values.ToList(), ErrorString = "", Status = "", }; return(ret); }
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); }