コード例 #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}'");

            var result = openCLResult.parsed;

            if (result?.Platforms?.Count > 0)
            {
                var amdPlatforms = result.Platforms.Where(platform => IsAMDPlatform(platform)).ToList();
                foreach (var platform in amdPlatforms)
                {
                    var platformNum = platform.PlatformNum;
                    if (platform.Devices.Count > 0)
                    {
                        AMDDevice.GlobalOpenCLPlatformID = 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.AMD_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.AMD_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.AMD_BUS_ID, gpuRAM, codename, infSection, platformNum);
                        amdDevices.Add(amdDevice);
                    }
                }
            }
            Logger.Info(Tag, "TryQueryAMDDevicesAsync END");

            return(amdDevices);
        }
コード例 #2
0
ファイル: CPUDetector.cs プロジェクト: nasri190/NiceHashMiner
        public static Task <CPUDevice> TryQueryCPUDeviceTask()
        {
            return(Task.Run(async() =>
            {
                var(cpuJSON, cpuID) = await TryQueryCPUDevicesAsync();
                Logger.Info(Tag, cpuJSON);
                if (!CpuUtils.IsCpuMiningCapable(cpuID))
                {
                    return null;
                }

                var cpuDetectResult = QueryCPUDevice();
                // get all CPUs
                var cpuCount = cpuID.PhysicalProcessorCount;
                var name = cpuID.Name.Trim();
                // get all cores (including virtual - HT can benefit mining)
                var threadsPerCpu = cpuDetectResult.VirtualCoresCount / cpuCount;
                // TODO important move this to settings
                var threadsPerCpuMask = threadsPerCpu;
                if (threadsPerCpu * cpuCount > 64)
                {
                    // set lower
                    threadsPerCpuMask = 64;
                }

                List <ulong> affinityMasks = null;
                // multiple CPUs are identified as a single CPU from nhm perspective, it is the miner plugins job to handle this correctly
                if (cpuCount > 1)
                {
                    name = $"({cpuCount}x){name}";
                    affinityMasks = new List <ulong>();
                    for (var i = 0; i < cpuCount; i++)
                    {
                        var affinityMask = CpuUtils.CreateAffinityMask(i, threadsPerCpuMask);
                        affinityMasks.Add(affinityMask);
                    }
                }
                var hashedInfo = $"{0}--{name}--{threadsPerCpu}";
                foreach (var cpuInfo in cpuDetectResult.CpuInfos)
                {
                    hashedInfo += $"{cpuInfo.Family}--{cpuInfo.ModelName}--{cpuInfo.NumberOfCores}--{cpuInfo.PhysicalID}--{cpuInfo.VendorID}";
                    hashedInfo += cpuJSON;
                }
                var uuidHEX = UUID.GetHexUUID(hashedInfo);
                var uuid = $"CPU-{uuidHEX}";

                // plugin device
                var bd = new BaseDevice(DeviceType.CPU, uuid, name, 0);
                var cpu = new CPUDevice(bd, cpuCount, threadsPerCpu, cpuDetectResult.IsHyperThreadingEnabled, affinityMasks, CpuUtils.SupportedExtensions(cpuID), cpuID);
                return cpu;
            }));
        }
コード例 #3
0
        public static CUDADevice Transform(CudaDevice cudaDevice)
        {
            string uuid = cudaDevice.UUID;

            // if no nvml loaded fallback ID
            if (string.IsNullOrEmpty(uuid))
            {
                var infoToHashed = $"{cudaDevice.DeviceID}--{DeviceType.NVIDIA}--{cudaDevice.DeviceGlobalMemory}--{cudaDevice.SM_major}--{cudaDevice.SM_minor}--{cudaDevice.DeviceName}--{cudaDevice.pciBusID}";
                var uuidHEX      = UUID.GetHexUUID(infoToHashed);
                uuid = $"NVF-{uuidHEX}"; // TODO indicate NVF as NVIDIA Fallback
            }
            var name = GetNameFromCudaDevice(cudaDevice);
            var bd   = new BaseDevice(DeviceType.NVIDIA, uuid, name, (int)cudaDevice.DeviceID);

            return(new CUDADevice(bd, cudaDevice.pciBusID, cudaDevice.DeviceGlobalMemory, cudaDevice.SM_major, cudaDevice.SM_minor));
        }
コード例 #4
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);
        }
コード例 #5
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);
        }