Move hwmon specific functions into their own source file

pull/488/head
jsteube 8 years ago
parent 5dd5c15966
commit d15ae38723

@ -0,0 +1,54 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#pragma once
typedef struct
{
HM_ADAPTER_ADL adl;
HM_ADAPTER_NVML nvml;
HM_ADAPTER_NVAPI nvapi;
HM_ADAPTER_XNVCTRL xnvctrl;
int od_version;
int fan_get_supported;
int fan_set_supported;
} hm_attrs_t;
int get_adapters_num_adl (void *adl, int *iNumberAdapters);
int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_get_adapter_index_nvapi (HM_ADAPTER_NVAPI nvapiGPUHandle[DEVICES_MAX]);
int hm_get_adapter_index_nvml (HM_ADAPTER_NVML nvmlGPUHandle[DEVICES_MAX]);
LPAdapterInfo hm_get_adapter_info_adl (void *adl, int iNumberAdapters);
u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_get_overdrive_version (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_check_fanspeed_control (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
// int hm_get_device_num (void *adl, HM_ADAPTER_ADL hm_adapter_index, int *hm_device_num);
// void hm_get_opencl_busid_devid (hm_attrs_t *hm_device, uint opencl_num_devices, cl_device_id *devices);
int hm_get_threshold_slowdown_with_device_id (const uint device_id);
int hm_get_threshold_shutdown_with_device_id (const uint device_id);
int hm_get_temperature_with_device_id (const uint device_id);
int hm_get_fanspeed_with_device_id (const uint device_id);
int hm_get_fanpolicy_with_device_id (const uint device_id);
int hm_get_buslanes_with_device_id (const uint device_id);
int hm_get_utilization_with_device_id (const uint device_id);
int hm_get_memoryspeed_with_device_id (const uint device_id);
int hm_get_corespeed_with_device_id (const uint device_id);
int hm_get_throttle_with_device_id (const uint device_id);
int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed, const int fanpolicy);
int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspeed, const int fanpolicy);
int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fanspeed);
void hm_device_val_to_str (char *target_buf, int max_buf_size, char *suffix, int value);

@ -214,43 +214,6 @@ void unlock_file (FILE *fp);
void fsync (int fd);
#endif
#ifdef HAVE_HWMON
int get_adapters_num_adl (void *adl, int *iNumberAdapters);
int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_get_adapter_index_nvapi (HM_ADAPTER_NVAPI nvapiGPUHandle[DEVICES_MAX]);
int hm_get_adapter_index_nvml (HM_ADAPTER_NVML nvmlGPUHandle[DEVICES_MAX]);
LPAdapterInfo hm_get_adapter_info_adl (void *adl, int iNumberAdapters);
u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_get_overdrive_version (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
int hm_check_fanspeed_control (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo);
// int hm_get_device_num (void *adl, HM_ADAPTER_ADL hm_adapter_index, int *hm_device_num);
// void hm_get_opencl_busid_devid (hm_attrs_t *hm_device, uint opencl_num_devices, cl_device_id *devices);
int hm_get_threshold_slowdown_with_device_id (const uint device_id);
int hm_get_threshold_shutdown_with_device_id (const uint device_id);
int hm_get_temperature_with_device_id (const uint device_id);
int hm_get_fanspeed_with_device_id (const uint device_id);
int hm_get_fanpolicy_with_device_id (const uint device_id);
int hm_get_buslanes_with_device_id (const uint device_id);
int hm_get_utilization_with_device_id (const uint device_id);
int hm_get_memoryspeed_with_device_id (const uint device_id);
int hm_get_corespeed_with_device_id (const uint device_id);
int hm_get_throttle_with_device_id (const uint device_id);
int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed, const int fanpolicy);
int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspeed, const int fanpolicy);
int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fanspeed);
void hm_device_val_to_str (char *target_buf, int max_buf_size, char *suffix, int value);
#endif // HAVE_HWMON
void myabort (void);
void myquit (void);

@ -572,19 +572,3 @@ struct __hc_device_param
};
typedef struct __hc_device_param hc_device_param_t;
#ifdef HAVE_HWMON
typedef struct
{
HM_ADAPTER_ADL adl;
HM_ADAPTER_NVML nvml;
HM_ADAPTER_NVAPI nvapi;
HM_ADAPTER_XNVCTRL xnvctrl;
int od_version;
int fan_get_supported;
int fan_set_supported;
} hm_attrs_t;
#endif // HAVE_HWMON

