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