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

Commit b81dcde

Browse files
authored
Merge pull request #770 from Davesmacer/mixed-fix
Mixed multiple AMD+NVIDIA fix
2 parents 5bfae73 + e229e8e commit b81dcde

File tree

12 files changed

+329
-24
lines changed

12 files changed

+329
-24
lines changed

ethminer/MinerAux.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ class MinerCLI
648648
<< " 1: eth-proxy compatible: dwarfpool, f2pool, nanopool (required for hashrate reporting to work with nanopool)" << endl
649649
<< " 2: EthereumStratum/1.0.0: nicehash" << endl
650650
<< " -RH, --report-hashrate Report current hashrate to pool (please only enable on pools supporting this)" << endl
651-
<< " -HWMON [n] Displays gpu temp, fan percent and power usage. Note: In linux, the program uses sysfs, which may require running with root priviledges." << endl
651+
<< " -HWMON [<n>], Displays gpu temp, fan percent and power usage. Note: In linux, the program uses sysfs, which may require running with root priviledges." << endl
652652
<< " 0: Displays only temp and fan percent (default)" << endl
653653
<< " 1: Also displays power usage" << endl
654654
<< " --exit Stops the miner whenever an error is encountered" << endl
@@ -665,7 +665,7 @@ class MinerCLI
665665
<< "Mining configuration:" << endl
666666
<< " -G,--opencl When mining use the GPU via OpenCL." << endl
667667
<< " -U,--cuda When mining use the GPU via CUDA." << endl
668-
<< " -X,--cuda-opencl Use OpenCL + CUDA in a system with mixed AMD/Nvidia cards. May require setting --opencl-platform 1" << endl
668+
<< " -X,--cuda-opencl Use OpenCL + CUDA in a system with mixed AMD/Nvidia cards. May require setting --opencl-platform 1 or 2. Use --list-devices option to check which platform is your AMD. " << endl
669669
<< " --opencl-platform <n> When mining using -G/--opencl use OpenCL platform n (default: 0)." << endl
670670
<< " --opencl-device <n> When mining using -G/--opencl use OpenCL device n (default: 0)." << endl
671671
<< " --opencl-devices <0 1 ..n> Select which OpenCL devices to mine on. Default is to use all" << endl

libethash-cl/CLMiner.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,13 @@ bool CLMiner::init(const h256& seed)
531531
{
532532
platformId = OPENCL_PLATFORM_NVIDIA;
533533
m_hwmoninfo.deviceType = HwMonitorInfoType::NVIDIA;
534+
m_hwmoninfo.indexSource = HwMonitorIndexSource::OPENCL;
534535
}
535536
else if (platformName == "AMD Accelerated Parallel Processing")
536537
{
537538
platformId = OPENCL_PLATFORM_AMD;
538539
m_hwmoninfo.deviceType = HwMonitorInfoType::AMD;
540+
m_hwmoninfo.indexSource = HwMonitorIndexSource::OPENCL;
539541
}
540542
else if (platformName == "Clover")
541543
{
@@ -552,9 +554,10 @@ bool CLMiner::init(const h256& seed)
552554
}
553555

554556
// use selected device
555-
unsigned deviceId = s_devices[index] > -1 ? s_devices[index] : index;
556-
m_hwmoninfo.deviceIndex = deviceId;
557-
cl::Device& device = devices[min<unsigned>(deviceId, devices.size() - 1)];
557+
int idx = index % devices.size();
558+
unsigned deviceId = s_devices[idx] > -1 ? s_devices[idx] : index;
559+
m_hwmoninfo.deviceIndex = deviceId % devices.size();
560+
cl::Device& device = devices[deviceId % devices.size()];
558561
string device_version = device.getInfo<CL_DEVICE_VERSION>();
559562
ETHCL_LOG("Device: " << device.getInfo<CL_DEVICE_NAME>() << " / " << device_version);
560563

