Added a ton of new NVML stuff
[hashcat.git] / src / hashcat.c
index 7fc6839..76446bd 100644 (file)
@@ -1547,8 +1547,7 @@ void status_display ()
       const int num_corespeed   = hm_get_corespeed_with_device_id   (device_id);
       const int num_memoryspeed = hm_get_memoryspeed_with_device_id (device_id);
       const int num_buslanes    = hm_get_buslanes_with_device_id    (device_id);
-      // not working
-      //const int num_throttle    = hm_get_throttle_with_device_id    (device_id);
+      const int num_throttle    = hm_get_throttle_with_device_id    (device_id);
 
       char output_buf[256] = { 0 };
 
@@ -1596,14 +1595,12 @@ void status_display ()
         output_len = strlen (output_buf);
       }
 
-      /*
-      if (num_throttle >= 0)
+      if (num_throttle == 1)
       {
-        snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Throttle:%u", num_throttle);
+        snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " *Throttled*");
 
         output_len = strlen (output_buf);
       }
-      */
 
       if (output_len == 0)
       {
@@ -4010,9 +4007,7 @@ static void *thread_monitor (void *p)
                   }
                   else if (device_param->device_vendor_id == VENDOR_ID_NV)
                   {
-                    #ifdef _WIN
-                    hm_set_fanspeed_with_device_id_nvapi (device_id, fan_speed_new, 1);
-                    #endif
+
                   }
 
                   fan_speed_chgd[device_id] = 1;
@@ -13990,40 +13985,6 @@ int main (int argc, char **argv)
 
     if (gpu_temp_disable == 0)
     {
-      #if defined(WIN)
-      NVAPI_PTR *nvapi = (NVAPI_PTR *) mymalloc (sizeof (NVAPI_PTR));
-
-      if (nvapi_init (nvapi) == 0)
-        data.hm_nv = nvapi;
-
-      if (data.hm_nv)
-      {
-        if (hm_NvAPI_Initialize (data.hm_nv) == NVAPI_OK)
-        {
-          HM_ADAPTER_NV nvGPUHandle[DEVICES_MAX] = { 0 };
-
-          int tmp_in = hm_get_adapter_index_nv (nvGPUHandle);
-
-          int tmp_out = 0;
-
-          for (int i = 0; i < tmp_in; i++)
-          {
-            hm_adapters_nv[tmp_out++].adapter_index.nv = nvGPUHandle[i];
-          }
-
-          for (int i = 0; i < tmp_out; i++)
-          {
-            NV_GPU_COOLER_SETTINGS pCoolerSettings;
-
-            pCoolerSettings.Version = GPU_COOLER_SETTINGS_VER | sizeof (NV_GPU_COOLER_SETTINGS);
-
-            if (hm_NvAPI_GPU_GetCoolerSettings (data.hm_nv, hm_adapters_nv[i].adapter_index.nv, 0, &pCoolerSettings) != NVAPI_NOT_SUPPORTED) hm_adapters_nv[i].fan_get_supported = 1;
-          }
-        }
-      }
-      #endif // WIN
-
-      #if defined(LINUX)
       NVML_PTR *nvml = (NVML_PTR *) mymalloc (sizeof (NVML_PTR));
 
       if (nvml_init (nvml) == 0)
@@ -14049,10 +14010,24 @@ int main (int argc, char **argv)
             unsigned int speed;
 
             if (hm_NVML_nvmlDeviceGetFanSpeed (data.hm_nv, 1, hm_adapters_nv[i].adapter_index.nv, &speed) != NVML_ERROR_NOT_SUPPORTED) hm_adapters_nv[i].fan_get_supported = 1;
+
+            hm_NVML_nvmlDeviceSetComputeMode (data.hm_nv, 1, hm_adapters_nv[i].adapter_index.nv, NVML_COMPUTEMODE_EXCLUSIVE_PROCESS);
+
+            hm_NVML_nvmlDeviceSetGpuOperationMode (data.hm_nv, 1, hm_adapters_nv[i].adapter_index.nv, NVML_GOM_ALL_ON);
+
+            unsigned int minLimit;
+            unsigned int maxLimit;
+
+            if (hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (data.hm_nv, 1, hm_adapters_nv[i].adapter_index.nv, &minLimit, &maxLimit) == NVML_SUCCESS)
+            {
+              if (maxLimit > 0)
+              {
+                hm_NVML_nvmlDeviceSetPowerManagementLimit (data.hm_nv, 1, hm_adapters_nv[i].adapter_index.nv, maxLimit);
+              }
+            }
           }
         }
       }
-      #endif // LINUX
 
       data.hm_amd = NULL;
 
@@ -15600,8 +15575,12 @@ int main (int argc, char **argv)
       if (gpu_temp_disable == 0)
       {
         const int gpu_temp_threshold_slowdown = hm_get_threshold_slowdown_with_device_id (device_id);
+        const int gpu_temp_threshold_shutdown = hm_get_threshold_slowdown_with_device_id (device_id);
+
+        data.hm_device[device_id].gpu_temp_threshold_slowdown = (gpu_temp_threshold_slowdown > 0) ? gpu_temp_threshold_slowdown : 10000;
+        data.hm_device[device_id].gpu_temp_threshold_shutdown = (gpu_temp_threshold_shutdown > 0) ? gpu_temp_threshold_shutdown : 10000;
 
-        data.hm_device[device_id].gpu_temp_threshold_slowdown = (gpu_temp_threshold_slowdown == -1) ? 100000 : gpu_temp_threshold_slowdown;
+        // we could use those numbers for gpu_temp_retain and gpu_temp_abort, too
       }
 
       /**
@@ -15637,9 +15616,7 @@ int main (int argc, char **argv)
               }
               else if (device_param->device_vendor_id == VENDOR_ID_NV)
               {
-                #ifdef _WIN
-                rc = hm_set_fanspeed_with_device_id_nvapi (device_id, fanspeed, 1);
-                #endif
+
               }
 
               if (rc == 0)
@@ -17917,9 +17894,7 @@ int main (int argc, char **argv)
               }
               else if (device_param->device_vendor_id == VENDOR_ID_NV)
               {
-                #ifdef _WIN
-                rc = hm_set_fanspeed_with_device_id_nvapi (device_id, fanspeed, 16);
-                #endif
+
               }
 
               if (rc == -1) log_info ("WARNING: Failed to restore default fan speed and policy for device #%", device_id + 1);
@@ -17997,20 +17972,10 @@ int main (int argc, char **argv)
     {
       if (data.hm_nv)
       {
-        #if defined(LINUX)
-
         hm_NVML_nvmlShutdown (data.hm_nv);
 
         nvml_close (data.hm_nv);
 
-        #elif defined(WIN)
-
-        hm_NvAPI_Unload (data.hm_nv);
-
-        nvapi_close (data.hm_nv);
-
-        #endif
-
         data.hm_nv = NULL;
       }