-
Notifications
You must be signed in to change notification settings - Fork 16
/
amdapi_adl.cpp
329 lines (288 loc) · 8.99 KB
/
amdapi_adl.cpp
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
#include "amdapi_adl.h"
#include <QDebug>
void* __stdcall ADL_Main_Memory_Alloc ( int iSize )
{
void* lpBuffer = malloc ( iSize );
return lpBuffer;
}
// Optional Memory de-allocation function
void __stdcall ADL_Main_Memory_Free ( void** lpBuffer )
{
if ( NULL != *lpBuffer )
{
free ( *lpBuffer );
*lpBuffer = NULL;
}
}
amdapi_adl::amdapi_adl() : QLibrary("atiadlxx")
, _isInitialized(false)
, _gpuCount(0)
, _lpAdapterInfo(nullptr)
, _context(nullptr)
{
qDebug() << "Entering adl constructor";
ADL2_Main_Control_Create = (ADL2_MAIN_CONTROL_CREATE) resolve("ADL2_Main_Control_Create");
ADL2_Main_Control_Destroy = (ADL2_MAIN_CONTROL_DESTROY) resolve("ADL_Main_Control_Destroy");
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) resolve("ADL_Adapter_NumberOfAdapters_Get");
ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) resolve("ADL_Adapter_AdapterInfo_Get");
ADL_AdapterX2_Caps = (ADL_ADAPTERX2_CAPS) resolve( "ADL_AdapterX2_Caps");
ADL2_Adapter_Active_Get = (ADL2_ADAPTER_ACTIVE_GET)resolve( "ADL2_Adapter_Active_Get");
ADL2_OverdriveN_Capabilities_Get = (ADL2_OVERDRIVEN_CAPABILITIES_GET) resolve ( "ADL2_OverdriveN_Capabilities_Get");
ADL2_OverdriveN_SystemClocks_Get = (ADL2_OVERDRIVEN_SYSTEMCLOCKS_GET) resolve ( "ADL2_OverdriveN_SystemClocks_Get");
ADL2_OverdriveN_SystemClocks_Set = (ADL2_OVERDRIVEN_SYSTEMCLOCKS_SET) resolve ( "ADL2_OverdriveN_SystemClocks_Set");
ADL2_OverdriveN_MemoryClocks_Get = (ADL2_OVERDRIVEN_MEMORYCLOCKS_GET) resolve ( "ADL2_OverdriveN_MemoryClocks_Get");
ADL2_OverdriveN_MemoryClocks_Set = (ADL2_OVERDRIVEN_MEMORYCLOCKS_SET) resolve ( "ADL2_OverdriveN_MemoryClocks_Set");
ADL2_OverdriveN_PerformanceStatus_Get = (ADL2_OVERDRIVEN_PERFORMANCESTATUS_GET) resolve ("ADL2_OverdriveN_PerformanceStatus_Get");
ADL2_OverdriveN_FanControl_Get = (ADL2_OVERDRIVEN_FANCONTROL_GET) resolve ( "ADL2_OverdriveN_FanControl_Get");
ADL2_OverdriveN_FanControl_Set = (ADL2_OVERDRIVEN_FANCONTROL_SET) resolve ( "ADL2_OverdriveN_FanControl_Set");
ADL2_OverdriveN_PowerLimit_Get = (ADL2_OVERDRIVEN_POWERLIMIT_GET) resolve ( "ADL2_OverdriveN_PowerLimit_Get");
ADL2_OverdriveN_PowerLimit_Set = (ADL2_OVERDRIVEN_POWERLIMIT_SET) resolve ( "ADL2_OverdriveN_PowerLimit_Set");
ADL2_OverdriveN_Temperature_Get = (ADL2_OVERDRIVEN_TEMPERATURE_GET) resolve ( "ADL2_OverdriveN_Temperature_Get");
ADL2_Overdrive_Caps = (ADL2_OVERDRIVE_CAPS) resolve ( "ADL2_Overdrive_Caps");
if ( NULL == ADL2_Main_Control_Create ||
NULL == ADL2_Main_Control_Destroy ||
NULL == ADL_Adapter_NumberOfAdapters_Get||
NULL == ADL_Adapter_AdapterInfo_Get ||
NULL == ADL_AdapterX2_Caps ||
NULL == ADL2_Adapter_Active_Get ||
NULL == ADL2_OverdriveN_Capabilities_Get ||
NULL == ADL2_OverdriveN_SystemClocks_Get ||
NULL == ADL2_OverdriveN_SystemClocks_Set ||
NULL == ADL2_OverdriveN_MemoryClocks_Get ||
NULL == ADL2_OverdriveN_MemoryClocks_Set ||
NULL == ADL2_OverdriveN_PerformanceStatus_Get ||
NULL == ADL2_OverdriveN_FanControl_Get ||
NULL == ADL2_OverdriveN_FanControl_Set ||
NULL == ADL2_Overdrive_Caps
)
{
qDebug("Failed to get ADL function pointers");
return;
}
if (ADL_OK != ADL2_Main_Control_Create(ADL_Main_Memory_Alloc, 1, &_context))
{
qDebug("Failed to initialize nested ADL2 context");
return ;
}
getGPUCount();
if(_gpuCount)
{
_lpAdapterInfo = (LPAdapterInfo)malloc ( sizeof (AdapterInfo) * _gpuCount );
memset ( _lpAdapterInfo,'\0', sizeof (AdapterInfo) * _gpuCount );
// Get the AdapterInfo structure for all adapters in the system
ADL_Adapter_AdapterInfo_Get (_lpAdapterInfo, sizeof (AdapterInfo) * _gpuCount);
_isInitialized = true;
}
}
amdapi_adl::~amdapi_adl()
{
if(_isInitialized)
{
free(_lpAdapterInfo);
ADL2_Main_Control_Destroy(&_context);
}
}
int amdapi_adl::getGPUCount()
{
if ( ADL_OK != ADL_Adapter_NumberOfAdapters_Get ( &_gpuCount ) )
{
qDebug("Cannot get the number of adapters!");
return 0;
}
return _gpuCount;
}
int amdapi_adl::getGpuTemperature(int gpu)
{
int temp;
int iSupported,iEnabled,iVersion;
ADL2_Overdrive_Caps(_context, _lpAdapterInfo[gpu].iAdapterIndex, &iSupported, &iEnabled, &iVersion);
if (iSupported && iVersion == 7)
{
if (ADL_OK != ADL2_OverdriveN_Temperature_Get(_context,_lpAdapterInfo[gpu].iAdapterIndex,1, &temp))
{
qDebug() << "ADL2_OverdriveN_Temperature_Get fails on gpu#" << gpu;
return 0;
}
return temp;
}
else
qDebug() << "Do not support N...";
return 0;
}
int amdapi_adl::getGPUClock(int gpu)
{
return 0;
}
int amdapi_adl::getMemClock(int gpu)
{
return 0;
}
int amdapi_adl::getPowerDraw(int gpu)
{
return 0;
}
int amdapi_adl::getFanSpeed(int gpu)
{
ADLODNFanControl fanCtrl;
int iSupported,iEnabled,iVersion;
ADL2_Overdrive_Caps(_context, _lpAdapterInfo[gpu].iAdapterIndex, &iSupported, &iEnabled, &iVersion);
if (iSupported && iVersion == 7)
{
if (ADL_OK != ADL2_OverdriveN_FanControl_Get(_context, _lpAdapterInfo[gpu].iAdapterIndex, &fanCtrl))
{
qDebug() << "ADL2_OverdriveN_FanControl_Get fails on gpu#" << gpu;
return 0;
}
else
return fanCtrl.iCurrentFanSpeed;
}
return 0;
}
int amdapi_adl::setMemClockOffset(int gpu, int clock)
{
return 0;
}
int amdapi_adl::setGPUOffset(int gpu, int offset)
{
return 0;
}
int amdapi_adl::setPowerLimitPercent(int gpu, unsigned int percent)
{
return 0;
}
int amdapi_adl::setTempLimitOffset(int gpu, unsigned int offset)
{
return 0;
}
int amdapi_adl::setFanSpeed(int gpu, unsigned int percent)
{
return 0;
}
int amdapi_adl::getHigherTemp()
{
unsigned int maxTemp = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int temp = getGpuTemperature(i);
if(temp > maxTemp)
maxTemp = temp;
}
return maxTemp;
}
int amdapi_adl::getLowerTemp()
{
unsigned int minTemp = 100000000;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int temp = getGpuTemperature(i);
if(temp < minTemp)
minTemp = temp;
}
return minTemp;
}
int amdapi_adl::getHigherFanSpeed()
{
unsigned int maxSpeed = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int speed = getFanSpeed(i);
if(speed > maxSpeed)
maxSpeed = speed;
}
return maxSpeed;
}
int amdapi_adl::getLowerFanSpeed()
{
unsigned int minSpeed = 1000000;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int speed = getFanSpeed(i);
if(speed < minSpeed)
minSpeed = speed;
}
return minSpeed;
}
int amdapi_adl::getMemMaxClock()
{
unsigned int maxClock = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int clock = getMemClock(i);
if(clock > maxClock)
maxClock = clock;
}
return maxClock;
}
int amdapi_adl::getMemLowerClock()
{
unsigned int minClock = 1000000;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int speed = getMemClock(i);
if(speed < minClock)
minClock = speed;
}
return minClock;
}
int amdapi_adl::getGPUMaxClock()
{
unsigned int maxClock = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int clock = getGPUClock(i);
if(clock > maxClock)
maxClock = clock;
}
return maxClock;
}
int amdapi_adl::getGPUMinClock()
{
unsigned int minClock = 1000000;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int speed = getGPUClock(i);
if(speed < minClock)
minClock = speed;
}
return minClock;
}
int amdapi_adl::getMaxPowerDraw()
{
unsigned int maxWatt = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int watt = getPowerDraw(i);
if(watt > maxWatt)
maxWatt = watt;
}
return maxWatt;
}
int amdapi_adl::getMinPowerDraw()
{
unsigned int minWatt = 1000000;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
{
unsigned int watt = getPowerDraw(i);
if(watt < minWatt)
minWatt = watt;
}
return minWatt;
}
int amdapi_adl::getPowerDrawSum()
{
unsigned int totalWatt = 0;
unsigned int gpuCount = getGPUCount();
for(unsigned int i = 0; i < gpuCount; i++)
totalWatt += getPowerDraw(i);
return totalWatt;
}