Iterate and change virtual device order instead of shuffling ram.
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
diff --git a/adl.c b/adl.c
index dae10b5..f9460b8 100644
--- a/adl.c
+++ b/adl.c
@@ -28,6 +28,12 @@ const int opt_overheattemp = 85;
const int opt_cutofftemp = 95;
static pthread_mutex_t adl_lock;
+struct gpu_adapters {
+ int iAdapterIndex;
+ int iBusNumber;
+ int id;
+};
+
// Memory allocation function
static void * __stdcall ADL_Main_Memory_Alloc(int iSize)
{
@@ -106,35 +112,10 @@ static bool fanspeed_twin(struct gpu_adl *ga, struct gpu_adl *other_ga)
return true;
}
-static void reorder_devices(int devices)
-{
- struct cgpu_info base_gpus[MAX_GPUDEVICES];
- struct cgpu_info *cgpu, *base_cgpu;
- int i, j;
-
- memcpy(base_gpus, gpus, sizeof(gpus));
- for (i = 0; i < devices; i++) {
- cgpu = &gpus[i];
-
- for (j = 0; j < devices; j++) {
- base_cgpu = &base_gpus[j];
- if (base_cgpu->virtual_gpu == i) {
- memcpy(cgpu, base_cgpu, sizeof(struct cgpu_info));
- /* Swap the parameters so the device displayed
- * matches its physical location, but its
- * initialised from its virtual location */
- cgpu->device_id = base_cgpu->virtual_gpu;
- cgpu->virtual_gpu = base_cgpu->device_id;
- break;
- }
- }
- }
-}
-
void init_adl(int nDevs)
{
int i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
- bool map_devices = false;
+ struct gpu_adapters adapters[nDevs], vadapters[nDevs];
#if defined (LINUX)
hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
@@ -220,12 +201,10 @@ void init_adl(int nDevs)
return;
}
+ /* Iterate over iNumberAdapters and find the lpAdapterID of real devices */
for (i = 0; i < iNumberAdapters; i++) {
- struct gpu_adl *ga;
int iAdapterIndex;
int lpAdapterID;
- ADLODPerformanceLevels *lpOdPerformanceLevels;
- int lev;
iAdapterIndex = lpInfo[i].iAdapterIndex;
/* Get unique identifier of the adapter, 0 means not AMD */
@@ -238,21 +217,53 @@ void init_adl(int nDevs)
if (lpAdapterID == last_adapter)
continue;
+ adapters[devices].iAdapterIndex = iAdapterIndex;
+ adapters[devices].iBusNumber = lpInfo[i].iBusNumber;
+ adapters[devices].id = i;
+
/* We found a truly new adapter instead of a logical
- * one. Now since there's no way of correlating the
- * opencl enumerated devices and the ADL enumerated
- * ones, we have to assume they're in the same order.*/
+ * one. Now since there's no way of correlating the
+ * opencl enumerated devices and the ADL enumerated
+ * ones, we have to assume they're in the same order.*/
if (++devices > nDevs) {
applog(LOG_ERR, "ADL found more devices than opencl");
return;
}
- gpu = devices - 1;
last_adapter = lpAdapterID;
if (!lpAdapterID) {
applog(LOG_INFO, "Adapter returns ID 0 meaning not AMD. Card order might be confused");
continue;
}
+ }
+
+ for (i = 0; i < devices; i++) {
+ int j, virtual_gpu = 0;
+
+ for (j = 0; j < devices; j++) {
+ if (i == j)
+ continue;
+ if (adapters[j].iBusNumber < adapters[i].iBusNumber)
+ virtual_gpu++;
+ }
+ vadapters[virtual_gpu].id = adapters[i].id;
+ }
+
+ for (gpu = 0; gpu < devices; gpu++) {
+ struct gpu_adl *ga;
+ int iAdapterIndex;
+ int lpAdapterID;
+ ADLODPerformanceLevels *lpOdPerformanceLevels;
+ int lev;
+
+ i = vadapters[gpu].id;
+ iAdapterIndex = lpInfo[i].iAdapterIndex;
+
+ /* Get unique identifier of the adapter, 0 means not AMD */
+ if (ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID) != ADL_OK) {
+ applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get");
+ continue;
+ }
if (!gpus[gpu].enabled) {
gpus[i].gpu_engine =
@@ -393,10 +404,8 @@ void init_adl(int nDevs)
for (gpu = 0; gpu < devices; gpu++) {
struct gpu_adl *ga = &gpus[gpu].adl;
- struct cgpu_info *cgpu = &gpus[gpu];
int j;
- cgpu->virtual_gpu = 0;
for (j = 0; j < devices; j++) {
struct gpu_adl *other_ga;
@@ -405,11 +414,6 @@ void init_adl(int nDevs)
other_ga = &gpus[j].adl;
- /* Find the real GPU order based on their order
- * according to their iBusNumber value */
- if (other_ga->iBusNumber < ga->iBusNumber)
- cgpu->virtual_gpu++;
-
/* Search for twin GPUs on a single card. They will be
* separated by one bus id and one will have fanspeed
* while the other won't. */
@@ -422,14 +426,7 @@ void init_adl(int nDevs)
}
}
}
- if (cgpu->virtual_gpu != gpu) {
- map_devices = true;
- applog(LOG_INFO, "GPU %d mapped to virtual GPU %d", gpu, cgpu->virtual_gpu);
- }
}
-
- if (map_devices)
- reorder_devices(devices);
}
static float __gpu_temp(struct gpu_adl *ga)