@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi
## Objects
##
NATIVE_OBJS := obj/terminal.NATIVE.o obj/logfile.NATIVE.o obj/data.NATIVE.o obj/convert.NATIVE.o obj/memory.NATIVE.o obj/logging.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/bitops.NATIVE.o obj/bitops.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/interface.NATIVE.o
NATIVE_OBJS := obj/hwmon.NATIVE.o obj/terminal.NATIVE.o obj/logfile.NATIVE.o obj/data.NATIVE.o obj/convert.NATIVE.o obj/memory.NATIVE.o obj/logging.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/bitops.NATIVE.o obj/bitops.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/interface.NATIVE.o
ifeq ($(UNAME),Linux)
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
endif
LINUX_32_OBJS := obj/terminal.LINUX.32.o obj/logfile.LINUX.32.o obj/data.LINUX.32.o obj/convert.LINUX.32.o obj/memory.LINUX.32.o obj/logging.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/bitops.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/interface.LINUX.32.o
LINUX_64_OBJS := obj/terminal.LINUX.64.o obj/logfile.LINUX.64.o obj/data.LINUX.64.o obj/convert.LINUX.64.o obj/memory.LINUX.64.o obj/logging.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/bitops.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/interface.LINUX.64.o
LINUX_32_OBJS := obj/hwmon.LINUX.32.o obj/terminal.LINUX.32.o obj/logfile.LINUX.32.o obj/data.LINUX.32.o obj/convert.LINUX.32.o obj/memory.LINUX.32.o obj/logging.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/bitops.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/interface.LINUX.32.o
LINUX_64_OBJS := obj/hwmon.LINUX.64.o obj/terminal.LINUX.64.o obj/logfile.LINUX.64.o obj/data.LINUX.64.o obj/convert.LINUX.64.o obj/memory.LINUX.64.o obj/logging.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/bitops.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/interface.LINUX.64.o
# Windows CRT file globbing:
@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
WIN_32_OBJS := obj/terminal.WIN.32.o obj/logfile.WIN.32.o obj/data.WIN.32.o obj/convert.WIN.32.o obj/memory.WIN.32.o obj/logging.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/bitops.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/interface.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/terminal.WIN.64.o obj/logfile.WIN.64.o obj/data.WIN.64.o obj/convert.WIN.64.o obj/memory.WIN.64.o obj/logging.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/bitops.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/interface.WIN.64.o $(CRT_GLOB_64)
WIN_32_OBJS := obj/hwmon.WIN.32.o obj/terminal.WIN.32.o obj/logfile.WIN.32.o obj/data.WIN.32.o obj/convert.WIN.32.o obj/memory.WIN.32.o obj/logging.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/bitops.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/interface.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/hwmon.WIN.64.o obj/terminal.WIN.64.o obj/logfile.WIN.64.o obj/data.WIN.64.o obj/convert.WIN.64.o obj/memory.WIN.64.o obj/logging.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/bitops.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/interface.WIN.64.o $(CRT_GLOB_64)
##
## Targets: Global

@ -12,6 +12,7 @@
#include "ext_xnvctrl.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "data.h"
hc_global_data_t data;

@ -32,6 +32,7 @@
#include "inc_hash_constants.h"
#include "interface.h"
#include "shared.h"
#include "hwmon.h"
#include "data.h"
#include <search.h>

