03671d52485df104e1613a9808704cbdd816f0a4
[hashcat.git] / include / ext_nvml.h
1 /**
2 * Authors.....: Jens Steube <jens.steube@gmail.com>
3 * Gabriele Gristina <matrix@hashcat.net>
4 * magnum <john.magnum@hushmail.com>
5 *
6 * License.....: MIT
7 */
8
9 #ifndef EXT_NVML_H
10 #define EXT_NVML_H
11
12 #if defined(HAVE_HWMON) && defined(HAVE_NVML)
13
14 #include <common.h>
15
16 /**
17 * Declarations from nvml.h
18 */
19
20 typedef struct nvmlDevice_st* nvmlDevice_t;
21
22 typedef struct nvmlPciInfo_st {
23 char busId[16];
24 unsigned int domain;
25 unsigned int bus;
26 unsigned int device;
27 unsigned int pciDeviceId;
28 unsigned int pciSubSystemId;
29 } nvmlPciInfo_t;
30
31 typedef struct nvmlUtilization_st {
32 unsigned int gpu; // GPU kernel execution last second, percent
33 unsigned int memory; // GPU memory read/write last second, percent
34 } nvmlUtilization_t;
35
36 typedef enum nvmlTemperatureSensors_enum {
37 NVML_TEMPERATURE_GPU = 0 // Temperature sensor for the GPU die
38 } nvmlTemperatureSensors_t;
39
40 typedef enum nvmlReturn_enum {
41 NVML_SUCCESS = 0, // The operation was successful
42 NVML_ERROR_UNINITIALIZED = 1, // NVML was not first initialized with nvmlInit()
43 NVML_ERROR_INVALID_ARGUMENT = 2, // A supplied argument is invalid
44 NVML_ERROR_NOT_SUPPORTED = 3, // The requested operation is not available on target device
45 NVML_ERROR_NO_PERMISSION = 4, // The current user does not have permission for operation
46 NVML_ERROR_ALREADY_INITIALIZED = 5, // Deprecated: Multiple initializations are now allowed through ref counting
47 NVML_ERROR_NOT_FOUND = 6, // A query to find an object was unsuccessful
48 NVML_ERROR_INSUFFICIENT_SIZE = 7, // An input argument is not large enough
49 NVML_ERROR_INSUFFICIENT_POWER = 8, // A device's external power cables are not properly attached
50 NVML_ERROR_DRIVER_NOT_LOADED = 9, // NVIDIA driver is not loaded
51 NVML_ERROR_TIMEOUT = 10, // User provided timeout passed
52 NVML_ERROR_UNKNOWN = 999 // An internal driver error occurred
53 } nvmlReturn_t;
54
55 typedef enum nvmlClockType_enum {
56 NVML_CLOCK_GRAPHICS = 0,
57 NVML_CLOCK_SM = 1,
58 NVML_CLOCK_MEM = 2
59 } nvmlClockType_t;
60
61 typedef enum nvmlTemperatureThresholds_enum
62 {
63 NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0, // Temperature at which the GPU will shut down
64 // for HW protection
65 NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1, // Temperature at which the GPU will begin slowdown
66 // Keep this last
67 NVML_TEMPERATURE_THRESHOLD_COUNT
68 } nvmlTemperatureThresholds_t;
69
70 /*
71 * End of declarations from nvml.h
72 **/
73
74 typedef nvmlDevice_t HM_ADAPTER_NV;
75
76 #include <shared.h>
77
78 typedef const char * (*NVML_ERROR_STRING) (nvmlReturn_t);
79 typedef int (*NVML_INIT) (void);
80 typedef int (*NVML_SHUTDOWN) (void);
81 typedef nvmlReturn_t (*NVML_DEVICE_GET_NAME) (nvmlDevice_t, char *, unsigned int);
82 typedef nvmlReturn_t (*NVML_DEVICE_GET_HANDLE_BY_INDEX) (unsigned int, nvmlDevice_t *);
83 typedef nvmlReturn_t (*NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatureSensors_t, unsigned int *);
84 typedef nvmlReturn_t (*NVML_DEVICE_GET_FAN_SPEED) (nvmlDevice_t, unsigned int *);
85 typedef nvmlReturn_t (*NVML_DEVICE_GET_POWER_USAGE) (nvmlDevice_t, unsigned int *);
86 typedef nvmlReturn_t (*NVML_DEVICE_GET_UTILIZATION_RATES) (nvmlDevice_t, nvmlUtilization_t *);
87 typedef nvmlReturn_t (*NVML_DEVICE_GET_CLOCKINFO) (nvmlDevice_t, nvmlClockType_t, unsigned int *);
88 typedef nvmlReturn_t (*NVML_DEVICE_GET_THRESHOLD) (nvmlDevice_t, nvmlTemperatureThresholds_t, unsigned int *);
89
90 typedef struct
91 {
92 NV_LIB lib;
93
94 NVML_ERROR_STRING nvmlErrorString;
95 NVML_INIT nvmlInit;
96 NVML_SHUTDOWN nvmlShutdown;
97 NVML_DEVICE_GET_NAME nvmlDeviceGetName;
98 NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex;
99 NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature;
100 NVML_DEVICE_GET_FAN_SPEED nvmlDeviceGetFanSpeed;
101 NVML_DEVICE_GET_POWER_USAGE nvmlDeviceGetPowerUsage;
102 NVML_DEVICE_GET_UTILIZATION_RATES nvmlDeviceGetUtilizationRates;
103 NVML_DEVICE_GET_CLOCKINFO nvmlDeviceGetClockInfo;
104 NVML_DEVICE_GET_THRESHOLD nvmlDeviceGetTemperatureThreshold;
105
106 } hm_nvml_lib_t;
107
108 #define NVML_PTR hm_nvml_lib_t
109
110 int nvml_init (NVML_PTR *lib);
111 void nvml_close (NVML_PTR *lib);
112
113 const char * hm_NVML_nvmlErrorString (NVML_PTR *nvml, nvmlReturn_t nvml_rc);
114 nvmlReturn_t hm_NVML_nvmlInit (NVML_PTR *nvml);
115 nvmlReturn_t hm_NVML_nvmlShutdown (NVML_PTR *nvml);
116 nvmlReturn_t hm_NVML_nvmlDeviceGetName (NVML_PTR *nvml, nvmlDevice_t device, char *name, unsigned int length);
117 nvmlReturn_t hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR *nvml, int, unsigned int index, nvmlDevice_t *device);
118 nvmlReturn_t hm_NVML_nvmlDeviceGetTemperature (NVML_PTR *nvml, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp);
119 nvmlReturn_t hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *speed);
120 nvmlReturn_t hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR *nvml, nvmlDevice_t device, unsigned int *power);
121 nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, nvmlDevice_t device, nvmlUtilization_t *utilization);
122 nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock);
123 nvmlReturn_t hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR *nvml, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp);
124
125 #endif // HAVE_HWMON && HAVE_NVML
126
127 #endif // EXT_NVML_H