Esempio n. 1
0
        public static DeviceQuery QueryGpuStatus(int pciBusID)
        {
            var info = GetAdapterInfoByPciBusID(pciBusID);

            var errorMessages = new string[7];

            try
            {
                return(new DeviceQuery()
                {
                    FanSpeed = $"{GetAdapterFanCurrentSpeed(info, out errorMessages[0])} rpm",
                    Temperature = $"{GetAdapterTemperature(info, out errorMessages[1])} C",
                    PowerDraw = $"{Math.Round(GetAdapterNormalizedPower(info, out errorMessages[2]), 2)} W",
                    ClockGPU = $"{GetAdapterCurrentCoreClock(info, out errorMessages[3])} MHz",
                    ClockVRAM = $"{GetAdapterCurrentVramClock(info, out errorMessages[4])} MHz",
                    UtilizationGPU = $"{GetAdapterCurrentUtilization(info, out errorMessages[5])} %",
                    UtilizationVRAM = null // Not supported
                });
            }
            finally
            {
                foreach (var errorMessage in errorMessages)
                {
                    if (!string.IsNullOrWhiteSpace(errorMessage))
                    {
                        AMD_APP.Log(Logger.Level.Error, errorMessage);
                    }
                }
            }
        }
Esempio n. 2
0
        public static bool Initialize(out string errorMessage)
        {
            errorMessage = string.Empty;

            _PowerHistory = new List <Tuple <int, DateTime, decimal> >();
            try
            {
                var response = -1;

                if (ADL.ADL_Main_Control_Create != null)
                {
                    response = ADL.ADL_Main_Control_Create?.Invoke(ADL.ADL_Main_Memory_Alloc, 1 /*Get only the present adapters*/) ?? -1;
                }

                if (response != SUCCESS)
                {
                    errorMessage = "ADL_Main_Control_Create failed.";
                    return(false);
                }

                var numOfAdapters = 0;
                response = ADL.ADL_Adapter_NumberOfAdapters_Get?.Invoke(ref numOfAdapters) ?? -1;

                if (response != SUCCESS)
                {
                    errorMessage = "ADL_Adapter_NumberOfAdapters_Get failed.";
                    return(false);
                }

                if (numOfAdapters < 1)
                {
                    errorMessage = "ADL returned no adapter.";
                    return(false);
                }

                var adapterInfos = new ADL_AdapterInfoArray();
                int size         = Marshal.SizeOf(adapterInfos);

                var adapterBuffer = Marshal.AllocCoTaskMem(size);
                try
                {
                    Marshal.StructureToPtr(adapterInfos, adapterBuffer, false);
                    response = ADL.ADL_Adapter_AdapterInfo_Get?.Invoke(adapterBuffer, size) ?? -1;

                    if (response != SUCCESS)
                    {
                        errorMessage = $"ADL_Adapter_AdapterInfo_Get() returned error code {response}";
                        return(false);
                    }
                    adapterInfos = Marshal.PtrToStructure <ADL_AdapterInfoArray>(adapterBuffer);
                }
                finally { Marshal.FreeCoTaskMem(adapterBuffer); }

                var infoList = new List <DeviceAdapterInfo>(numOfAdapters);

                for (var i = 0; i < numOfAdapters; i++)
                {
                    var info = adapterInfos.ADLAdapterInfo[i];
                    int isSupported = 0, isEnabled = 0, version = 0;

                    if (infoList.Any(di => di.Info.BusNumber == info.BusNumber))
                    {
                        continue;
                    }

                    response = ADL.ADL2_Overdrive_Caps?.Invoke(IntPtr.Zero, info.AdapterIndex, ref isSupported, ref isEnabled, ref version) ?? -1;

                    if (response == SUCCESS)
                    {
                        infoList.Add(new DeviceAdapterInfo()
                        {
                            Info = info,
                            IsOverdriveSupported = (isSupported > 0),
                            IsEnabled            = (isEnabled > 0),
                            OverdriveVersion     = version
                        });
                    }
                }

                AdapterInfos = infoList.Where(i => i.IsOverdriveSupported).ToArray();
                infoList.Clear();
                return(true);
            }
            catch (Exception ex)
            {
                AMD_APP.Log(ex);
                AMD_APP.Log(Logger.Level.Error, "Failed to initialize AMD ADL.");
                return(false);
            }
        }