@ -0,0 +1,858 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#include "common.h"
#include "types_int.h"
#include "memory.h"
#include "logging.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "data.h"
extern hc_global_data_t data;
int get_adapters_num_adl (void *adl, int *iNumberAdapters)
{
if (hm_ADL_Adapter_NumberOfAdapters_Get ((ADL_PTR *) adl, iNumberAdapters) != ADL_OK) return -1;
if (iNumberAdapters == 0)
{
log_info ("WARN: No ADL adapters found.");
return -1;
}
return 0;
}
/*
int hm_show_performance_level (HM_LIB hm_dll, int iAdapterIndex)
{
ADLODPerformanceLevels *lpOdPerformanceLevels = NULL;
ADLODParameters lpOdParameters;
lpOdParameters.iSize = sizeof (ADLODParameters);
size_t plevels_size = 0;
if (hm_ADL_Overdrive_ODParameters_Get (hm_dll, iAdapterIndex, &lpOdParameters) != ADL_OK) return -1;
log_info ("[DEBUG] %s, adapter %d performance level (%d) : %s %s",
__func__, iAdapterIndex,
lpOdParameters.iNumberOfPerformanceLevels,
(lpOdParameters.iActivityReportingSupported) ? "activity reporting" : "",
(lpOdParameters.iDiscretePerformanceLevels) ? "discrete performance levels" : "performance ranges");
plevels_size = sizeof (ADLODPerformanceLevels) + sizeof (ADLODPerformanceLevel) * (lpOdParameters.iNumberOfPerformanceLevels - 1);
lpOdPerformanceLevels = (ADLODPerformanceLevels *) mymalloc (plevels_size);
lpOdPerformanceLevels->iSize = sizeof (ADLODPerformanceLevels) + sizeof (ADLODPerformanceLevel) * (lpOdParameters.iNumberOfPerformanceLevels - 1);
if (hm_ADL_Overdrive_ODPerformanceLevels_Get (hm_dll, iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK) return -1;
for (int j = 0; j < lpOdParameters.iNumberOfPerformanceLevels; j++)
log_info ("[DEBUG] %s, adapter %d, level %d : engine %d, memory %d, voltage: %d",
__func__, iAdapterIndex, j,
lpOdPerformanceLevels->aLevels[j].iEngineClock / 100, lpOdPerformanceLevels->aLevels[j].iMemoryClock / 100, lpOdPerformanceLevels->aLevels[j].iVddc);
myfree (lpOdPerformanceLevels);
return 0;
}
*/
LPAdapterInfo hm_get_adapter_info_adl (void *adl, int iNumberAdapters)
{
size_t AdapterInfoSize = iNumberAdapters * sizeof (AdapterInfo);
LPAdapterInfo lpAdapterInfo = (LPAdapterInfo) mymalloc (AdapterInfoSize);
if (hm_ADL_Adapter_AdapterInfo_Get ((ADL_PTR *) adl, lpAdapterInfo, AdapterInfoSize) != ADL_OK) return NULL;
return lpAdapterInfo;
}
int hm_get_adapter_index_nvapi (HM_ADAPTER_NVAPI nvapiGPUHandle[DEVICES_MAX])
{
NvU32 pGpuCount;
if (hm_NvAPI_EnumPhysicalGPUs (data.hm_nvapi, nvapiGPUHandle, &pGpuCount) != NVAPI_OK) return 0;
if (pGpuCount == 0)
{
log_info ("WARN: No NvAPI adapters found");
return 0;
}
return (pGpuCount);
}
int hm_get_adapter_index_nvml (HM_ADAPTER_NVML nvmlGPUHandle[DEVICES_MAX])
{
int pGpuCount = 0;
for (uint i = 0; i < DEVICES_MAX; i++)
{
if (hm_NVML_nvmlDeviceGetHandleByIndex (data.hm_nvml, 1, i, &nvmlGPUHandle[i]) != NVML_SUCCESS) break;
// can be used to determine if the device by index matches the cuda device by index
// char name[100]; memset (name, 0, sizeof (name));
// hm_NVML_nvmlDeviceGetName (data.hm_nvml, nvGPUHandle[i], name, sizeof (name) - 1);
pGpuCount++;
}
if (pGpuCount == 0)
{
log_info ("WARN: No NVML adapters found");
return 0;
}
return (pGpuCount);
}
/*
//
// does not help at all, since ADL does not assign different bus id, device id when we have multi GPU setups
//
int hm_get_opencl_device_index (hm_attrs_t *hm_device, uint num_adl_adapters, int bus_num, int dev_num)
{
u32 idx = -1;
for (uint i = 0; i < num_adl_adapters; i++)
{
int opencl_bus_num = hm_device[i].busid;
int opencl_dev_num = hm_device[i].devid;
if ((opencl_bus_num == bus_num) && (opencl_dev_num == dev_num))
{
idx = i;
break;
}
}
if (idx >= DEVICES_MAX) return -1;
return idx;
}
void hm_get_opencl_busid_devid (hm_attrs_t *hm_device, uint opencl_num_devices, cl_device_id *devices)
{
for (uint i = 0; i < opencl_num_devices; i++)
{
cl_device_topology_amd device_topology;
hc_clGetDeviceInfo (devices[i], CL_DEVICE_TOPOLOGY_AMD, sizeof (device_topology), &device_topology, NULL);
hm_device[i].busid = device_topology.pcie.bus;
hm_device[i].devid = device_topology.pcie.device;
}
}
*/
static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
// basically bubble sort
for (int i = 0; i < num_adl_adapters; i++)
{
for (int j = 0; j < num_adl_adapters - 1; j++)
{
// get info of adapter [x]
u32 adapter_index_x = valid_adl_device_list[j];
AdapterInfo info_x = lpAdapterInfo[adapter_index_x];
u32 bus_num_x = info_x.iBusNumber;
u32 dev_num_x = info_x.iDeviceNumber;
// get info of adapter [y]
u32 adapter_index_y = valid_adl_device_list[j + 1];
AdapterInfo info_y = lpAdapterInfo[adapter_index_y];
u32 bus_num_y = info_y.iBusNumber;
u32 dev_num_y = info_y.iDeviceNumber;
uint need_swap = 0;
if (bus_num_y < bus_num_x)
{
need_swap = 1;
}
else if (bus_num_y == bus_num_x)
{
if (dev_num_y < dev_num_x)
{
need_swap = 1;
}
}
if (need_swap == 1)
{
u32 temp = valid_adl_device_list[j + 1];
valid_adl_device_list[j + 1] = valid_adl_device_list[j];
valid_adl_device_list[j + 0] = temp;
}
}
}
}
u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
*num_adl_adapters = 0;
u32 *adl_adapters = NULL;
int *bus_numbers = NULL;
int *device_numbers = NULL;
for (int i = 0; i < iNumberAdapters; i++)
{
AdapterInfo info = lpAdapterInfo[i];
if (strlen (info.strUDID) < 1) continue;
#ifdef WIN
if (info.iVendorID != 1002) continue;
#else
if (info.iVendorID != 0x1002) continue;
#endif
if (info.iBusNumber < 0) continue;
if (info.iDeviceNumber < 0) continue;
int found = 0;
for (int pos = 0; pos < *num_adl_adapters; pos++)
{
if ((bus_numbers[pos] == info.iBusNumber) && (device_numbers[pos] == info.iDeviceNumber))
{
found = 1;
break;
}
}
if (found) continue;
// add it to the list
adl_adapters = (u32 *) myrealloc (adl_adapters, (*num_adl_adapters) * sizeof (int), sizeof (int));
adl_adapters[*num_adl_adapters] = i;
// rest is just bookkeeping
bus_numbers = (int*) myrealloc (bus_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int));
device_numbers = (int*) myrealloc (device_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int));
bus_numbers[*num_adl_adapters] = info.iBusNumber;
device_numbers[*num_adl_adapters] = info.iDeviceNumber;
(*num_adl_adapters)++;
}
myfree (bus_numbers);
myfree (device_numbers);
// sort the list by increasing bus id, device id number
hm_sort_adl_adapters_by_busid_devid (adl_adapters, *num_adl_adapters, lpAdapterInfo);
return adl_adapters;
}
int hm_check_fanspeed_control (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
// loop through all valid devices
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
// if (hm_show_performance_level (adl, info.iAdapterIndex) != 0) return -1;
// get fanspeed info
if (hm_device[opencl_device_index].od_version == 5)
{
ADLFanSpeedInfo FanSpeedInfo;
memset (&FanSpeedInfo, 0, sizeof (ADLFanSpeedInfo));
FanSpeedInfo.iSize = sizeof (ADLFanSpeedInfo);
if (hm_ADL_Overdrive5_FanSpeedInfo_Get (adl, info.iAdapterIndex, 0, &FanSpeedInfo) != ADL_OK) return -1;
// check read and write capability in fanspeedinfo
if ((FanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_READ) &&
(FanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE))
{
hm_device[opencl_device_index].fan_get_supported = 1;
}
else
{
hm_device[opencl_device_index].fan_get_supported = 0;
}
}
else // od_version == 6
{
ADLOD6FanSpeedInfo faninfo;
memset (&faninfo, 0, sizeof (faninfo));
if (hm_ADL_Overdrive6_FanSpeed_Get (adl, info.iAdapterIndex, &faninfo) != ADL_OK) return -1;
// check read capability in fanspeedinfo
if (faninfo.iSpeedType & ADL_OD6_FANSPEED_TYPE_PERCENT)
{
hm_device[opencl_device_index].fan_get_supported = 1;
}
else
{
hm_device[opencl_device_index].fan_get_supported = 0;
}
}
}
return 0;
}
int hm_get_overdrive_version (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// get overdrive version
int od_supported = 0;
int od_enabled = 0;
int od_version = 0;
if (hm_ADL_Overdrive_Caps (adl, info.iAdapterIndex, &od_supported, &od_enabled, &od_version) != ADL_OK) return -1;
// store the overdrive version in hm_device
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
hm_device[opencl_device_index].od_version = od_version;
}
return 0;
}
int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// store the iAdapterIndex in hm_device
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
hm_device[opencl_device_index].adl = info.iAdapterIndex;
}
return num_adl_adapters;
}
int hm_get_threshold_slowdown_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
}
else if (data.hm_device[device_id].od_version == 6)
{
int CurrentValue = 0;
int DefaultValue = 0;
if (hm_ADL_Overdrive6_TargetTemperatureData_Get (data.hm_adl, data.hm_device[device_id].adl, &CurrentValue, &DefaultValue) != ADL_OK) return -1;
// the return value has never been tested since hm_ADL_Overdrive6_TargetTemperatureData_Get() never worked on any system. expect problems.
return DefaultValue;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int target = 0;
if (hm_NVML_nvmlDeviceGetTemperatureThreshold (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1;
return target;
}
return -1;
}
int hm_get_threshold_shutdown_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
}
else if (data.hm_device[device_id].od_version == 6)
{
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int target = 0;
if (hm_NVML_nvmlDeviceGetTemperatureThreshold (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1;
return target;
}
return -1;
}
int hm_get_temperature_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLTemperature Temperature;
Temperature.iSize = sizeof (ADLTemperature);
if (hm_ADL_Overdrive5_Temperature_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &Temperature) != ADL_OK) return -1;
return Temperature.iTemperature / 1000;
}
else if (data.hm_device[device_id].od_version == 6)
{
int Temperature = 0;
if (hm_ADL_Overdrive6_Temperature_Get (data.hm_adl, data.hm_device[device_id].adl, &Temperature) != ADL_OK) return -1;
return Temperature / 1000;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int temperature = 0;
if (hm_NVML_nvmlDeviceGetTemperature (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_GPU, (uint *) &temperature) != NVML_SUCCESS) return -1;
return temperature;
}
return -1;
}
int hm_get_fanpolicy_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.hm_device[device_id].fan_get_supported == 1)
{
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
if (hm_ADL_Overdrive5_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return (lpFanSpeedValue.iFanSpeed & ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) ? 0 : 1;
}
else // od_version == 6
{
return 1;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
return 1;
}
}
return -1;
}
int hm_get_fanspeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.hm_device[device_id].fan_get_supported == 1)
{
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
if (hm_ADL_Overdrive5_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return lpFanSpeedValue.iFanSpeed;
}
else // od_version == 6
{
ADLOD6FanSpeedInfo faninfo;
memset (&faninfo, 0, sizeof (faninfo));
if (hm_ADL_Overdrive6_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, &faninfo) != ADL_OK) return -1;
return faninfo.iFanSpeedPercent;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int speed = 0;
if (hm_NVML_nvmlDeviceGetFanSpeed (data.hm_nvml, 0, data.hm_device[device_id].nvml, (uint *) &speed) != NVML_SUCCESS) return -1;
return speed;
}
}
return -1;
}
int hm_get_buslanes_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iCurrentBusLanes;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int currLinkWidth;
if (hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (data.hm_nvml, 1, data.hm_device[device_id].nvml, &currLinkWidth) != NVML_SUCCESS) return -1;
return currLinkWidth;
}
return -1;
}
int hm_get_utilization_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iActivityPercent;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
nvmlUtilization_t utilization;
if (hm_NVML_nvmlDeviceGetUtilizationRates (data.hm_nvml, 1, data.hm_device[device_id].nvml, &utilization) != NVML_SUCCESS) return -1;
return utilization.gpu;
}
return -1;
}
int hm_get_memoryspeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iMemoryClock / 100;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int clock;
if (hm_NVML_nvmlDeviceGetClockInfo (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_CLOCK_MEM, &clock) != NVML_SUCCESS) return -1;
return clock;
}
return -1;
}
int hm_get_corespeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iEngineClock / 100;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int clock;
if (hm_NVML_nvmlDeviceGetClockInfo (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_CLOCK_SM, &clock) != NVML_SUCCESS) return -1;
return clock;
}
return -1;
}
int hm_get_throttle_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned long long clocksThrottleReasons = 0;
unsigned long long supportedThrottleReasons = 0;
if (hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (data.hm_nvml, 1, data.hm_device[device_id].nvml, &clocksThrottleReasons) != NVML_SUCCESS) return -1;
if (hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (data.hm_nvml, 1, data.hm_device[device_id].nvml, &supportedThrottleReasons) != NVML_SUCCESS) return -1;
clocksThrottleReasons &= supportedThrottleReasons;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonGpuIdle;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonApplicationsClocksSetting;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonUnknown;
if (data.kernel_power_final)
{
clocksThrottleReasons &= ~nvmlClocksThrottleReasonHwSlowdown;
}
return (clocksThrottleReasons != nvmlClocksThrottleReasonNone);
}
return -1;
}
int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed, const int fanpolicy)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_adl)
{
if (fanpolicy == 1)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
lpFanSpeedValue.iFanSpeed = fanspeed;
if (hm_ADL_Overdrive5_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return 0;
}
else // od_version == 6
{
ADLOD6FanSpeedValue fan_speed_value;
memset (&fan_speed_value, 0, sizeof (fan_speed_value));
fan_speed_value.iSpeedType = ADL_OD6_FANSPEED_TYPE_PERCENT;
fan_speed_value.iFanSpeed = fanspeed;
if (hm_ADL_Overdrive6_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, &fan_speed_value) != ADL_OK) return -1;
return 0;
}
}
else
{
if (data.hm_device[device_id].od_version == 5)
{
if (hm_ADL_Overdrive5_FanSpeedToDefault_Set (data.hm_adl, data.hm_device[device_id].adl, 0) != ADL_OK) return -1;
return 0;
}
else // od_version == 6
{
if (hm_ADL_Overdrive6_FanSpeed_Reset (data.hm_adl, data.hm_device[device_id].adl) != ADL_OK) return -1;
return 0;
}
}
}
}
return -1;
}
int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspeed, const int fanpolicy)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_nvapi)
{
if (fanpolicy == 1)
{
NV_GPU_COOLER_LEVELS CoolerLevels;
memset (&CoolerLevels, 0, sizeof (NV_GPU_COOLER_LEVELS));
CoolerLevels.Version = GPU_COOLER_LEVELS_VER | sizeof (NV_GPU_COOLER_LEVELS);
CoolerLevels.Levels[0].Level = fanspeed;
CoolerLevels.Levels[0].Policy = 1;
if (hm_NvAPI_GPU_SetCoolerLevels (data.hm_nvapi, data.hm_device[device_id].nvapi, 0, &CoolerLevels) != NVAPI_OK) return -1;
return 0;
}
else
{
if (hm_NvAPI_GPU_RestoreCoolerSettings (data.hm_nvapi, data.hm_device[device_id].nvapi, 0) != NVAPI_OK) return -1;
return 0;
}
}
}
return -1;
}
int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fanspeed)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_xnvctrl)
{
if (set_fan_speed_target (data.hm_xnvctrl, data.hm_device[device_id].xnvctrl, fanspeed) != 0) return -1;
return 0;
}
}
return -1;
}

