1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
use status::NvAPI_Status;
use handles::NvPhysicalGpuHandle;
use types::BoolU32;
pub const NVAPI_MAX_GPU_CLOCKS: usize = 32;
pub const NVAPI_MAX_GPU_PUBLIC_CLOCKS: usize = 32;
pub const NVAPI_MAX_GPU_PERF_CLOCKS: usize = 32;
pub const NVAPI_MAX_GPU_PERF_VOLTAGES: usize = 16;
pub const NVAPI_MAX_GPU_PERF_PSTATES: usize = 16;
nvenum! {
pub enum NV_GPU_PUBLIC_CLOCK_ID / PublicClockId {
NVAPI_GPU_PUBLIC_CLOCK_GRAPHICS / Graphics = 0,
NVAPI_GPU_PUBLIC_CLOCK_MEMORY / Memory = 4,
NVAPI_GPU_PUBLIC_CLOCK_PROCESSOR / Processor = 7,
NVAPI_GPU_PUBLIC_CLOCK_VIDEO / Video = 8,
NVAPI_GPU_PUBLIC_CLOCK_UNDEFINED / Undefined = NVAPI_MAX_GPU_PUBLIC_CLOCKS,
}
}
nvenum_display! {
PublicClockId => _
}
nvstruct! {
pub struct NV_GPU_CLOCK_FREQUENCIES_V1 {
pub version: u32,
pub reserved: u32,
pub domain: [NV_GPU_CLOCK_FREQUENCIES_DOMAIN; NVAPI_MAX_GPU_PUBLIC_CLOCKS],
}
}
impl NV_GPU_CLOCK_FREQUENCIES_V1 {
pub fn ClockType(&self) -> NV_GPU_CLOCK_FREQUENCIES_CLOCK_TYPE {
(self.reserved & 3) as _
}
pub fn set_ClockType(&mut self, value: NV_GPU_CLOCK_FREQUENCIES_CLOCK_TYPE) {
self.reserved = (value as u32) & 3;
}
}
pub type NV_GPU_CLOCK_FREQUENCIES_V2 = NV_GPU_CLOCK_FREQUENCIES_V1;
pub type NV_GPU_CLOCK_FREQUENCIES = NV_GPU_CLOCK_FREQUENCIES_V2;
nvversion! { NV_GPU_CLOCK_FREQUENCIES_VER_1(NV_GPU_CLOCK_FREQUENCIES_V1 = 4 * 2 + (4 * 2) * NVAPI_MAX_GPU_PUBLIC_CLOCKS, 1) }
nvversion! { NV_GPU_CLOCK_FREQUENCIES_VER_2(NV_GPU_CLOCK_FREQUENCIES_V2 = 4 * 2 + (4 * 2) * NVAPI_MAX_GPU_PUBLIC_CLOCKS, 2) }
nvversion! { NV_GPU_CLOCK_FREQUENCIES_VER_3(NV_GPU_CLOCK_FREQUENCIES_V2 = 4 * 2 + (4 * 2) * NVAPI_MAX_GPU_PUBLIC_CLOCKS, 3) }
nvversion! { NV_GPU_CLOCK_FREQUENCIES_VER = NV_GPU_CLOCK_FREQUENCIES_VER_3 }
nvenum! {
pub enum NV_GPU_CLOCK_FREQUENCIES_CLOCK_TYPE / ClockFrequencyType {
NV_GPU_CLOCK_FREQUENCIES_CURRENT_FREQ / Current = 0,
NV_GPU_CLOCK_FREQUENCIES_BASE_CLOCK / Base = 1,
NV_GPU_CLOCK_FREQUENCIES_BOOST_CLOCK / Boost = 2,
NV_GPU_CLOCK_FREQUENCIES_CLOCK_TYPE_NUM / Count = 3,
}
}
nvenum_display! {
ClockFrequencyType => _
}
nvstruct! {
pub struct NV_GPU_CLOCK_FREQUENCIES_DOMAIN {
pub bIsPresent: BoolU32,
pub frequency: u32,
}
}
nvapi! {
pub type GPU_GetAllClockFrequenciesFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, pClkFreqs: *mut NV_GPU_CLOCK_FREQUENCIES) -> NvAPI_Status;
pub unsafe fn NvAPI_GPU_GetAllClockFrequencies;
}
pub mod private {
pub const NVAPI_MAX_USAGES_PER_GPU: usize = 8;
pub const NVAPI_MAX_CLOCKS_PER_GPU: usize = 288;
use types::BoolU32;
use status::NvAPI_Status;
use handles::NvPhysicalGpuHandle;
use debug_array::Array;
nvstruct! {
pub struct NV_USAGES_INFO_USAGE {
pub bIsPresent: BoolU32,
pub percentage: u32,
pub unknown: [u32; 2],
}
}
nvstruct! {
pub struct NV_USAGES_INFO_V1 {
pub version: u32,
pub flags: u32,
pub usages: [NV_USAGES_INFO_USAGE; NVAPI_MAX_USAGES_PER_GPU],
}
}
nvversion! { NV_USAGES_INFO_VER_1(NV_USAGES_INFO_V1 = 4 * (2 + 4 * NVAPI_MAX_USAGES_PER_GPU), 1) }
nvversion! { NV_USAGES_INFO_VER = NV_USAGES_INFO_VER_1 }
pub type NV_USAGES_INFO = NV_USAGES_INFO_V1;
nvapi! {
pub type GPU_GetUsagesFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, pUsagesInfo: *mut NV_USAGES_INFO) -> NvAPI_Status;
pub unsafe fn NvAPI_GPU_GetUsages;
}
debug_array_impl! { [u32; NVAPI_MAX_CLOCKS_PER_GPU] }
nvstruct! {
pub struct NV_CLOCKS_INFO_V1 {
pub version: u32,
pub clocks: Array<[u32; NVAPI_MAX_CLOCKS_PER_GPU]>,
}
}
nvversion! { NV_CLOCKS_INFO_VER_1(NV_CLOCKS_INFO_V1 = 4 * (1 + NVAPI_MAX_CLOCKS_PER_GPU), 1) }
nvversion! { NV_CLOCKS_INFO_VER = NV_CLOCKS_INFO_VER_1 }
pub type NV_CLOCKS_INFO = NV_CLOCKS_INFO_V1;
nvapi! {
pub type GPU_GetAllClocksFn = extern "C" fn(hPhysicalGPU: NvPhysicalGpuHandle, pClocksInfo: *mut NV_CLOCKS_INFO) -> NvAPI_Status;
pub unsafe fn NvAPI_GPU_GetAllClocks;
}
nvstruct! {
pub struct NV_CLOCK_TABLE_GPU_DELTA {
pub a: u32,
pub b: u32,
pub c: u32,
pub d: u32,
pub e: u32,
pub freqDeltaKHz: i32,
pub g: u32,
pub h: u32,
pub i: u32,
}
}
debug_array_impl! { [NV_CLOCK_TABLE_GPU_DELTA; 80] }
debug_array_impl! { [u32; 1529] }
nvstruct! {
pub struct NV_CLOCK_TABLE_V1 {
pub version: u32,
pub mask: [u32; 4],
pub unknown: [u32; 12],
pub gpuDeltas: Array<[NV_CLOCK_TABLE_GPU_DELTA; 80]>,
pub memFilled: [u32; 23],
pub memDeltas: [i32; 23],
pub unknown2: Array<[u32; 1529]>,
}
}
nvversion! { NV_CLOCK_TABLE_VER_1(NV_CLOCK_TABLE_V1 = 9248, 1) }
nvversion! { NV_CLOCK_TABLE_VER = NV_CLOCK_TABLE_VER_1 }
pub type NV_CLOCK_TABLE = NV_CLOCK_TABLE_V1;
nvapi! {
pub unsafe fn NvAPI_GPU_GetClockBoostTable(hPhysicalGPU: NvPhysicalGpuHandle, pClockTable: *mut NV_CLOCK_TABLE) -> NvAPI_Status;
}
nvapi! {
pub unsafe fn NvAPI_GPU_SetClockBoostTable(hPhysicalGPU: NvPhysicalGpuHandle, pClockTable: *const NV_CLOCK_TABLE) -> NvAPI_Status;
}
nvstruct! {
pub struct NV_CLOCK_RANGES_ENTRY {
pub a: u32,
pub clockType: super::NV_GPU_PUBLIC_CLOCK_ID,
pub c: u32,
pub d: u32,
pub e: u32,
pub f: u32,
pub g: u32,
pub h: u32,
pub i: u32,
pub j: u32,
pub rangeMax: i32,
pub rangeMin: i32,
pub tempMax: i32,
pub n: u32,
pub o: u32,
pub p: u32,
pub q: u32,
pub r: u32,
}
}
nvstruct! {
pub struct NV_CLOCK_RANGES_V1 {
pub version: u32,
pub numClocks: u32,
pub zero: [u32; 8],
pub entries: [NV_CLOCK_RANGES_ENTRY; 32],
}
}
nvversion! { NV_CLOCK_RANGES_VER_1(NV_CLOCK_RANGES_V1 = 2344, 1) }
nvversion! { NV_CLOCK_RANGES_VER = NV_CLOCK_RANGES_VER_1 }
pub type NV_CLOCK_RANGES = NV_CLOCK_RANGES_V1;
nvapi! {
pub unsafe fn NvAPI_GPU_GetClockBoostRanges(hPhysicalGPU: NvPhysicalGpuHandle, pClockRanges: *mut NV_CLOCK_RANGES) -> NvAPI_Status;
}
nvstruct! {
pub struct NV_CLOCK_MASKS_CLOCK {
pub a: u32,
pub b: u32,
pub c: u32,
pub d: u32,
pub memDelta: u32,
pub gpuDelta: u32,
}
}
debug_array_impl! { [NV_CLOCK_MASKS_CLOCK; 80 + 23] }
debug_array_impl! { [u32; 916] }
nvstruct! {
pub struct NV_CLOCK_MASKS_V1 {
pub version: u32,
pub mask: [u32; 4],
pub unknown: [u32; 8],
pub clocks: Array<[NV_CLOCK_MASKS_CLOCK; 80 + 23]>,
pub unknown2: Array<[u32; 916]>,
}
}
nvversion! { NV_CLOCK_MASKS_VER_1(NV_CLOCK_MASKS_V1 = 6188, 1) }
nvversion! { NV_CLOCK_MASKS_VER = NV_CLOCK_MASKS_VER_1 }
pub type NV_CLOCK_MASKS = NV_CLOCK_MASKS_V1;
nvapi! {
pub unsafe fn NvAPI_GPU_GetClockBoostMask(hPhysicalGPU: NvPhysicalGpuHandle, pClockMasks: *mut NV_CLOCK_MASKS) -> NvAPI_Status;
}
nvenum! {
pub enum NV_GPU_CLOCK_LOCK_MODE / ClockLockMode {
NVAPI_GPU_CLOCK_LOCK_NONE / None = 0,
NVAPI_GPU_CLOCK_LOCK_MANUAL / Manual = 3,
}
}
nvstruct! {
pub struct NV_CLOCK_LOCK_ENTRY {
pub id: u32,
pub b: u32,
pub mode: NV_GPU_CLOCK_LOCK_MODE,
pub d: u32,
pub voltage_uV: u32,
pub f: u32,
}
}
nvstruct! {
pub struct NV_CLOCK_LOCK_V2 {
pub version: u32,
pub flags: u32,
pub count: u32,
pub entries: [NV_CLOCK_LOCK_ENTRY; 0x20],
}
}
pub type NV_CLOCK_LOCK = NV_CLOCK_LOCK_V2;
nvversion! { NV_CLOCK_LOCK_VER_2(NV_CLOCK_LOCK_V2 = 0x30c, 2) }
nvversion! { NV_CLOCK_LOCK_VER = NV_CLOCK_LOCK_VER_2 }
nvapi! {
pub unsafe fn NvAPI_GPU_GetClockBoostLock(hPhysicalGPU: NvPhysicalGpuHandle, pClockLocks: *mut NV_CLOCK_LOCK) -> NvAPI_Status;
}
nvapi! {
pub unsafe fn NvAPI_GPU_SetClockBoostLock(hPhysicalGPU: NvPhysicalGpuHandle, pClockLocks: *const NV_CLOCK_LOCK) -> NvAPI_Status;
}
}