Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit a2fd2fe

Browse files
committedFeb 18, 2018
ADL power fully working! It uses same option as with Nvidia cards
1 parent 7878635 commit a2fd2fe

File tree

6 files changed

+90
-10
lines changed

6 files changed

+90
-10
lines changed
 

‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,22 @@ This project uses [CMake] and [Hunter] package manager.
8989
```sh
9090
cmake ..
9191
```
92+
Note: In Windows, it is possible to have issues with VS 2017 compilers, in that case, use VS 2017 installer to get VS 2015 compilers and use:
93+
```sh
94+
cmake .. -G "Visual Studio 15 2017 Win64" -Tv140
95+
```
96+
9297

9398
3. Build the project using [CMake Build Tool Mode]. This is a portable variant
9499
of `make`.
95100

96101
```sh
97102
cmake --build .
98103
```
104+
Note: In Windows, it is possible to have compiler issues if you don't specify build config. In that case use:
105+
```sh
106+
cmake --build . --config Release
107+
```
99108

100109
4. _(Optional, Linux only)_ Install the built executable.
101110

‎libethcore/Farm.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,24 @@ class Farm: public FarmFace
259259
if (hwmon) {
260260
HwMonitorInfo hwInfo = i->hwmonInfo();
261261
HwMonitor hw;
262+
hw.powerW = 0.0;
262263
unsigned int tempC = 0, fanpcnt = 0, powerW = 0;
263264
if (hwInfo.deviceIndex >= 0) {
264265
if (hwInfo.deviceType == HwMonitorInfoType::NVIDIA && nvmlh) {
265266
wrap_nvml_get_tempC(nvmlh, hwInfo.deviceIndex, &tempC);
266267
wrap_nvml_get_fanpcnt(nvmlh, hwInfo.deviceIndex, &fanpcnt);
267268
if(power) {
268269
wrap_nvml_get_power_usage(nvmlh, hwInfo.deviceIndex, &powerW);
270+
hw.powerW = powerW/((double)1000.0);
269271
}
270272
}
271273
else if (hwInfo.deviceType == HwMonitorInfoType::AMD && adlh) {
272274
wrap_adl_get_tempC(adlh, hwInfo.deviceIndex, &tempC);
273275
wrap_adl_get_fanpcnt(adlh, hwInfo.deviceIndex, &fanpcnt);
274-
//TODO
275-
//if(power) {
276-
//wrap_adl_get_power_usage(adlh, hwInfo.deviceIndex, &powerW);
277-
//}
276+
if(power) {
277+
wrap_adl_get_power_usage(adlh, hwInfo.deviceIndex, &powerW);
278+
hw.powerW = adlf2double(powerW);
279+
}
278280
}
279281
#if defined(__linux)
280282
// Overwrite with sysfs data if present
@@ -290,7 +292,6 @@ class Farm: public FarmFace
290292
}
291293
hw.tempC = tempC;
292294
hw.fanP = fanpcnt;
293-
hw.powrW = powerW/((double)1000.0);
294295
p.minerMonitors.push_back(hw);
295296
}
296297
}

‎libethcore/Miner.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ struct HwMonitor
8080
{
8181
int tempC = 0;
8282
int fanP = 0;
83-
double powrW = 0;
83+
double powerW = 0;
8484
};
8585