@ -24,6 +24,7 @@
#include "inc_hash_constants.h"
#include "timer.h"
#include "types.h"
#include "hwmon.h"
#include "data.h"
#include "interface.h"

@ -13,6 +13,7 @@
#include "timer.h"
#include "types.h"
#include "memory.h"
#include "hwmon.h"
#include "data.h"
#include "logfile.h"

@ -21,6 +21,7 @@
#include "types.h"
#include "rp_cpu.h"
#include "terminal.h"
#include "hwmon.h"
#include "data.h"
#include "shared.h"
@ -69,852 +70,6 @@ void fsync (int fd)
}
#endif
/**
* thermal
*/
#ifdef HAVE_HWMON
int get_adapters_num_adl (void *adl, int *iNumberAdapters)
{
if (hm_ADL_Adapter_NumberOfAdapters_Get ((ADL_PTR *) adl, iNumberAdapters) != ADL_OK) return -1;
if (iNumberAdapters == 0)
{
log_info ("WARN: No ADL adapters found.");
return -1;
}
return 0;
}
/*
int hm_show_performance_level (HM_LIB hm_dll, int iAdapterIndex)
{
ADLODPerformanceLevels *lpOdPerformanceLevels = NULL;
ADLODParameters lpOdParameters;
lpOdParameters.iSize = sizeof (ADLODParameters);
size_t plevels_size = 0;
if (hm_ADL_Overdrive_ODParameters_Get (hm_dll, iAdapterIndex, &lpOdParameters) != ADL_OK) return -1;
log_info ("[DEBUG] %s, adapter %d performance level (%d) : %s %s",
__func__, iAdapterIndex,
lpOdParameters.iNumberOfPerformanceLevels,
(lpOdParameters.iActivityReportingSupported) ? "activity reporting" : "",
(lpOdParameters.iDiscretePerformanceLevels) ? "discrete performance levels" : "performance ranges");
plevels_size = sizeof (ADLODPerformanceLevels) + sizeof (ADLODPerformanceLevel) * (lpOdParameters.iNumberOfPerformanceLevels - 1);
lpOdPerformanceLevels = (ADLODPerformanceLevels *) mymalloc (plevels_size);
lpOdPerformanceLevels->iSize = sizeof (ADLODPerformanceLevels) + sizeof (ADLODPerformanceLevel) * (lpOdParameters.iNumberOfPerformanceLevels - 1);
if (hm_ADL_Overdrive_ODPerformanceLevels_Get (hm_dll, iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK) return -1;
for (int j = 0; j < lpOdParameters.iNumberOfPerformanceLevels; j++)
log_info ("[DEBUG] %s, adapter %d, level %d : engine %d, memory %d, voltage: %d",
__func__, iAdapterIndex, j,
lpOdPerformanceLevels->aLevels[j].iEngineClock / 100, lpOdPerformanceLevels->aLevels[j].iMemoryClock / 100, lpOdPerformanceLevels->aLevels[j].iVddc);
myfree (lpOdPerformanceLevels);
return 0;
}
*/
LPAdapterInfo hm_get_adapter_info_adl (void *adl, int iNumberAdapters)
{
size_t AdapterInfoSize = iNumberAdapters * sizeof (AdapterInfo);
LPAdapterInfo lpAdapterInfo = (LPAdapterInfo) mymalloc (AdapterInfoSize);
if (hm_ADL_Adapter_AdapterInfo_Get ((ADL_PTR *) adl, lpAdapterInfo, AdapterInfoSize) != ADL_OK) return NULL;
return lpAdapterInfo;
}
int hm_get_adapter_index_nvapi (HM_ADAPTER_NVAPI nvapiGPUHandle[DEVICES_MAX])
{
NvU32 pGpuCount;
if (hm_NvAPI_EnumPhysicalGPUs (data.hm_nvapi, nvapiGPUHandle, &pGpuCount) != NVAPI_OK) return 0;
if (pGpuCount == 0)
{
log_info ("WARN: No NvAPI adapters found");
return 0;
}
return (pGpuCount);
}
int hm_get_adapter_index_nvml (HM_ADAPTER_NVML nvmlGPUHandle[DEVICES_MAX])
{
int pGpuCount = 0;
for (uint i = 0; i < DEVICES_MAX; i++)
{
if (hm_NVML_nvmlDeviceGetHandleByIndex (data.hm_nvml, 1, i, &nvmlGPUHandle[i]) != NVML_SUCCESS) break;
// can be used to determine if the device by index matches the cuda device by index
// char name[100]; memset (name, 0, sizeof (name));
// hm_NVML_nvmlDeviceGetName (data.hm_nvml, nvGPUHandle[i], name, sizeof (name) - 1);
pGpuCount++;
}
if (pGpuCount == 0)
{
log_info ("WARN: No NVML adapters found");
return 0;
}
return (pGpuCount);
}
/*
//
// does not help at all, since ADL does not assign different bus id, device id when we have multi GPU setups
//
int hm_get_opencl_device_index (hm_attrs_t *hm_device, uint num_adl_adapters, int bus_num, int dev_num)
{
u32 idx = -1;
for (uint i = 0; i < num_adl_adapters; i++)
{
int opencl_bus_num = hm_device[i].busid;
int opencl_dev_num = hm_device[i].devid;
if ((opencl_bus_num == bus_num) && (opencl_dev_num == dev_num))
{
idx = i;
break;
}
}
if (idx >= DEVICES_MAX) return -1;
return idx;
}
void hm_get_opencl_busid_devid (hm_attrs_t *hm_device, uint opencl_num_devices, cl_device_id *devices)
{
for (uint i = 0; i < opencl_num_devices; i++)
{
cl_device_topology_amd device_topology;
hc_clGetDeviceInfo (devices[i], CL_DEVICE_TOPOLOGY_AMD, sizeof (device_topology), &device_topology, NULL);
hm_device[i].busid = device_topology.pcie.bus;
hm_device[i].devid = device_topology.pcie.device;
}
}
*/
static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
// basically bubble sort
for (int i = 0; i < num_adl_adapters; i++)
{
for (int j = 0; j < num_adl_adapters - 1; j++)
{
// get info of adapter [x]
u32 adapter_index_x = valid_adl_device_list[j];
AdapterInfo info_x = lpAdapterInfo[adapter_index_x];
u32 bus_num_x = info_x.iBusNumber;
u32 dev_num_x = info_x.iDeviceNumber;
// get info of adapter [y]
u32 adapter_index_y = valid_adl_device_list[j + 1];
AdapterInfo info_y = lpAdapterInfo[adapter_index_y];
u32 bus_num_y = info_y.iBusNumber;
u32 dev_num_y = info_y.iDeviceNumber;
uint need_swap = 0;
if (bus_num_y < bus_num_x)
{
need_swap = 1;
}
else if (bus_num_y == bus_num_x)
{
if (dev_num_y < dev_num_x)
{
need_swap = 1;
}
}
if (need_swap == 1)
{
u32 temp = valid_adl_device_list[j + 1];
valid_adl_device_list[j + 1] = valid_adl_device_list[j];
valid_adl_device_list[j + 0] = temp;
}
}
}
}
u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
*num_adl_adapters = 0;
u32 *adl_adapters = NULL;
int *bus_numbers = NULL;
int *device_numbers = NULL;
for (int i = 0; i < iNumberAdapters; i++)
{
AdapterInfo info = lpAdapterInfo[i];
if (strlen (info.strUDID) < 1) continue;
#ifdef WIN
if (info.iVendorID != 1002) continue;
#else
if (info.iVendorID != 0x1002) continue;
#endif
if (info.iBusNumber < 0) continue;
if (info.iDeviceNumber < 0) continue;
int found = 0;
for (int pos = 0; pos < *num_adl_adapters; pos++)
{
if ((bus_numbers[pos] == info.iBusNumber) && (device_numbers[pos] == info.iDeviceNumber))
{
found = 1;
break;
}
}
if (found) continue;
// add it to the list
adl_adapters = (u32 *) myrealloc (adl_adapters, (*num_adl_adapters) * sizeof (int), sizeof (int));
adl_adapters[*num_adl_adapters] = i;
// rest is just bookkeeping
bus_numbers = (int*) myrealloc (bus_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int));
device_numbers = (int*) myrealloc (device_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int));
bus_numbers[*num_adl_adapters] = info.iBusNumber;
device_numbers[*num_adl_adapters] = info.iDeviceNumber;
(*num_adl_adapters)++;
}
myfree (bus_numbers);
myfree (device_numbers);
// sort the list by increasing bus id, device id number
hm_sort_adl_adapters_by_busid_devid (adl_adapters, *num_adl_adapters, lpAdapterInfo);
return adl_adapters;
}
int hm_check_fanspeed_control (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
// loop through all valid devices
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
// if (hm_show_performance_level (adl, info.iAdapterIndex) != 0) return -1;
// get fanspeed info
if (hm_device[opencl_device_index].od_version == 5)
{
ADLFanSpeedInfo FanSpeedInfo;
memset (&FanSpeedInfo, 0, sizeof (ADLFanSpeedInfo));
FanSpeedInfo.iSize = sizeof (ADLFanSpeedInfo);
if (hm_ADL_Overdrive5_FanSpeedInfo_Get (adl, info.iAdapterIndex, 0, &FanSpeedInfo) != ADL_OK) return -1;
// check read and write capability in fanspeedinfo
if ((FanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_READ) &&
(FanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE))
{
hm_device[opencl_device_index].fan_get_supported = 1;
}
else
{
hm_device[opencl_device_index].fan_get_supported = 0;
}
}
else // od_version == 6
{
ADLOD6FanSpeedInfo faninfo;
memset (&faninfo, 0, sizeof (faninfo));
if (hm_ADL_Overdrive6_FanSpeed_Get (adl, info.iAdapterIndex, &faninfo) != ADL_OK) return -1;
// check read capability in fanspeedinfo
if (faninfo.iSpeedType & ADL_OD6_FANSPEED_TYPE_PERCENT)
{
hm_device[opencl_device_index].fan_get_supported = 1;
}
else
{
hm_device[opencl_device_index].fan_get_supported = 0;
}
}
}
return 0;
}
int hm_get_overdrive_version (void *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// get overdrive version
int od_supported = 0;
int od_enabled = 0;
int od_version = 0;
if (hm_ADL_Overdrive_Caps (adl, info.iAdapterIndex, &od_supported, &od_enabled, &od_version) != ADL_OK) return -1;
// store the overdrive version in hm_device
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
hm_device[opencl_device_index].od_version = od_version;
}
return 0;
}
int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo)
{
for (int i = 0; i < num_adl_adapters; i++)
{
u32 adapter_index = valid_adl_device_list[i];
// get AdapterInfo
AdapterInfo info = lpAdapterInfo[adapter_index];
// store the iAdapterIndex in hm_device
// unfortunately this doesn't work since bus id and dev id are not unique
// int opencl_device_index = hm_get_opencl_device_index (hm_device, num_adl_adapters, info.iBusNumber, info.iDeviceNumber);
// if (opencl_device_index == -1) continue;
int opencl_device_index = i;
hm_device[opencl_device_index].adl = info.iAdapterIndex;
}
return num_adl_adapters;
}
int hm_get_threshold_slowdown_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
}
else if (data.hm_device[device_id].od_version == 6)
{
int CurrentValue = 0;
int DefaultValue = 0;
if (hm_ADL_Overdrive6_TargetTemperatureData_Get (data.hm_adl, data.hm_device[device_id].adl, &CurrentValue, &DefaultValue) != ADL_OK) return -1;
// the return value has never been tested since hm_ADL_Overdrive6_TargetTemperatureData_Get() never worked on any system. expect problems.
return DefaultValue;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int target = 0;
if (hm_NVML_nvmlDeviceGetTemperatureThreshold (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1;
return target;
}
return -1;
}
int hm_get_threshold_shutdown_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
}
else if (data.hm_device[device_id].od_version == 6)
{
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int target = 0;
if (hm_NVML_nvmlDeviceGetTemperatureThreshold (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1;
return target;
}
return -1;
}
int hm_get_temperature_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLTemperature Temperature;
Temperature.iSize = sizeof (ADLTemperature);
if (hm_ADL_Overdrive5_Temperature_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &Temperature) != ADL_OK) return -1;
return Temperature.iTemperature / 1000;
}
else if (data.hm_device[device_id].od_version == 6)
{
int Temperature = 0;
if (hm_ADL_Overdrive6_Temperature_Get (data.hm_adl, data.hm_device[device_id].adl, &Temperature) != ADL_OK) return -1;
return Temperature / 1000;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int temperature = 0;
if (hm_NVML_nvmlDeviceGetTemperature (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_TEMPERATURE_GPU, (uint *) &temperature) != NVML_SUCCESS) return -1;
return temperature;
}
return -1;
}
int hm_get_fanpolicy_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.hm_device[device_id].fan_get_supported == 1)
{
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
if (hm_ADL_Overdrive5_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return (lpFanSpeedValue.iFanSpeed & ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) ? 0 : 1;
}
else // od_version == 6
{
return 1;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
return 1;
}
}
return -1;
}
int hm_get_fanspeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.hm_device[device_id].fan_get_supported == 1)
{
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
if (hm_ADL_Overdrive5_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return lpFanSpeedValue.iFanSpeed;
}
else // od_version == 6
{
ADLOD6FanSpeedInfo faninfo;
memset (&faninfo, 0, sizeof (faninfo));
if (hm_ADL_Overdrive6_FanSpeed_Get (data.hm_adl, data.hm_device[device_id].adl, &faninfo) != ADL_OK) return -1;
return faninfo.iFanSpeedPercent;
}
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
int speed = 0;
if (hm_NVML_nvmlDeviceGetFanSpeed (data.hm_nvml, 0, data.hm_device[device_id].nvml, (uint *) &speed) != NVML_SUCCESS) return -1;
return speed;
}
}
return -1;
}
int hm_get_buslanes_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iCurrentBusLanes;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int currLinkWidth;
if (hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (data.hm_nvml, 1, data.hm_device[device_id].nvml, &currLinkWidth) != NVML_SUCCESS) return -1;
return currLinkWidth;
}
return -1;
}
int hm_get_utilization_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iActivityPercent;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
nvmlUtilization_t utilization;
if (hm_NVML_nvmlDeviceGetUtilizationRates (data.hm_nvml, 1, data.hm_device[device_id].nvml, &utilization) != NVML_SUCCESS) return -1;
return utilization.gpu;
}
return -1;
}
int hm_get_memoryspeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iMemoryClock / 100;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int clock;
if (hm_NVML_nvmlDeviceGetClockInfo (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_CLOCK_MEM, &clock) != NVML_SUCCESS) return -1;
return clock;
}
return -1;
}
int hm_get_corespeed_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
if (data.hm_adl)
{
ADLPMActivity PMActivity;
PMActivity.iSize = sizeof (ADLPMActivity);
if (hm_ADL_Overdrive_CurrentActivity_Get (data.hm_adl, data.hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1;
return PMActivity.iEngineClock / 100;
}
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned int clock;
if (hm_NVML_nvmlDeviceGetClockInfo (data.hm_nvml, 1, data.hm_device[device_id].nvml, NVML_CLOCK_SM, &clock) != NVML_SUCCESS) return -1;
return clock;
}
return -1;
}
int hm_get_throttle_with_device_id (const uint device_id)
{
if ((data.devices_param[device_id].device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_AMD)
{
}
if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
{
unsigned long long clocksThrottleReasons = 0;
unsigned long long supportedThrottleReasons = 0;
if (hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (data.hm_nvml, 1, data.hm_device[device_id].nvml, &clocksThrottleReasons) != NVML_SUCCESS) return -1;
if (hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (data.hm_nvml, 1, data.hm_device[device_id].nvml, &supportedThrottleReasons) != NVML_SUCCESS) return -1;
clocksThrottleReasons &= supportedThrottleReasons;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonGpuIdle;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonApplicationsClocksSetting;
clocksThrottleReasons &= ~nvmlClocksThrottleReasonUnknown;
if (data.kernel_power_final)
{
clocksThrottleReasons &= ~nvmlClocksThrottleReasonHwSlowdown;
}
return (clocksThrottleReasons != nvmlClocksThrottleReasonNone);
}
return -1;
}
int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed, const int fanpolicy)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_adl)
{
if (fanpolicy == 1)
{
if (data.hm_device[device_id].od_version == 5)
{
ADLFanSpeedValue lpFanSpeedValue;
memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue);
lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
lpFanSpeedValue.iFanSpeed = fanspeed;
if (hm_ADL_Overdrive5_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
return 0;
}
else // od_version == 6
{
ADLOD6FanSpeedValue fan_speed_value;
memset (&fan_speed_value, 0, sizeof (fan_speed_value));
fan_speed_value.iSpeedType = ADL_OD6_FANSPEED_TYPE_PERCENT;
fan_speed_value.iFanSpeed = fanspeed;
if (hm_ADL_Overdrive6_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, &fan_speed_value) != ADL_OK) return -1;
return 0;
}
}
else
{
if (data.hm_device[device_id].od_version == 5)
{
if (hm_ADL_Overdrive5_FanSpeedToDefault_Set (data.hm_adl, data.hm_device[device_id].adl, 0) != ADL_OK) return -1;
return 0;
}
else // od_version == 6
{
if (hm_ADL_Overdrive6_FanSpeed_Reset (data.hm_adl, data.hm_device[device_id].adl) != ADL_OK) return -1;
return 0;
}
}
}
}
return -1;
}
int hm_set_fanspeed_with_device_id_nvapi (const uint device_id, const int fanspeed, const int fanpolicy)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_nvapi)
{
if (fanpolicy == 1)
{
NV_GPU_COOLER_LEVELS CoolerLevels;
memset (&CoolerLevels, 0, sizeof (NV_GPU_COOLER_LEVELS));
CoolerLevels.Version = GPU_COOLER_LEVELS_VER | sizeof (NV_GPU_COOLER_LEVELS);
CoolerLevels.Levels[0].Level = fanspeed;
CoolerLevels.Levels[0].Policy = 1;
if (hm_NvAPI_GPU_SetCoolerLevels (data.hm_nvapi, data.hm_device[device_id].nvapi, 0, &CoolerLevels) != NVAPI_OK) return -1;
return 0;
}
else
{
if (hm_NvAPI_GPU_RestoreCoolerSettings (data.hm_nvapi, data.hm_device[device_id].nvapi, 0) != NVAPI_OK) return -1;
return 0;
}
}
}
return -1;
}
int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fanspeed)
{
if (data.hm_device[device_id].fan_set_supported == 1)
{
if (data.hm_xnvctrl)
{
if (set_fan_speed_target (data.hm_xnvctrl, data.hm_device[device_id].xnvctrl, fanspeed) != 0) return -1;
return 0;
}
}
return -1;
}
#endif // HAVE_HWMON
/**
* maskprocessor
*/

Loading…
Cancel
Save