Reorder displayed devices to map to physical locations and initialise according to logical location instead.
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
diff --git a/adl.c b/adl.c
index 373e1ee..dae10b5 100644
--- a/adl.c
+++ b/adl.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <curses.h>
+#include <string.h>
#include "miner.h"
#include "ADL_SDK/adl_sdk.h"
@@ -94,7 +95,7 @@ static inline void unlock_adl(void)
/* This looks for the twin GPU that has the fanspeed control of a non fanspeed
* control GPU on dual GPU cards */
-static inline bool fanspeed_twin(struct gpu_adl *ga, struct gpu_adl *other_ga)
+static bool fanspeed_twin(struct gpu_adl *ga, struct gpu_adl *other_ga)
{
if (!other_ga->has_fanspeed)
return false;
@@ -105,9 +106,35 @@ static inline 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;
#if defined (LINUX)
hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
@@ -395,8 +422,14 @@ void init_adl(int nDevs)
}
}
}
- applog(LOG_INFO, "GPU %d mapped to virtual GPU %d", gpu, cgpu->virtual_gpu);
+ 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)
diff --git a/adl.h b/adl.h
index c7341e2..50bd5b8 100644
--- a/adl.h
+++ b/adl.h
@@ -20,18 +20,8 @@ void change_gpusettings(int gpu);
void gpu_autotune(int gpu, bool *enable);
void clear_adl(int nDevs);
#else /* HAVE_ADL */
-#include "miner.h"
#define adl_active (0)
-static inline void init_adl(int nDevs)
-{
- int i;
-
- for (i = 0; i < nDevs; i++) {
- struct cgpu_info *cgpu = &gpus[i];
-
- cgpu->virtual_gpu = i;
- }
-}
+static inline void init_adl(int nDevs) {}
static inline void change_gpusettings(int gpu) { }
static inline void clear_adl(int nDevs) {}
#endif
diff --git a/main.c b/main.c
index de544cd..51f70d2 100644
--- a/main.c
+++ b/main.c
@@ -4837,6 +4837,8 @@ select_cgpu:
cgpu->enabled = true;
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
+ int virtual_gpu;
+
thr = &thr_info[thr_id];
cgpu = thr->cgpu;
if (cgpu->api != &opencl_api)
@@ -4844,6 +4846,7 @@ select_cgpu:
if (dev_from_id(thr_id) != gpu)
continue;
+ virtual_gpu = cgpu->virtual_gpu;
/* Lose this ram cause we may get stuck here! */
//tq_freeze(thr->q);
@@ -4855,7 +4858,7 @@ select_cgpu:
//free(clState);
applog(LOG_INFO, "Reinit GPU thread %d", thr_id);
- clStates[thr_id] = initCl(gpu, name, sizeof(name));
+ clStates[thr_id] = initCl(virtual_gpu, name, sizeof(name));
if (!clStates[thr_id]) {
applog(LOG_ERR, "Failed to reinit GPU thread %d", thr_id);
goto select_cgpu;
@@ -5524,16 +5527,15 @@ static void opencl_detect()
nDevs = clDevicesNum();
if (nDevs < 0) {
- applog(LOG_ERR, "clDevicesNum returned error, none usable");
+ applog(LOG_ERR, "clDevicesNum returned error, no GPUs usable");
nDevs = 0;
}
if (MAX_DEVICES - total_devices < nDevs)
nDevs = MAX_DEVICES - total_devices;
- if (!nDevs) {
+ if (!nDevs)
return;
- }
if (opt_kernel) {
if (strcmp(opt_kernel, "poclbm") && strcmp(opt_kernel, "phatk"))
@@ -5547,12 +5549,16 @@ static void opencl_detect()
for (i = 0; i < nDevs; ++i) {
struct cgpu_info *cgpu;
+
cgpu = devices[total_devices++] = &gpus[i];
cgpu->enabled = true;
cgpu->api = &opencl_api;
cgpu->device_id = i;
cgpu->threads = opt_g_threads;
}
+
+ if (!opt_noadl)
+ init_adl(nDevs);
}
static void reinit_opencl_device(struct cgpu_info *gpu)
@@ -5604,6 +5610,7 @@ static bool opencl_thread_prepare(struct thr_info *thr)
struct timeval now;
struct cgpu_info *cgpu = thr->cgpu;
int gpu = cgpu->device_id;
+ int virtual_gpu = cgpu->virtual_gpu;
int i = thr->id;
static bool failmessage = false;
@@ -5614,8 +5621,8 @@ static bool opencl_thread_prepare(struct thr_info *thr)
return false;
}
- applog(LOG_INFO, "Init GPU thread %i", i);
- clStates[i] = initCl(gpu, name, sizeof(name));
+ applog(LOG_INFO, "Init GPU thread %i GPU %i virtual GPU %i", i, gpu, virtual_gpu);
+ clStates[i] = initCl(virtual_gpu, name, sizeof(name));
if (!clStates[i]) {
enable_curses();
applog(LOG_ERR, "Failed to init GPU thread %d, disabling device %d", i, gpu);
@@ -6172,10 +6179,7 @@ retry_pools:
gettimeofday(&total_tv_end, NULL);
get_datestamp(datestamp, &total_tv_start);
-#ifdef HAVE_OPENCL
- if (!opt_noadl)
- init_adl(nDevs);
-#else
+#ifndef HAVE_OPENCL
opt_g_threads = 0;
#endif