private static bool GetCoolerSettings(int busId, out NvCoolerSettings info) { info = NvCoolerSettings.Create(); if (NvapiNativeMethods.NvGetCoolerSettings == null) { return(false); } if (_nvGetCoolerSettingsNotSupporteds.Contains(busId)) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } NvCoolerTarget coolerIndex = NvCoolerTarget.NVAPI_COOLER_TARGET_ALL; var r = NvapiNativeMethods.NvGetCoolerSettings(handle, coolerIndex, ref info); if (r != NvStatus.NVAPI_OK) { if (r == NvStatus.NVAPI_NOT_SUPPORTED || r == NvStatus.NVAPI_FIRMWARE_REVISION_NOT_SUPPORTED || r == NvStatus.NVAPI_GPU_NOT_POWERED) { _nvGetCoolerSettingsNotSupporteds.Add(busId); } NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetCoolerSettings)} {r.ToString()}"); return(false); } return(true); } catch { } return(false); }
internal static AdlStatus ADLMainControlCreate(out IntPtr context) { AdlStatus r; string dllName = "atiadlxx.dll"; try { CreateDelegates(dllName); r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1); } catch (Exception e) { Logger.ErrorDebugLine(e); try { dllName = "atiadlxy.dll"; CreateDelegates(dllName); r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1); } catch (Exception ex) { Logger.ErrorDebugLine(ex); r = AdlStatus.ADL_ERR; } } if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(ADL_Main_Control_Create)} {r.ToString()} {dllName}"); } ADL2MainControlCreate(out context); return(r); }
private int GetTemperature(int gpuIndex) { try { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return(0); } if (gpu.OverdriveVersion >= 7) { var r = AdlNativeMethods.ADL2_OverdriveN_Temperature_Get(_context, gpu.AdapterIndex, ADLODNTemperatureType.CORE, out int temperature); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_Temperature_Get)} {r.ToString()}"); return(0); } return((int)(0.001f * temperature)); } else { ADLTemperature info = new ADLTemperature(); var r = AdlNativeMethods.ADL_Overdrive5_Temperature_Get(gpu.AdapterIndex, 0, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Overdrive5_Temperature_Get)} {r.ToString()}"); return(0); } return((int)(0.001f * info.Temperature)); } } catch { } return(0); }
private static bool NvThermalPoliciesSetLimit(int busId, ref NvGpuThermalLimit info) { if (NvapiNativeMethods.NvThermalPoliciesSetLimit == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvThermalPoliciesSetLimit(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvThermalPoliciesSetLimit)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { return(true); } } catch { } return(false); }
public void GetTempLimitAndPowerLimit(int gpuIndex, out int powerLimit, out int tempLimit) { powerLimit = 0; tempLimit = 0; if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return; } if (gpu.OverdriveVersion < 8) { ADLODNPowerLimitSetting info = new ADLODNPowerLimitSetting(); try { var r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get(_context, gpu.AdapterIndex, out info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get)} {r.ToString()}"); } else { powerLimit = 100 + info.iTDPLimit; tempLimit = info.iMaxOperatingTemperature; } } catch { } } else { if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting)) { powerLimit = 100 + odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_POWER_PERCENTAGE]; tempLimit = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_FAN_CURVE_TEMPERATURE_5]; } } }
private static bool GetFanCoolersGetStatus(int busId, out PrivateFanCoolersStatusV1 info) { info = PrivateFanCoolersStatusV1.Create(); if (NvapiNativeMethods.NvFanCoolersGetStatus == null) { return(false); } if (_nvFanCoolersGetStatusNotSupporteds.Contains(busId)) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvFanCoolersGetStatus(handle, ref info); if (r != NvStatus.NVAPI_OK) { if (r == NvStatus.NVAPI_NOT_SUPPORTED || r == NvStatus.NVAPI_FIRMWARE_REVISION_NOT_SUPPORTED) { _nvFanCoolersGetStatusNotSupporteds.Add(busId); } NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersGetStatus)} {r.ToString()}"); return(false); } return(true); } catch { } return(false); }
static AdlHelper() { try { int numberOfAdapters = 0; var adlStatus = AdlNativeMethods.ADLMainControlCreate(out _context); if (adlStatus >= AdlStatus.ADL_OK) { adlStatus = AdlNativeMethods.ADL_Adapter_NumberOfAdapters_Get(ref numberOfAdapters); if (adlStatus < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL_Adapter_NumberOfAdapters_Get)} {adlStatus.ToString()}"); } } if (numberOfAdapters > 0) { _adapterInfoes = new ADLAdapterInfo[numberOfAdapters]; adlStatus = AdlNativeMethods.ADLAdapterAdapterInfoGet(_adapterInfoes); if (adlStatus >= AdlStatus.ADL_OK && _adapterInfoes != null && _adapterInfoes.Length != 0) { _adapterInfoes = _adapterInfoes.Where(adapterInfo => !string.IsNullOrEmpty(adapterInfo.UDID) && adapterInfo.VendorID == AdlConst.ATI_VENDOR_ID).ToArray(); _isHasATIGpu = _adapterInfoes.Length > 0; } } } catch (Exception ex) { Logger.ErrorDebugLine(ex); } }
public bool SetTempLimit(int gpuIndex, int value) { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(false); } ADLODNPowerLimitSetting info = new ADLODNPowerLimitSetting(); try { var r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Get)} {r.ToString()}"); return(false); } bool isAutoModel = value == 0; info.iMode = isAutoModel ? AdlConst.ODNControlType_Auto : AdlConst.ODNControlType_Manual; info.iMaxOperatingTemperature = isAutoModel ? -1 : value; r = AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_PowerLimit_Set)} {r.ToString()}"); return(false); } return(true); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } }
private bool NvGetPStateV1(int busId, out NvGpuPerfPStates20InfoV1 info) { info = NvGpuPerfPStates20InfoV1.Create(); if (NvapiNativeMethods.NvGetPStateV1 == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvGetPStateV1(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetPStateV1)} {r.ToString()}"); return(false); } return(true); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } }
public uint GetFanSpeed(int gpuIndex) { if (!NvmlInit() || !TryGetNvmlDevice(gpuIndex, out nvmlDevice nvmlDevice)) { return(0); } if (_nvmlDeviceGetFanSpeedNotSupporteds.Contains(gpuIndex)) { return(0); } uint fanSpeed = 0; try { var r = NvmlNativeMethods.nvmlDeviceGetFanSpeed(nvmlDevice, ref fanSpeed); if (r != nvmlReturn.Success) { if (r == nvmlReturn.NotSupported) { _nvmlDeviceGetFanSpeedNotSupporteds.Add(gpuIndex); } NTMinerConsole.DevError(() => $"{nameof(NvmlNativeMethods.nvmlDeviceGetFanSpeed)} {r.ToString()}"); } } catch { } return(fanSpeed); }
public void GetTemperature(IGpu gpu, out uint coreTemperature, out uint memoryTemperature) { coreTemperature = 0; memoryTemperature = 0; if (NvapiNativeMethods.NvGetThermalSettings == null) { return; } try { int busId = gpu.GetOverClockId(); if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return; } NvGPUThermalSettings settings = NvGPUThermalSettings.Create(); var r = NvapiNativeMethods.NvGetThermalSettings(handle, (int)NvThermalTarget.ALL, ref settings); if (r != NvStatus.NVAPI_OK) { settings.Count = 0; NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetThermalSettings)} {r.ToString()}"); } if (settings.Count > 0) { coreTemperature = settings.Sensor[0].CurrentTemp; } // TODO:3090是支持显存温度的,但不知道用什么接口读取 if (settings.Count > 1) { memoryTemperature = settings.Sensor[1].CurrentTemp; } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
private bool NvFanCoolersGetControl(int busId, out PrivateFanCoolersControlV1 info) { info = new PrivateFanCoolersControlV1(); if (NvapiNativeMethods.NvFanCoolersGetControl == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } info.version = (uint)(VERSION1 | (Marshal.SizeOf(typeof(PrivateFanCoolersControlV1)))); var r = NvapiNativeMethods.NvFanCoolersGetControl(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersGetControl)} {r.ToString()}"); return(false); } return(true); } catch { } return(false); }
private static void CheckResult(nvmlReturn r, Func <string> getMessage) { if (r != nvmlReturn.Success) { NTMinerConsole.DevError(getMessage); } }
private NvGpuThermalLimit NvThermalPoliciesGetLimit(int busId) { NvGpuThermalLimit info = new NvGpuThermalLimit(); if (NvapiNativeMethods.NvThermalPoliciesGetLimit == null) { return(info); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(info); } info.version = (uint)(VERSION2 | (Marshal.SizeOf(typeof(NvGpuThermalLimit)))); var r = NvapiNativeMethods.NvThermalPoliciesGetLimit(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvThermalPoliciesGetLimit)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { return(info); } } catch { } return(info); }
private bool NvPowerPoliciesGetInfo(int busId, out NvGpuPowerInfo info) { info = new NvGpuPowerInfo(); if (NvapiNativeMethods.NvPowerPoliciesGetInfo == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } info.version = (uint)(VERSION1 | (Marshal.SizeOf(typeof(NvGpuPowerInfo)))); var r = NvapiNativeMethods.NvPowerPoliciesGetInfo(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvPowerPoliciesGetInfo)} {r.ToString()}"); return(false); } return(true); } catch { return(false); } }
private bool NvSetPStateV1(int busId, ref NvGpuPerfPStates20InfoV1 info) { if (NvapiNativeMethods.NvSetPStateV1 == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } int len = Marshal.SizeOf(typeof(NvGpuPerfPStates20InfoV1)); info.version = (uint)(VERSION1 | (Marshal.SizeOf(typeof(NvGpuPerfPStates20InfoV1)))); var r = NvapiNativeMethods.NvSetPStateV1(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvSetPStateV1)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { return(true); } } catch { } return(false); }
private NvGpuClockFrequenciesV2 NvGetAllClockFrequenciesV2(int busId, uint type) { NvGpuClockFrequenciesV2 info = new NvGpuClockFrequenciesV2(); if (NvapiNativeMethods.NvGetAllClockFrequenciesV2 == null) { return(info); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(info); } info.version = (uint)(VERSION2 | (Marshal.SizeOf(typeof(NvGpuClockFrequenciesV2)))); info.ClockType = type; var r = NvapiNativeMethods.NvGetAllClockFrequenciesV2(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetAllClockFrequenciesV2)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { return(info); } } catch { } return(info); }
public bool GetMemoryClock(int gpuIndex, out int memoryClock, out int iVddc) { memoryClock = 0; iVddc = 0; try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(false); } ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create(); var r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}"); return(false); } int index = 0; for (int i = 0; i < info.aLevels.Length; i++) { if (info.aLevels[i].iEnabled != 0) { index = i; } NTMinerConsole.DevWarn(() => "GetMemoryClock " + info.aLevels[i].ToString()); } memoryClock = info.aLevels[index].iClock * 10; iVddc = info.aLevels[index].iVddc; return(true); } catch { return(false); } }
private bool NvGetPStateV2(int busId, out NvGpuPerfPStates20InfoV2 info) { info = new NvGpuPerfPStates20InfoV2(); if (NvapiNativeMethods.NvGetPStateV2 == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } info.version = (uint)(VERSION2 | (Marshal.SizeOf(typeof(NvGpuPerfPStates20InfoV2)))); var r = NvapiNativeMethods.NvGetPStateV2(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetPStateV2)} {r.ToString()}"); return(false); } return(true); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } }
private static bool NvSetPStateV2(int busId, ref NvGpuPerfPStates20InfoV2 info) { if (NvapiNativeMethods.NvSetPStateV2 == null) { return(false); } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } var r = NvapiNativeMethods.NvSetPStateV2(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvSetPStateV2)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { return(true); } } catch { } return(false); }
public void GetVersion(out Version driverVersion, out string nvmlVersion) { driverVersion = new Version(); nvmlVersion = "0.0"; if (!NvmlInit()) { return; } try { var r = NvmlNativeMethods.nvmlSystemGetDriverVersion(out string version); if (r != nvmlReturn.Success) { NTMinerConsole.DevError(() => $"{nameof(NvmlNativeMethods.nvmlSystemGetDriverVersion)} {r.ToString()}"); } r = NvmlNativeMethods.nvmlSystemGetNVMLVersion(out nvmlVersion); if (r != nvmlReturn.Success) { NTMinerConsole.DevError(() => $"{nameof(NvmlNativeMethods.nvmlSystemGetNVMLVersion)} {r.ToString()}"); } if (!string.IsNullOrEmpty(version) && Version.TryParse(version, out Version v)) { driverVersion = v; } if (string.IsNullOrEmpty(nvmlVersion)) { nvmlVersion = "0.0"; } } catch { } }
private void SetMemoryClock(int busId, int mHz, int voltage) { int kHz = mHz * 1000; try { if (NvGetPStateV2(busId, out NvGpuPerfPStates20InfoV2 info)) { info.numPStates = 1; info.numClocks = 1; info.numBaseVoltages = 0; info.pstates[0].clocks[0].domainId = NvGpuPublicClockId.NVAPI_GPU_PUBLIC_CLOCK_MEMORY; info.pstates[0].clocks[0].typeId = NvGpuPerfPState20ClockTypeId.NVAPI_GPU_PERF_PSTATE20_CLOCK_TYPE_SINGLE; info.pstates[0].clocks[0].freqDelta_kHz.value = kHz; var r = NvSetPStateV2(busId, ref info); if (!r) { NTMinerConsole.DevError(() => $"{nameof(SetMemoryClock)} {r.ToString()}"); } } } catch { } }
public uint GetPowerUsage(int gpuIndex) { if (!NvmlInit() || !TryGetNvmlDevice(gpuIndex, out nvmlDevice nvmlDevice)) { return(0); } if (_nvmlDeviceGetPowerUsageNotSupporteds.Contains(gpuIndex)) { return(0); } uint power = 0; try { var r = NvmlNativeMethods.nvmlDeviceGetPowerUsage(nvmlDevice, ref power); power = (uint)(power / 1000.0); if (r != nvmlReturn.Success) { if (r == nvmlReturn.NotSupported) { _nvmlDeviceGetPowerUsageNotSupporteds.Add(gpuIndex); } NTMinerConsole.DevError(() => $"{nameof(NvmlNativeMethods.nvmlDeviceGetPowerUsage)} {r.ToString()}"); } } catch { } return(power); }
public OverClockRange GetClockRange(int gpuIndex) { OverClockRange result = new OverClockRange(gpuIndex); try { if (!TryGpuAdapterIndex(gpuIndex, out int adapterIndex)) { return(result); } ADLODNCapabilitiesX2 info = new ADLODNCapabilitiesX2(); var r = AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get(context, adapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_CapabilitiesX2_Get)} {r.ToString()}"); return(result); } result.PowerCurr = GetPowerLimit(gpuIndex); result.TempCurr = GetTempLimit(gpuIndex); if (GetMemoryClock(gpuIndex, out int memoryClock, out int iVddc)) { result.MemoryClockDelta = memoryClock; result.MemoryVoltage = iVddc; } if (GetCoreClock(gpuIndex, out int coreClock, out iVddc)) { result.CoreClockDelta = coreClock; result.CoreVoltage = iVddc; } result.CoreClockMin = info.sEngineClockRange.iMin * 10; result.CoreClockMax = info.sEngineClockRange.iMax * 10; result.MemoryClockMin = info.sMemoryClockRange.iMin * 10; result.MemoryClockMax = info.sMemoryClockRange.iMax * 10; result.PowerMin = info.power.iMin + 100; result.PowerMax = info.power.iMax + 100; result.PowerDefault = info.power.iDefault + 100; result.TempLimitMin = info.powerTuneTemperature.iMin; result.TempLimitMax = info.powerTuneTemperature.iMax; result.TempLimitDefault = info.powerTuneTemperature.iDefault; result.VoltMin = info.svddcRange.iMin; result.VoltMax = info.svddcRange.iMax; result.VoltDefault = info.svddcRange.iDefault; if (info.fanSpeed.iMax == 0) { result.FanSpeedMin = 0; } else { result.FanSpeedMin = info.fanSpeed.iMin * 100 / info.fanSpeed.iMax; } result.FanSpeedMax = 100; #if DEBUG NTMinerConsole.DevWarn(() => $"GetClockRange {result.ToString()}"); #endif } catch (Exception e) { Logger.ErrorDebugLine(e); } return(result); }
private bool SetCooler(int busId, uint value, bool isAutoMode) { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return(false); } #region GTX if (NvapiNativeMethods.NvSetCoolerLevels != null) { try { NvCoolerTarget coolerIndex = NvCoolerTarget.NVAPI_COOLER_TARGET_ALL; NvCoolerLevel info = NvCoolerLevel.Create(); info.coolers[0].currentLevel = isAutoMode ? 0 : value; info.coolers[0].currentPolicy = isAutoMode ? NvCoolerPolicy.NVAPI_COOLER_POLICY_AUTO : NvCoolerPolicy.NVAPI_COOLER_POLICY_MANUAL; var r = NvapiNativeMethods.NvSetCoolerLevels(handle, coolerIndex, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvSetCoolerLevels)} {r.ToString()}"); } else { return(true); } } catch { } } #endregion #region RTX if (NvapiNativeMethods.NvFanCoolersSetControl == null) { return(false); } try { if (NvFanCoolersGetControl(busId, out PrivateFanCoolersControlV1 info)) { for (int i = 0; i < info.FanCoolersControlCount; i++) { info.FanCoolersControlEntries[i].ControlMode = isAutoMode ? FanCoolersControlMode.Auto : FanCoolersControlMode.Manual; info.FanCoolersControlEntries[i].Level = isAutoMode ? 0u : (uint)value; } var r = NvapiNativeMethods.NvFanCoolersSetControl(handle, ref info); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvFanCoolersSetControl)} {r.ToString()}"); return(false); } return(true); } return(false); } catch (Exception e) { Logger.ErrorDebugLine(e); return(false); } #endregion }
internal static AdlStatus ADLMainControlCreate(out IntPtr context) { context = IntPtr.Zero; string path1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "atiadlxx.dll"); string path2 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "atiadlxy.dll"); string path3 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "atiadlxx.dll"); string path4 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86), "atiadlxy.dll"); if (!File.Exists(path1) && !File.Exists(path2) && !File.Exists(path3) && !File.Exists(path4)) { return(AdlStatus.ADL_ERR); } AdlStatus r = AdlStatus.ADL_ERR; string dllName = "atiadlxx.dll"; try { CreateDelegates(dllName); if (ADL_Main_Control_Create != null) { r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1); } else { return(AdlStatus.ADL_ERR); } } catch (Exception e) { Logger.ErrorDebugLine(e); try { dllName = "atiadlxy.dll"; CreateDelegates(dllName); if (ADL_Main_Control_Create != null) { r = ADL_Main_Control_Create(Marshal.AllocHGlobal, 1); } else { return(AdlStatus.ADL_ERR); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); r = AdlStatus.ADL_ERR; } } if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(ADL_Main_Control_Create)} {r.ToString()} {dllName}"); } ADL2MainControlCreate(out context); return(r); }
public void GetClockAndVolt(int gpuIndex, out int memoryClock, out int memoryiVddc, out int coreClock, out int coreiVddc) { memoryClock = 0; memoryiVddc = 0; coreClock = 0; coreiVddc = 0; try { if (!TryGetAtiGpu(gpuIndex, out ATIGPU gpu)) { return; } if (gpu.OverdriveVersion < 8) { try { ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create(); var r = AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get(_context, gpu.AdapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_SystemClocksX2_Get)} {r.ToString()}"); } var index = gpu.GpuLevels - 1; coreClock = info.aLevels[index].iClock * 10; coreiVddc = info.aLevels[index].iVddc; } catch { } try { ADLODNPerformanceLevelsX2 info = ADLODNPerformanceLevelsX2.Create(); var r = AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get(_context, gpu.AdapterIndex, ref info); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_OverdriveN_MemoryClocksX2_Get)} {r.ToString()}"); } int index = gpu.MemoryLevels - 1; memoryClock = info.aLevels[index].iClock * 10; memoryiVddc = info.aLevels[index].iVddc; } catch { } } else if (GetOD8CurrentSetting(gpu.AdapterIndex, out ADLOD8CurrentSetting odCurrentSetting)) { coreClock = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_FMAX] * 1000; coreiVddc = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_GFXCLK_VOLTAGE3]; memoryClock = odCurrentSetting.Od8SettingTable[(int)ADLOD8SettingId.OD8_UCLK_FMAX] * 1000; } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
private static void ADL2MainControlCreate(out IntPtr context) { try { var r = ADL2_Main_Control_Create(Marshal.AllocHGlobal, 1, out context); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(ADL2_Main_Control_Create)} {r.ToString()}"); } } catch (Exception ex) { Logger.ErrorDebugLine(ex); context = IntPtr.Zero; } }
private bool GetOD8CurrentSetting(int adapterIndex, out ADLOD8CurrentSetting odCurrentSetting) { odCurrentSetting = ADLOD8CurrentSetting.Create(); try { var r = AdlNativeMethods.ADL2_Overdrive8_Current_Setting_Get(_context, adapterIndex, ref odCurrentSetting); if (r < AdlStatus.ADL_OK) { NTMinerConsole.DevError(() => $"{nameof(AdlNativeMethods.ADL2_Overdrive8_Current_Setting_Get)} {r.ToString()}"); } return(r == AdlStatus.ADL_OK); } catch (Exception ex) { Logger.ErrorDebugLine(ex); return(false); } }
private static void SetVoltage(int busId, int voltage) { voltage *= 1000; if (NvapiNativeMethods.NvSetClockBoostLock == null) { return; } try { if (!HandlesByBusId.TryGetValue(busId, out NvPhysicalGpuHandle handle)) { return; } NvGpuClockLock clockLock = NvGpuClockLock.Create(); var r = NvapiNativeMethods.NvGetClockBoostLock(HandlesByBusId[busId], ref clockLock); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvGetClockBoostLock)} {r.ToString()}"); } if (r == NvStatus.NVAPI_OK) { uint index = clockLock.Enties[0].index; foreach (var item in clockLock.Enties) { if (item.index > index) { index = item.index; } } if (voltage != 0) { clockLock.Enties[index].mode = 3; } else { clockLock.Enties[index].mode = 0; } clockLock.Enties[index].voltageUV = (uint)voltage; r = NvapiNativeMethods.NvSetClockBoostLock(handle, ref clockLock); if (r != NvStatus.NVAPI_OK) { NTMinerConsole.DevError(() => $"{nameof(NvapiNativeMethods.NvSetClockBoostLock)} {r.ToString()}"); } } } catch { } }