Browse Source

cpu & opencl: Respect scan-serial auto/noauto instructions

Luke Dashjr 12 years ago
parent
commit
583cf156e8
4 changed files with 29 additions and 9 deletions
  1. 14 5
      driver-cpu.c
  2. 12 3
      driver-opencl.c
  3. 1 1
      fpgautils.c
  4. 2 0
      fpgautils.h

+ 14 - 5
driver-cpu.c

@@ -30,6 +30,7 @@
 #include <libgen.h>
 #include <libgen.h>
 
 
 #include "compat.h"
 #include "compat.h"
+#include "fpgautils.h"
 #include "miner.h"
 #include "miner.h"
 #include "bench_block.h"
 #include "bench_block.h"
 #include "driver-cpu.h"
 #include "driver-cpu.h"
@@ -709,7 +710,7 @@ char *force_nthreads_int(const char *arg, int *i)
 #endif
 #endif
 
 
 #ifdef WANT_CPUMINE
 #ifdef WANT_CPUMINE
-static void cpu_detect()
+static int cpu_autodetect()
 {
 {
 	int i;
 	int i;
 
 
@@ -745,13 +746,10 @@ static void cpu_detect()
 	#endif /* !WIN32 */
 	#endif /* !WIN32 */
 
 
 	if (opt_n_threads < 0 || !forced_n_threads) {
 	if (opt_n_threads < 0 || !forced_n_threads) {
-		if ((total_devices || total_devices_new) && !opt_usecpu)
-			opt_n_threads = 0;
-		else
 			opt_n_threads = num_processors;
 			opt_n_threads = num_processors;
 	}
 	}
 	if (num_processors < 1)
 	if (num_processors < 1)
-		return;
+		return 0;
 
 
 	cpus = calloc(opt_n_threads, sizeof(struct cgpu_info));
 	cpus = calloc(opt_n_threads, sizeof(struct cgpu_info));
 	if (unlikely(!cpus))
 	if (unlikely(!cpus))
@@ -767,6 +765,17 @@ static void cpu_detect()
 		cgpu->kname = algo_names[opt_algo];
 		cgpu->kname = algo_names[opt_algo];
 		add_cgpu(cgpu);
 		add_cgpu(cgpu);
 	}
 	}
+	return opt_n_threads;
+}
+
+static void cpu_detect()
+{
+	if ((opt_n_threads < 0 || !forced_n_threads)
+	 && ((total_devices || total_devices_new) && !opt_usecpu))
+		// If there are any other devices, only act if the user has explicitly enabled it
+		noserial_detect_manual(&cpu_drv, cpu_autodetect);
+	else
+		noserial_detect(&cpu_drv, cpu_autodetect);
 }
 }
 
 
 static pthread_mutex_t cpualgo_lock;
 static pthread_mutex_t cpualgo_lock;

+ 12 - 3
driver-opencl.c

@@ -39,6 +39,7 @@
 #define OMIT_OPENCL_API
 #define OMIT_OPENCL_API
 
 
 #include "compat.h"
 #include "compat.h"
+#include "fpgautils.h"
 #include "miner.h"
 #include "miner.h"
 #include "driver-opencl.h"
 #include "driver-opencl.h"
 #include "findnonce.h"
 #include "findnonce.h"
@@ -1408,7 +1409,7 @@ void *reinit_gpu(__maybe_unused void *userdata)
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 struct device_drv opencl_api;
 struct device_drv opencl_api;
 
 
-static void opencl_detect()
+static int opencl_autodetect()
 {
 {
 #ifndef WIN32
 #ifndef WIN32
 	if (!getenv("DISPLAY")) {
 	if (!getenv("DISPLAY")) {
@@ -1419,7 +1420,7 @@ static void opencl_detect()
 
 
 	if (!load_opencl_symbols()) {
 	if (!load_opencl_symbols()) {
 		nDevs = 0;
 		nDevs = 0;
-		return;
+		return 0;
 	}
 	}
 
 
 
 
@@ -1432,7 +1433,7 @@ static void opencl_detect()
 	}
 	}
 
 
 	if (!nDevs)
 	if (!nDevs)
-		return;
+		return 0;
 
 
 	/* If opt_g_threads is not set, use default 1 thread on scrypt and
 	/* If opt_g_threads is not set, use default 1 thread on scrypt and
 	 * 2 for regular mining */
 	 * 2 for regular mining */
@@ -1478,6 +1479,14 @@ static void opencl_detect()
 
 
 	if (!opt_noadl)
 	if (!opt_noadl)
 		init_adl(nDevs);
 		init_adl(nDevs);
+	
+	return nDevs;
+}
+
+static void opencl_detect()
+{
+	// This wrapper ensures users can specify -S opencl:noauto to disable it
+	noserial_detect(&opencl_api, opencl_autodetect);
 }
 }
 
 
 static void reinit_opencl_device(struct cgpu_info *gpu)
 static void reinit_opencl_device(struct cgpu_info *gpu)

+ 1 - 1
fpgautils.c

@@ -365,7 +365,7 @@ int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_
 {
 {
 	struct string_elist *iter, *tmp;
 	struct string_elist *iter, *tmp;
 	const char *dev, *colon;
 	const char *dev, *colon;
-	bool inhibitauto = false;
+	bool inhibitauto = flags & 4;
 	char found = 0;
 	char found = 0;
 	bool forceauto = flags & 1;
 	bool forceauto = flags & 1;
 	bool hasname;
 	bool hasname;

+ 2 - 0
fpgautils.h

@@ -25,6 +25,8 @@ extern int _serial_detect(struct device_drv *api, detectone_func_t, autoscan_fun
 	_serial_detect(api, detectone,     NULL, 2)
 	_serial_detect(api, detectone,     NULL, 2)
 #define noserial_detect(api, autoscan)  \
 #define noserial_detect(api, autoscan)  \
 	_serial_detect(api, NULL     , autoscan, 0)
 	_serial_detect(api, NULL     , autoscan, 0)
+#define noserial_detect_manual(api, autoscan)  \
+	_serial_detect(api, NULL     , autoscan, 4)
 extern int _serial_autodetect(detectone_func_t, ...);
 extern int _serial_autodetect(detectone_func_t, ...);
 #define serial_autodetect(...)  _serial_autodetect(__VA_ARGS__, NULL)
 #define serial_autodetect(...)  _serial_autodetect(__VA_ARGS__, NULL)