@@ -39,10 +39,56 @@ Farm::Farm(
39
39
{
40
40
#if defined(__linux)
41
41
sysfsh = wrap_amdsysfs_create ();
42
+ if (sysfsh)
43
+ {
44
+ // Build Pci identification mapping as done in miners.
45
+ for (int i = 0 ; i < sysfsh->sysfs_gpucount ; i++)
46
+ {
47
+ std::ostringstream oss;
48
+ std::string uniqueId;
49
+ oss << std::setfill (' 0' ) << std::setw (2 ) << std::hex
50
+ << (unsigned int )sysfsh->sysfs_pci_bus_id [i] << " :" << std::setw (2 )
51
+ << (unsigned int )(sysfsh->sysfs_pci_device_id [i]) << " .0" ;
52
+ uniqueId = oss.str ();
53
+ map_amdsysfs_handle[uniqueId] = i;
54
+ }
55
+ }
56
+
42
57
#else
43
58
adlh = wrap_adl_create ();
59
+ if (adlh)
60
+ {
61
+ // Build Pci identification as done in miners.
62
+ for (int i = 0 ; i < adlh->adl_gpucount ; i++)
63
+ {
64
+ std::ostringstream oss;
65
+ std::string uniqueId;
66
+ oss << std::setfill (' 0' ) << std::setw (2 ) << std::hex
67
+ << (unsigned int )adlh->devs [adlh->phys_logi_device_id [i]].iBusNumber << " :"
68
+ << std::setw (2 )
69
+ << (unsigned int )(adlh->devs [adlh->phys_logi_device_id [i]].iDeviceNumber )
70
+ << " .0" ;
71
+ uniqueId = oss.str ();
72
+ map_adl_handle[uniqueId] = i;
73
+ }
74
+ }
75
+
44
76
#endif
45
77
nvmlh = wrap_nvml_create ();
78
+ if (nvmlh)
79
+ {
80
+ // Build Pci identification as done in miners.
81
+ for (int i = 0 ; i < nvmlh->nvml_gpucount ; i++)
82
+ {
83
+ std::ostringstream oss;
84
+ std::string uniqueId;
85
+ oss << std::setfill (' 0' ) << std::setw (2 ) << std::hex
86
+ << (unsigned int )nvmlh->nvml_pci_bus_id [i] << " :" << std::setw (2 )
87
+ << (unsigned int )(nvmlh->nvml_pci_device_id [i] >> 3 ) << " .0" ;
88
+ uniqueId = oss.str ();
89
+ map_nvml_handle[uniqueId] = i;
90
+ }
91
+ }
46
92
}
47
93
48
94
// Initialize nonce_scrambler
@@ -66,11 +112,12 @@ Farm::~Farm()
66
112
m_collectTimer.cancel ();
67
113
68
114
// Deinit HWMON
69
- if (adlh)
70
- wrap_adl_destroy (adlh);
71
115
#if defined(__linux)
72
116
if (sysfsh)
73
117
wrap_amdsysfs_destroy (sysfsh);
118
+ #else
119
+ if (adlh)
120
+ wrap_adl_destroy (adlh);
74
121
#endif
75
122
if (nvmlh)
76
123
wrap_nvml_destroy (nvmlh);
@@ -122,7 +169,8 @@ void Farm::setWork(WorkPackage const& _newWp)
122
169
{
123
170
// Equally divide the residual segment among miners
124
171
_startNonce = m_currentWp.startNonce ;
125
- m_nonce_segment_with = (unsigned int )log2 (pow (2 , 64 - (m_currentWp.exSizeBytes * 4 )) / m_miners.size ());
172
+ m_nonce_segment_with =
173
+ (unsigned int )log2 (pow (2 , 64 - (m_currentWp.exSizeBytes * 4 )) / m_miners.size ());
126
174
}
127
175
else
128
176
{
@@ -373,59 +421,95 @@ void Farm::collectData(const boost::system::error_code& ec)
373
421
HwMonitorInfo hwInfo = miner->hwmonInfo ();
374
422
HwMonitor hw;
375
423
unsigned int tempC = 0 , fanpcnt = 0 , powerW = 0 ;
376
- if (hwInfo.deviceIndex >= 0 )
424
+
425
+ if (hwInfo.deviceType == HwMonitorInfoType::NVIDIA && nvmlh)
377
426
{
378
- if (hwInfo.deviceType == HwMonitorInfoType::NVIDIA && nvmlh)
427
+ int devIdx = hwInfo.deviceIndex ;
428
+ if (devIdx == -1 && !hwInfo.devicePciId .empty ())
379
429
{
380
- int typeidx = 0 ;
381
- if (hwInfo. indexSource == HwMonitorIndexSource::CUDA)
382
- typeidx = nvmlh-> cuda_nvml_device_id [hwInfo.deviceIndex ];
383
- else if (hwInfo. indexSource == HwMonitorIndexSource::OPENCL)
384
- typeidx = nvmlh-> opencl_nvml_device_id [hwInfo. deviceIndex ];
430
+ if (map_nvml_handle. find (hwInfo. devicePciId ) != map_nvml_handle. end ())
431
+ {
432
+ devIdx = map_nvml_handle [hwInfo.devicePciId ];
433
+ miner-> setHwmonDeviceIndex (devIdx);
434
+ }
385
435
else
386
- typeidx = hwInfo.deviceIndex ; // Unknown, don't map
436
+ {
437
+ // This will prevent further tries to map
438
+ miner->setHwmonDeviceIndex (-2 );
439
+ }
440
+ }
387
441
388
- wrap_nvml_get_tempC (nvmlh, typeidx, &tempC);
389
- wrap_nvml_get_fanpcnt (nvmlh, typeidx, &fanpcnt);
442
+ if (devIdx >= 0 )
443
+ {
444
+ wrap_nvml_get_tempC (nvmlh, devIdx, &tempC);
445
+ wrap_nvml_get_fanpcnt (nvmlh, devIdx, &fanpcnt);
390
446
391
447
if (m_hwmonlvl == 2 )
392
- wrap_nvml_get_power_usage (nvmlh, typeidx , &powerW);
448
+ wrap_nvml_get_power_usage (nvmlh, devIdx , &powerW);
393
449
}
394
- else if (hwInfo.deviceType == HwMonitorInfoType::AMD)
395
- {
396
- int typeidx = 0 ;
450
+ }
451
+ else if (hwInfo.deviceType == HwMonitorInfoType::AMD)
452
+ {
453
+ int devIdx = 0 ;
397
454
#if defined(__linux)
398
- if (sysfsh)
455
+ if (sysfsh)
456
+ {
457
+ devIdx = hwInfo.deviceIndex ;
458
+ if (devIdx == -1 && !hwInfo.devicePciId .empty ())
399
459
{
400
- if (hwInfo.indexSource == HwMonitorIndexSource::OPENCL)
401
- typeidx = sysfsh->opencl_sysfs_device_id [hwInfo.deviceIndex ];
460
+ if (map_amdsysfs_handle.find (hwInfo.devicePciId ) !=
461
+ map_amdsysfs_handle.end ())
462
+ {
463
+ devIdx = map_amdsysfs_handle[hwInfo.devicePciId ];
464
+ miner->setHwmonDeviceIndex (devIdx);
465
+ }
402
466
else
403
- typeidx = hwInfo.deviceIndex ; // Unknown don't map
404
-
405
- wrap_amdsysfs_get_tempC (sysfsh, typeidx, &tempC);
406
- wrap_amdsysfs_get_fanpcnt (sysfsh, typeidx, &fanpcnt);
467
+ {
468
+ // This will prevent further tries to map
469
+ miner->setHwmonDeviceIndex (-2 );
470
+ }
471
+ }
472
+
473
+ if (devIdx >= 0 )
474
+ {
475
+ wrap_amdsysfs_get_tempC (sysfsh, devIdx, &tempC);
476
+ wrap_amdsysfs_get_fanpcnt (sysfsh, devIdx, &fanpcnt);
407
477
408
478
if (m_hwmonlvl == 2 )
409
- wrap_amdsysfs_get_power_usage (sysfsh, typeidx , &powerW);
479
+ wrap_amdsysfs_get_power_usage (sysfsh, devIdx , &powerW);
410
480
}
481
+ }
411
482
#else
412
- if (adlh) // Windows only for AMD
483
+ if (adlh) // Windows only for AMD
484
+ {
485
+ int devIdx = hwInfo.deviceIndex ;
486
+ if (devIdx == -1 && !hwInfo.devicePciId .empty ())
413
487
{
414
- if (hwInfo.indexSource == HwMonitorIndexSource::OPENCL)
415
- typeidx = adlh->opencl_adl_device_id [hwInfo.deviceIndex ];
488
+ if (map_adl_handle.find (hwInfo.devicePciId ) != map_adl_handle.end ())
489
+ {
490
+ devIdx = map_adl_handle[hwInfo.devicePciId ];
491
+ miner->setHwmonDeviceIndex (devIdx);
492
+ }
416
493
else
417
- typeidx = hwInfo.deviceIndex ; // Unknown don't map
494
+ {
495
+ // This will prevent further tries to map
496
+ miner->setHwmonDeviceIndex (-2 );
497
+ }
498
+ }
418
499
419
- wrap_adl_get_tempC (adlh, typeidx, &tempC);
420
- wrap_adl_get_fanpcnt (adlh, typeidx, &fanpcnt);
500
+ if (devIdx >= 0 )
501
+ {
502
+ wrap_adl_get_tempC (adlh, devIdx, &tempC);
503
+ wrap_adl_get_fanpcnt (adlh, devIdx, &fanpcnt);
421
504
422
505
if (m_hwmonlvl == 2 )
423
- wrap_adl_get_power_usage (adlh, typeidx , &powerW);
506
+ wrap_adl_get_power_usage (adlh, devIdx , &powerW);
424
507
}
425
- #endif
426
508
}
509
+ #endif
427
510
}
428
511
512
+
429
513
// If temperature control has been enabled call
430
514
// check threshold
431
515
if (m_tstop)
0 commit comments