libethash-cuda/CUDAMiner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ bool CUDAMiner::cuda_init(
328328
// use selected device
329329
m_device_num = _deviceId < numDevices -1 ? _deviceId : numDevices - 1;
330330
m_hwmoninfo.deviceType = HwMonitorInfoType::NVIDIA;
331+
m_hwmoninfo.indexSource = HwMonitorIndexSource::CUDA;
331332
m_hwmoninfo.deviceIndex = m_device_num;
332333

333334
cudaDeviceProp device_props;

libethcore/Farm.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Farm: public FarmFace
132132
}
133133
else
134134
{
135+
135136
start = m_miners.size();
136137
ins += start;
137138
m_miners.reserve(ins);
@@ -259,30 +260,56 @@ class Farm: public FarmFace
259260
if (hwmon) {
260261
HwMonitorInfo hwInfo = i->hwmonInfo();
261262
HwMonitor hw;
262-
hw.powerW = 0.0;
263263
unsigned int tempC = 0, fanpcnt = 0, powerW = 0;
264264
if (hwInfo.deviceIndex >= 0) {
265265
if (hwInfo.deviceType == HwMonitorInfoType::NVIDIA && nvmlh) {
266-
wrap_nvml_get_tempC(nvmlh, hwInfo.deviceIndex, &tempC);
267-
wrap_nvml_get_fanpcnt(nvmlh, hwInfo.deviceIndex, &fanpcnt);
266+
int typeidx = 0;
267+
if(hwInfo.indexSource == HwMonitorIndexSource::CUDA){
268+
typeidx = nvmlh->cuda_nvml_device_id[hwInfo.deviceIndex];
269+
}
270+
else if(hwInfo.indexSource == HwMonitorIndexSource::OPENCL){
271+
typeidx = nvmlh->opencl_nvml_device_id[hwInfo.deviceIndex];
272+
}
273+
else{
274+
//Unknown, don't map
275+
typeidx = hwInfo.deviceIndex;
276+
}
277+
wrap_nvml_get_tempC(nvmlh, typeidx, &tempC);
278+
wrap_nvml_get_fanpcnt(nvmlh, typeidx, &fanpcnt);
268279
if(power) {
269-
wrap_nvml_get_power_usage(nvmlh, hwInfo.deviceIndex, &powerW);
280+
wrap_nvml_get_power_usage(nvmlh, typeidx, &powerW);
270281
}
271282
}
272283
else if (hwInfo.deviceType == HwMonitorInfoType::AMD && adlh) {
273-
wrap_adl_get_tempC(adlh, hwInfo.deviceIndex, &tempC);
274-
wrap_adl_get_fanpcnt(adlh, hwInfo.deviceIndex, &fanpcnt);
284+
int typeidx = 0;
285+
if(hwInfo.indexSource == HwMonitorIndexSource::OPENCL){
286+
typeidx = adlh->opencl_adl_device_id[hwInfo.deviceIndex];
287+
}
288+
else{
289+
//Unknown, don't map
290+
typeidx = hwInfo.deviceIndex;
291+
}
292+
wrap_adl_get_tempC(adlh, typeidx, &tempC);
293+
wrap_adl_get_fanpcnt(adlh, typeidx, &fanpcnt);
275294
if(power) {
276-
wrap_adl_get_power_usage(adlh, hwInfo.deviceIndex, &powerW);
295+
wrap_adl_get_power_usage(adlh, typeidx, &powerW);
277296
}
278297
}
279298
#if defined(__linux)
280299
// Overwrite with sysfs data if present
281300
if (hwInfo.deviceType == HwMonitorInfoType::AMD && sysfsh) {
282-
wrap_amdsysfs_get_tempC(sysfsh, hwInfo.deviceIndex, &tempC);
283-
wrap_amdsysfs_get_fanpcnt(sysfsh, hwInfo.deviceIndex, &fanpcnt);
301+
int typeidx = 0;
302+
if(hwInfo.indexSource == HwMonitorIndexSource::OPENCL){
303+
typeidx = sysfsh->opencl_sysfs_device_id[hwInfo.deviceIndex];
304+
}
305+
else{
306+
//Unknown, don't map
307+
typeidx = hwInfo.deviceIndex;
308+
}
309+
wrap_amdsysfs_get_tempC(sysfsh, typeidx, &tempC);
310+
wrap_amdsysfs_get_fanpcnt(sysfsh, typeidx, &fanpcnt);
284311
if(power) {
285-
wrap_amdsysfs_get_power_usage(sysfsh, hwInfo.deviceIndex, &powerW);
312+
wrap_amdsysfs_get_power_usage(sysfsh, typeidx, &powerW);
286313
}
287314
}
288315
#endif

libethcore/Miner.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,19 @@ enum class HwMonitorInfoType
7070
AMD
7171
};
7272

73+
enum class HwMonitorIndexSource
74+
{
75+
UNKNOWN,
76+
OPENCL,
77+
CUDA
78+
};
79+
7380
struct HwMonitorInfo
7481
{
7582
HwMonitorInfoType deviceType = HwMonitorInfoType::UNKNOWN;
83+
HwMonitorIndexSource indexSource = HwMonitorIndexSource::UNKNOWN;
7684
int deviceIndex = -1;
85+
7786
};
7887

7988
struct HwMonitor

libhwmon/wrapadl.cpp

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <stdio.h>
77
#include <stdlib.h>
88
#include <string.h>
9+
#include <string>
10+
#include "wraphelper.h"
911
#include "wrapadl.h"
1012

1113
#if defined(__cplusplus)
@@ -114,10 +116,11 @@ return NULL;
114116
adlh->adlAdapterNumberOfAdapters(&logicalGpuCount);
115117

116118
adlh->phys_logi_device_id = (int*)calloc(logicalGpuCount, sizeof(int));
117-
119+
118120
adlh->adl_gpucount = 0;
119121
int last_adapter = 0;
120122
if (logicalGpuCount > 0) {
123+
adlh->log_gpucount = logicalGpuCount;
121124
adlh->devs = (LPAdapterInfo)malloc(sizeof(AdapterInfo) * logicalGpuCount);
122125
memset(adlh->devs, '\0', sizeof(AdapterInfo) * logicalGpuCount);
123126

@@ -140,11 +143,65 @@ return NULL;
140143
if (adapterID == last_adapter) {
141144
continue;
142145
}
146+
143147
last_adapter = adapterID;
144148
adlh->adl_gpucount++;
145149
}
146150
}
147151

152+
153+
adlh->adl_opencl_device_id = (int*) calloc(adlh->adl_gpucount, sizeof(int));
154+
#if ETH_ETHASHCL
155+
if(adlh->adl_gpucount > 0){
156+
//Get and count OpenCL devices.
157+
adlh->opencl_gpucount = 0;
158+
std::vector<cl::Platform> platforms;
159+
cl::Platform::get(&platforms);
160+
std::vector<cl::Device> platdevs;
161+
for(unsigned p = 0; p<platforms.size(); p++){
162+
std::string platformName = platforms[p].getInfo<CL_PLATFORM_NAME>();
163+
if (platformName == "AMD Accelerated Parallel Processing") {
164+
platforms[p].getDevices(
165+
CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR,
166+
&platdevs
167+
);
168+
adlh->opencl_gpucount = platdevs.size();
169+
break;
170+
}
171+
}
172+
adlh->opencl_adl_device_id = (int*) calloc(adlh->opencl_gpucount, sizeof(int));
173+
174+
//Map ADL phys device id to Opencl
175+
for(int i = 0; i<adlh->adl_gpucount; i++){
176+
for(unsigned j = 0; j<platdevs.size(); j++){
177+
cl::Device cldev = platdevs[j];
178+
cl_device_topology_amd topology;
179+
int status = clGetDeviceInfo (cldev(), CL_DEVICE_TOPOLOGY_AMD,
180+
sizeof(cl_device_topology_amd), &topology, NULL);
181+
if(status == CL_SUCCESS) {
182+
if (topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) {
183+
if(adlh->devs[adlh->phys_logi_device_id[i]].iBusNumber == (int)topology.pcie.bus
184+
&& adlh->devs[adlh->phys_logi_device_id[i]].iDeviceNumber == (int)topology.pcie.device
185+
&& adlh->devs[adlh->phys_logi_device_id[i]].iFunctionNumber == (int)topology.pcie.function){
186+
#if 0
187+
printf("[DEBUG] - ADL GPU[%d]%d,%d,%d matches OpenCL GPU[%d]%d,%d,%d\n",
188+
adlh->phys_logi_device_id[i],
189+
adlh->devs[adlh->phys_logi_device_id[i]].iBusNumber,
190+
adlh->devs[adlh->phys_logi_device_id[i]].iDeviceNumber,
191+
adlh->devs[adlh->phys_logi_device_id[i]].iFunctionNumber,
192+
j, (int)topology.pcie.bus, (int)topology.pcie.device, (int)topology.pcie.function);
193+
#endif
194+
adlh->adl_opencl_device_id[i] = j;
195+
adlh->opencl_adl_device_id[j] = i;
196+
}
197+
}
198+
}
199+
200+
}
201+
}
202+
}
203+
#endif
204+
148205
return adlh;
149206
}
150207