8686
inline std::ostream& operator<<(std::ostream& os, HwMonitor _hw)
8787
{
8888
string power = "";
89-
if(_hw.powrW != 0){
89+
if(_hw.powerW != 0){
9090
ostringstream stream;
91-
stream << fixed << setprecision(2) << _hw.powrW << "W";
91+
stream << fixed << setprecision(2) << _hw.powerW << "W";
9292
power = stream.str();
9393
}
9494
return os << _hw.tempC << "C " << _hw.fanP << "% " << power;

‎libhwmon/wrapadl.cpp

+30-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88
#include <string.h>
9-
#include "wraphelper.h"
109
#include "wrapadl.h"
1110

1211
#if defined(__cplusplus)
@@ -72,6 +71,15 @@ return NULL;
7271
wrap_dlsym(adlh->adl_dll, "ADL_Main_Control_Refresh");
7372
adlh->adlMainControlDestroy = (wrap_adlReturn_t(*)(void))
7473
wrap_dlsym(adlh->adl_dll, "ADL_Main_Control_Destroy");
74+
adlh->adl2MainControlCreate = (wrap_adlReturn_t(*)(ADL_MAIN_MALLOC_CALLBACK, int, ADL_CONTEXT_HANDLE*))
75+
wrap_dlsym(adlh->adl_dll, "ADL2_Main_Control_Create");
76+
adlh->adl2MainControlDestroy = (wrap_adlReturn_t(*)(ADL_CONTEXT_HANDLE))
77+
wrap_dlsym(adlh->adl_dll, "ADL_Main_Control_Destroy");
78+
adlh->adl2Overdrive6CurrentPowerGet = (wrap_adlReturn_t(*)(ADL_CONTEXT_HANDLE, int, int, int*))
79+
wrap_dlsym(adlh->adl_dll, "ADL2_Overdrive6_CurrentPower_Get");
80+
adlh->adl2MainControlRefresh = (wrap_adlReturn_t(*)(ADL_CONTEXT_HANDLE))
81+
wrap_dlsym(adlh->adl_dll, "ADL2_Main_Control_Refresh");
82+
7583

7684
if (adlh->adlMainControlCreate == NULL ||
7785
adlh->adlMainControlDestroy == NULL ||
@@ -80,7 +88,11 @@ return NULL;
8088
adlh->adlAdapterAdapterInfoGet == NULL ||
8189
adlh->adlAdapterAdapterIdGet == NULL ||
8290
adlh->adlOverdrive5TemperatureGet == NULL ||
83-
adlh->adlOverdrive5FanSpeedGet == NULL
91+
adlh->adlOverdrive5FanSpeedGet == NULL ||
92+
adlh->adl2MainControlCreate == NULL ||
93+
adlh->adl2MainControlRefresh == NULL ||
94+
adlh->adl2MainControlDestroy == NULL ||
95+
adlh->adl2Overdrive6CurrentPowerGet == NULL
8496
) {
8597
#if 0
8698
printf("Failed to obtain all required ADL function pointers\n");
@@ -93,6 +105,11 @@ return NULL;
93105
adlh->adlMainControlCreate(ADL_Main_Memory_Alloc, 1);
94106
adlh->adlMainControlRefresh();
95107

108+
adlh->context = NULL;
109+
110+
adlh->adl2MainControlCreate(ADL_Main_Memory_Alloc, 1, &(adlh->context));
111+
adlh->adl2MainControlRefresh(adlh->context);
112+
96113
int logicalGpuCount = 0;
97114
adlh->adlAdapterNumberOfAdapters(&logicalGpuCount);
98115

@@ -134,6 +151,7 @@ return NULL;
134151
int wrap_adl_destroy(wrap_adl_handle *adlh)
135152
{
136153
adlh->adlMainControlDestroy();
154+
adlh->adl2MainControlDestroy(adlh->context);
137155
wrap_dlclose(adlh->adl_dll);
138156
free(adlh);
139157
return 0;
@@ -188,6 +206,16 @@ int wrap_adl_get_fanpcnt(wrap_adl_handle *adlh, int gpuindex, unsigned int *fanp
188206
return 0;
189207
}
190208

209+
int wrap_adl_get_power_usage(wrap_adl_handle *adlh, int gpuindex, unsigned int *power)
210+
{
211+
wrap_adlReturn_t rc;
212+
if (gpuindex < 0 || gpuindex >= adlh->adl_gpucount){
213+
return -1;
214+
}
215+
rc = adlh->adl2Overdrive6CurrentPowerGet(adlh->context, adlh->phys_logi_device_id[gpuindex], 0, (int*)power);
216+
return rc;
217+
}
218+
191219
#if defined(__cplusplus)
192220
}
193221
#endif

‎libhwmon/wrapadl.h

+19
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
* Wrapper for ADL, inspired by wrapnvml from John E. Stone
33
*
44
* By Philipp Andreas - github@smurfy.de
5+
* ADL power by Davesmacer
56
*/
67

8+
#include "wraphelper.h"
9+
710
#pragma once
811

912
#if defined(__cplusplus)
1013
extern "C" {
1114
#endif
1215

16+
1317
typedef enum wrap_adlReturn_enum {
1418
WRAPADL_OK= 0
1519
} wrap_adlReturn_t;
@@ -24,6 +28,13 @@ typedef enum wrap_adlReturn_enum {
2428
#endif
2529

2630
typedef void* (ADL_API_CALL *ADL_MAIN_MALLOC_CALLBACK)(int);
31+
/// \brief Handle to ADL client context.
32+
///
33+
/// ADL clients obtain context handle from initial call to \ref ADL2_Main_Control_Create.
34+
/// Clients have to pass the handle to each subsequent ADL call and finally destroy
35+
/// the context with call to \ref ADL2_Main_Control_Destroy
36+
/// \nosubgrouping
37+
typedef void* ADL_CONTEXT_HANDLE;
2738

2839
#define ADL_MAX_PATH 256
2940
typedef struct AdapterInfo
@@ -111,6 +122,7 @@ typedef struct {
111122
int adl_gpucount;
112123
int *phys_logi_device_id;
113124
LPAdapterInfo devs;
125+
ADL_CONTEXT_HANDLE context;
114126
wrap_adlReturn_t(*adlMainControlCreate)(ADL_MAIN_MALLOC_CALLBACK, int);
115127
wrap_adlReturn_t(*adlAdapterNumberOfAdapters)(int *);
116128
wrap_adlReturn_t(*adlAdapterAdapterInfoGet)(LPAdapterInfo, int);
@@ -119,6 +131,10 @@ typedef struct {
119131
wrap_adlReturn_t(*adlOverdrive5FanSpeedGet)(int, int, ADLFanSpeedValue*);
120132
wrap_adlReturn_t(*adlMainControlRefresh)(void);
121133
wrap_adlReturn_t(*adlMainControlDestroy)(void);
134+
wrap_adlReturn_t(*adl2MainControlCreate)(ADL_MAIN_MALLOC_CALLBACK, int, ADL_CONTEXT_HANDLE* );
135+
wrap_adlReturn_t(*adl2MainControlDestroy)(ADL_CONTEXT_HANDLE);
136+
wrap_adlReturn_t(*adl2Overdrive6CurrentPowerGet)(ADL_CONTEXT_HANDLE, int, int, int*);
137+
wrap_adlReturn_t(*adl2MainControlRefresh)(ADL_CONTEXT_HANDLE);
122138
} wrap_adl_handle;
123139

124140
wrap_adl_handle * wrap_adl_create();
@@ -132,6 +148,9 @@ int wrap_adl_get_tempC(wrap_adl_handle *adlh, int gpuindex, unsigned int *tempC)
132148

133149
int wrap_adl_get_fanpcnt(wrap_adl_handle *adlh, int gpuindex, unsigned int *fanpcnt);
134150

151+
int wrap_adl_get_power_usage(wrap_adl_handle *adlh, int gpuindex, unsigned int *milliwatts);
152+
153+
135154
#if defined(__cplusplus)
136155
}
137156
#endif

‎libhwmon/wraphelper.h

+23
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,26 @@ static int wrap_dlclose(void *h) {
2929
return dlclose(h);
3030
}
3131
#endif
32+
//Converts from 8 fractional bit int to double (ADL method result format)
33+
static double adlf2double(int adlf){
34+
double res = 0.0;
35+
int fraction = adlf & 0x00FF; //last 8 bits seem to be decimal part
36+
int number = (adlf & 0xFF00) >> 8; //first 8 bits are the integer part
37+
double dfraction = 0; //decimal part
38+
int i = 1;
39+
while(fraction > 0){
40+
double digit = number % 10;
41+
if(fraction >= 100){//256 max value, if 3 digits, divide by 1000
42+
dfraction += (digit / (double)1000.0);
43+
}
44+
else if(fraction >=10){//if 2 digits...
45+
dfraction += (digit / (double)100.0);
46+
}
47+
else {//1 digit
48+
dfraction += (digit / (double)10.0);
49+
}
50+
fraction /= 10; //take it out
51+
}
52+
res = number + dfraction;
53+
return res;
54+
}

0 commit comments

Comments
 (0)
This repository has been archived.