1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Added --gpu-temp-retain support for windows through nvapi

This commit is contained in:
jsteube 2016-06-18 18:21:40 +02:00
parent 6a2ec331ef
commit 2bd49e6720
6 changed files with 97 additions and 21 deletions

View File

@ -24,7 +24,7 @@ It combines all features of all hashcat projects in one project.
- Added makefile install and uninstall targets
- Added autotuning engine and user-configurable tuning database
- Added current engine clock, current memory clock and pci-e lanes to the status display
- Added support for --gpu-temp-retain for nvidia devices on windows
- Added support for --gpu-temp-retain for NVidia GPU, both Linux and Windows
- Added execution timer of the running kernel to the status display
- Added command prompt to quit at next restore checkpoint
- Added human-readable error message for the OpenCL error codes
@ -137,4 +137,4 @@ It combines all features of all hashcat projects in one project.
- Disabled retain support by default, you can reactive it using --gpu-temp-retain
- Completely get rid of HAVE_ADL, HAVE_NVML and HAVE_NVAPI in sources
- Replaced NVAPI with NVML on windows
- Added support for XNVCTRL on Linux to add support for --gpu-temp-retain for NVidia GPU

View File

@ -19,6 +19,7 @@
#define NVAPI_INTERFACE extern NvAPI_Status
typedef unsigned long NvU32;
typedef signed long NvS32;
#define NV_DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
@ -35,6 +36,9 @@ typedef char NvAPI_ShortString[NVAPI_SHORT_STRING_MAX];
#define MAKE_NVAPI_VERSION(typeName,ver) (NvU32)(sizeof(typeName) | ((ver)<<16))
#define NVAPI_MAX_PHYSICAL_GPUS 64
#define NVAPI_MAX_COOLER_PER_GPU 20
#define GPU_COOLER_LEVELS_VER 0x10000
typedef enum _NvAPI_Status
{
@ -187,6 +191,20 @@ typedef struct
} NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1;
typedef struct
{
NvS32 Level;
NvS32 Policy;
} NvLevel;
typedef struct
{
NvU32 Version;
NvLevel Levels[NVAPI_MAX_COOLER_PER_GPU];
} NV_GPU_COOLER_LEVELS;
NVAPI_INTERFACE NvAPI_QueryInterface (uint offset);
NVAPI_INTERFACE NvAPI_Initialize ();
NVAPI_INTERFACE NvAPI_Unload ();
@ -194,6 +212,7 @@ NVAPI_INTERFACE NvAPI_GetErrorMessage (NvAPI_Status nr,NvAPI_ShortString szDesc)
NVAPI_INTERFACE NvAPI_EnumPhysicalGPUs (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesInfo (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info);
NVAPI_INTERFACE NvAPI_GPU_GetPerfPoliciesStatus (NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status);
NVAPI_INTERFACE NvAPI_GPU_SetCoolerLevels (NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels);
/*
* End of declarations from nvapi.h and subheaders
@ -216,6 +235,7 @@ typedef int (*NVAPI_API_CALL NVAPI_GETERRORMESSAGE) (NvAPI_Status, NvAPI_ShortSt
typedef int (*NVAPI_API_CALL NVAPI_ENUMPHYSICALGPUS) (NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *);
typedef int (*NVAPI_API_CALL NVAPI_GPU_GETPERFPOLICIESINFO) (NvPhysicalGpuHandle, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *);
typedef int (*NVAPI_API_CALL NVAPI_GPU_GETPERFPOLICIESSTATUS) (NvPhysicalGpuHandle, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *);
typedef int (*NVAPI_API_CALL NVAPI_GPU_SETCOOLERLEVELS) (NvPhysicalGpuHandle, NvU32, NV_GPU_COOLER_LEVELS *);
typedef struct
{
@ -228,6 +248,7 @@ typedef struct
NVAPI_ENUMPHYSICALGPUS NvAPI_EnumPhysicalGPUs;
NVAPI_GPU_GETPERFPOLICIESINFO NvAPI_GPU_GetPerfPoliciesInfo;
NVAPI_GPU_GETPERFPOLICIESSTATUS NvAPI_GPU_GetPerfPoliciesStatus;
NVAPI_GPU_SETCOOLERLEVELS NvAPI_GPU_SetCoolerLevels;
} hm_nvapi_lib_t;
@ -243,6 +264,7 @@ int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status nr, NvAPI_ShortStri
int hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount);
int hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info);
int hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status);
int hm_NvAPI_GPU_SetCoolerLevels (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels);
#endif // HAVE_HWMON

View File

@ -1465,6 +1465,7 @@ 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);

View File

@ -38,6 +38,7 @@ int nvapi_init (NVAPI_PTR *nvapi)
HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0)
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0)
HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0)
HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AE, NVAPI, 0)
return 0;
}
@ -152,6 +153,24 @@ int hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hP
return NvAPI_rc;
}
int hm_NvAPI_GPU_SetCoolerLevels (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels)
{
if (!nvapi) return (-1);
NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_SetCoolerLevels (hPhysicalGpu, coolerIndex, pCoolerLevels);
if (NvAPI_rc != NVAPI_OK)
{
NvAPI_ShortString string = { 0 };
hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string);
log_info ("WARN: %s %d %s\n", "NvAPI_GPU_SetCoolerLevels()", NvAPI_rc, string);
}
return NvAPI_rc;
}
#ifdef __MINGW64__
void __security_check_cookie (uintptr_t _StackCookie)

View File

@ -4235,7 +4235,11 @@ static void *thread_monitor (void *p)
}
else if (device_param->device_vendor_id == VENDOR_ID_NV)
{
#ifdef _POSIX
#ifdef _WIN
hm_set_fanspeed_with_device_id_nvapi (device_id, fan_speed_new, 1);
#endif
#ifdef _LINUX
hm_set_fanspeed_with_device_id_xnvctrl (device_id, fan_speed_new);
#endif
}
@ -14066,7 +14070,7 @@ int main (int argc, char **argv)
{
need_nvml = 1;
#ifdef _POSIX
#ifdef _LINUX
need_xnvctrl = 1;
#endif
@ -16180,7 +16184,11 @@ int main (int argc, char **argv)
}
else if (device_param->device_vendor_id == VENDOR_ID_NV)
{
#ifdef _POSIX
#ifdef _WIN
rc = hm_set_fanspeed_with_device_id_nvapi (device_id, fanspeed, 1);
#endif
#ifdef _LINUX
rc = set_fan_control (data.hm_xnvctrl, data.hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_TRUE);
#endif
}
@ -18382,7 +18390,11 @@ int main (int argc, char **argv)
}
else if (device_param->device_vendor_id == VENDOR_ID_NV)
{
#ifdef _POSIX
#ifdef _WIN
rc = hm_set_fanspeed_with_device_id_nvapi (device_id, fanspeed, fanpolicy);
#endif
#ifdef _LINUX
rc = set_fan_control (data.hm_xnvctrl, data.hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_FALSE);
#endif
}

View File

@ -3398,21 +3398,6 @@ int hm_get_throttle_with_device_id (const uint device_id)
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;
}
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)
@ -3453,6 +3438,43 @@ int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed
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)
{
NV_GPU_COOLER_LEVELS CoolerLevels = { 0 };
CoolerLevels.Version = GPU_COOLER_LEVELS_VER | sizeof (NV_GPU_COOLER_LEVELS);
CoolerLevels.Levels[0].Level = fanspeed;
CoolerLevels.Levels[0].Policy = fanpolicy;
if (hm_NvAPI_GPU_SetCoolerLevels (data.hm_nvapi, data.hm_device[device_id].nvapi, 0, &CoolerLevels) != 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
/**