@@ -172,6 +229,22 @@ int wrap_adl_get_gpu_name(wrap_adl_handle *adlh, int gpuindex, char *namebuf, in
172229
return 0;
173230
}
174231

232+
int wrap_adl_get_gpu_pci_id(wrap_adl_handle *adlh, int gpuindex, char *idbuf, int bufsize)
233+
{
234+
if (gpuindex < 0 || gpuindex >= adlh->adl_gpucount){
235+
return -1;
236+
}
237+
char buf[256];
238+
sprintf(
239+
buf,
240+
"%04x:%02x:%02x",
241+
0, // Is probably 0
242+
adlh->devs[adlh->phys_logi_device_id[gpuindex]].iBusNumber,
243+
adlh->devs[adlh->phys_logi_device_id[gpuindex]].iDeviceNumber
244+
);
245+
memcpy(idbuf, buf, bufsize);
246+
return 0;
247+
}
175248

176249
int wrap_adl_get_tempC(wrap_adl_handle *adlh, int gpuindex, unsigned int *tempC)
177250
{
@@ -209,9 +282,9 @@ int wrap_adl_get_fanpcnt(wrap_adl_handle *adlh, int gpuindex, unsigned int *fanp
209282
int wrap_adl_get_power_usage(wrap_adl_handle *adlh, int gpuindex, unsigned int* miliwatts)
210283
{
211284
wrap_adlReturn_t rc;
212-
if (gpuindex < 0 || gpuindex >= adlh->adl_gpucount){
285+
if (gpuindex < 0 || gpuindex >= adlh->adl_gpucount)
213286
return -1;
214-
}
287+
215288
int power = 0;
216289
rc = adlh->adl2Overdrive6CurrentPowerGet(adlh->context, adlh->phys_logi_device_id[gpuindex], 0, &power);
217290
*miliwatts = power * 3.90625;

libhwmon/wrapadl.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
* By Philipp Andreas - [email protected]
55
* ADL power by Davesmacer
66
*/
7-
8-
#include "wraphelper.h"
9-
107
#pragma once
118

129
#if defined(__cplusplus)
1310
extern "C" {
1411
#endif
1512

16-
1713
typedef enum wrap_adlReturn_enum {
1814
WRAPADL_OK= 0
1915
} wrap_adlReturn_t;
@@ -120,9 +116,13 @@ typedef struct ADLFanSpeedValue
120116
typedef struct {
121117
void *adl_dll;
122118
int adl_gpucount;
119+
int log_gpucount;
120+
int opencl_gpucount;
123121
int *phys_logi_device_id;
124122
LPAdapterInfo devs;
125123
ADL_CONTEXT_HANDLE context;
124+
int *adl_opencl_device_id; /* map ADL dev to OPENCL dev */
125+
int *opencl_adl_device_id; /* map OPENCL dev to ADL dev */
126126
wrap_adlReturn_t(*adlMainControlCreate)(ADL_MAIN_MALLOC_CALLBACK, int);
127127
wrap_adlReturn_t(*adlAdapterNumberOfAdapters)(int *);
128128
wrap_adlReturn_t(*adlAdapterAdapterInfoGet)(LPAdapterInfo, int);
@@ -144,6 +144,8 @@ int wrap_adl_get_gpucount(wrap_adl_handle *adlh, int *gpucount);
144144

145145
int wrap_adl_get_gpu_name(wrap_adl_handle *adlh, int gpuindex, char *namebuf, int bufsize);
146146

147+
int wrap_adl_get_gpu_pci_id(wrap_adl_handle *adlh, int gpuindex, char *idbuf, int bufsize);
148+
147149
int wrap_adl_get_tempC(wrap_adl_handle *adlh, int gpuindex, unsigned int *tempC);
148150

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

0 commit comments

Comments
 (0)