Browse Source

Merge pull request #157 from luke-jr/unify_drivers

Unify drivers as driver-*.c and add driver name to API
Con Kolivas 13 years ago
parent
commit
7b947882fe
17 changed files with 91 additions and 28 deletions
  1. 4 4
      Makefile.am
  2. 3 0
      adl.c
  3. 1 1
      api.c
  4. 32 3
      cgminer.c
  5. 9 5
      driver-bitforce.c
  6. 5 4
      driver-cpu.c
  7. 0 0
      driver-cpu.h
  8. 3 3
      driver-icarus.c
  9. 23 2
      driver-opencl.c
  10. 0 0
      driver-opencl.h
  11. 5 0
      miner.h
  12. 1 1
      sha256_4way.c
  13. 1 1
      sha256_altivec_4way.c
  14. 1 1
      sha256_sse2_amd64.c
  15. 1 1
      sha256_sse2_i386.c
  16. 1 1
      sha256_sse4_amd64.c
  17. 1 1
      sha256_via.c

+ 4 - 4
Makefile.am

@@ -37,7 +37,7 @@ cgminer_SOURCES	+= logging.c
 
 
 # GPU sources, TODO: make them selectable
 # GPU sources, TODO: make them selectable
 # the GPU portion extracted from original main.c
 # the GPU portion extracted from original main.c
-cgminer_SOURCES += device-gpu.h device-gpu.c
+cgminer_SOURCES += driver-opencl.h driver-opencl.c
 
 
 # the original GPU related sources, unchanged
 # the original GPU related sources, unchanged
 cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
 cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
@@ -53,7 +53,7 @@ cgminer_SOURCES	+= \
 		  sha256_altivec_4way.c
 		  sha256_altivec_4way.c
 
 
 # the CPU portion extracted from original main.c
 # the CPU portion extracted from original main.c
-cgminer_SOURCES += device-cpu.h device-cpu.c
+cgminer_SOURCES += driver-cpu.h driver-cpu.c
 
 
 if HAS_YASM
 if HAS_YASM
 AM_CFLAGS	= -DHAS_YASM
 AM_CFLAGS	= -DHAS_YASM
@@ -68,9 +68,9 @@ endif # HAS_YASM
 endif # HAS_CPUMINE
 endif # HAS_CPUMINE
 
 
 if HAS_BITFORCE
 if HAS_BITFORCE
-cgminer_SOURCES += bitforce.c
+cgminer_SOURCES += driver-bitforce.c
 endif
 endif
 
 
 if HAS_ICARUS
 if HAS_ICARUS
-cgminer_SOURCES += icarus.c
+cgminer_SOURCES += driver-icarus.c
 endif
 endif

+ 3 - 0
adl.c

@@ -352,6 +352,9 @@ void init_adl(int nDevs)
 		}
 		}
 
 
 		applog(LOG_INFO, "GPU %d %s hardware monitoring enabled", gpu, lpInfo[i].strAdapterName);
 		applog(LOG_INFO, "GPU %d %s hardware monitoring enabled", gpu, lpInfo[i].strAdapterName);
+		if (gpus[gpu].name)
+			free(gpus[gpu].name);
+		gpus[gpu].name = lpInfo[i].strAdapterName;
 		gpus[gpu].has_adl = true;
 		gpus[gpu].has_adl = true;
 		/* Flag adl as active if any card is successfully activated */
 		/* Flag adl as active if any card is successfully activated */
 		adl_active = true;
 		adl_active = true;

+ 1 - 1
api.c

@@ -25,7 +25,7 @@
 
 
 #include "compat.h"
 #include "compat.h"
 #include "miner.h"
 #include "miner.h"
-#include "device-cpu.h" /* for algo_names[], TODO: re-factor dependency */
+#include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 
 
 #if defined(unix) || defined(__APPLE__)
 #if defined(unix) || defined(__APPLE__)
 	#include <errno.h>
 	#include <errno.h>

+ 32 - 3
cgminer.c

@@ -44,8 +44,8 @@
 #include "miner.h"
 #include "miner.h"
 #include "findnonce.h"
 #include "findnonce.h"
 #include "adl.h"
 #include "adl.h"
-#include "device-cpu.h"
-#include "device-gpu.h"
+#include "driver-cpu.h"
+#include "driver-opencl.h"
 #include "bench_block.h"
 #include "bench_block.h"
 
 
 #if defined(unix)
 #if defined(unix)
@@ -4425,6 +4425,31 @@ void enable_device(struct cgpu_info *cgpu)
 #endif
 #endif
 }
 }
 
 
+struct _cgpu_devid_counter {
+	char name[4];
+	int lastid;
+	UT_hash_handle hh;
+};
+
+bool add_cgpu(struct cgpu_info*cgpu)
+{
+	static struct _cgpu_devid_counter *devids = NULL;
+	struct _cgpu_devid_counter *d;
+	
+	HASH_FIND_STR(devids, cgpu->api->name, d);
+	if (d)
+		cgpu->device_id = ++d->lastid;
+	else
+	{
+		d = malloc(sizeof(*d));
+		memcpy(d->name, cgpu->api->name, sizeof(d->name));
+		cgpu->device_id = d->lastid = 0;
+		HASH_ADD_STR(devids, name, d);
+	}
+	devices[total_devices++] = cgpu;
+	return true;
+}
+
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
 	struct block *block, *tmpblock;
 	struct block *block, *tmpblock;
@@ -4604,7 +4629,11 @@ int main(int argc, char *argv[])
 	if (devices_enabled == -1) {
 	if (devices_enabled == -1) {
 		applog(LOG_ERR, "Devices detected:");
 		applog(LOG_ERR, "Devices detected:");
 		for (i = 0; i < total_devices; ++i) {
 		for (i = 0; i < total_devices; ++i) {
-			applog(LOG_ERR, " %2d. %s%d", i, devices[i]->api->name, devices[i]->device_id);
+			struct cgpu_info *cgpu = devices[i];
+			if (cgpu->name)
+				applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->name, cgpu->api->dname);
+			else
+				applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->api->dname);
 		}
 		}
 		quit(0, "%d devices listed", total_devices);
 		quit(0, "%d devices listed", total_devices);
 	}
 	}

+ 9 - 5
bitforce.c → driver-bitforce.c

@@ -91,8 +91,8 @@ static void BFwrite(int fd, const void *buf, ssize_t bufLen)
 
 
 static bool bitforce_detect_one(const char *devpath)
 static bool bitforce_detect_one(const char *devpath)
 {
 {
+	char *s;
 	char pdevbuf[0x100];
 	char pdevbuf[0x100];
-	static int i = 0;
 
 
 	if (total_devices == MAX_DEVICES)
 	if (total_devices == MAX_DEVICES)
 		return false;
 		return false;
@@ -117,14 +117,17 @@ static bool bitforce_detect_one(const char *devpath)
 	// We have a real BitForce!
 	// We have a real BitForce!
 	struct cgpu_info *bitforce;
 	struct cgpu_info *bitforce;
 	bitforce = calloc(1, sizeof(*bitforce));
 	bitforce = calloc(1, sizeof(*bitforce));
-	devices[total_devices++] = bitforce;
 	bitforce->api = &bitforce_api;
 	bitforce->api = &bitforce_api;
-	bitforce->device_id = i++;
 	bitforce->device_path = strdup(devpath);
 	bitforce->device_path = strdup(devpath);
 	bitforce->deven = DEV_ENABLED;
 	bitforce->deven = DEV_ENABLED;
 	bitforce->threads = 1;
 	bitforce->threads = 1;
+	if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>"))))
+	{
+		s[0] = '\0';
+		bitforce->name = strdup(pdevbuf + 7);
+	}
 
 
-	return true;
+	return add_cgpu(bitforce);
 }
 }
 
 
 static bool bitforce_detect_auto_udev()
 static bool bitforce_detect_auto_udev()
@@ -358,7 +361,8 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 }
 }
 
 
 struct device_api bitforce_api = {
 struct device_api bitforce_api = {
-	.name = "BFL",
+	.dname = "bitforce",
+	.name = "PGA",
 	.api_detect = bitforce_detect,
 	.api_detect = bitforce_detect,
 	.get_statline_before = get_bitforce_statline_before,
 	.get_statline_before = get_bitforce_statline_before,
 	.thread_prepare = bitforce_thread_prepare,
 	.thread_prepare = bitforce_thread_prepare,

+ 5 - 4
device-cpu.c → driver-cpu.c

@@ -32,7 +32,7 @@
 #include "compat.h"
 #include "compat.h"
 #include "miner.h"
 #include "miner.h"
 #include "bench_block.h"
 #include "bench_block.h"
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #if defined(unix)
 #if defined(unix)
 	#include <errno.h>
 	#include <errno.h>
@@ -739,13 +739,13 @@ static void cpu_detect()
 	for (i = 0; i < opt_n_threads; ++i) {
 	for (i = 0; i < opt_n_threads; ++i) {
 		struct cgpu_info *cgpu;
 		struct cgpu_info *cgpu;
 
 
-		cgpu = devices[total_devices + i] = &cpus[i];
+		cgpu = &cpus[i];
 		cgpu->api = &cpu_api;
 		cgpu->api = &cpu_api;
 		cgpu->deven = DEV_ENABLED;
 		cgpu->deven = DEV_ENABLED;
-		cgpu->device_id = i;
 		cgpu->threads = 1;
 		cgpu->threads = 1;
+		cgpu->kname = algo_names[opt_algo];
+		add_cgpu(cgpu);
 	}
 	}
-	total_devices += opt_n_threads;
 }
 }
 
 
 static void reinit_cpu_device(struct cgpu_info *cpu)
 static void reinit_cpu_device(struct cgpu_info *cpu)
@@ -827,6 +827,7 @@ CPUSearch:
 }
 }
 
 
 struct device_api cpu_api = {
 struct device_api cpu_api = {
+	.dname = "cpu",
 	.name = "CPU",
 	.name = "CPU",
 	.api_detect = cpu_detect,
 	.api_detect = cpu_detect,
 	.reinit_device = reinit_cpu_device,
 	.reinit_device = reinit_cpu_device,

+ 0 - 0
device-cpu.h → driver-cpu.h


+ 3 - 3
icarus.c → driver-icarus.c

@@ -194,10 +194,9 @@ static bool icarus_detect_one(const char *devpath)
 	struct cgpu_info *icarus;
 	struct cgpu_info *icarus;
 	icarus = calloc(1, sizeof(struct cgpu_info));
 	icarus = calloc(1, sizeof(struct cgpu_info));
 	icarus->api = &icarus_api;
 	icarus->api = &icarus_api;
-	icarus->device_id = total_devices;
 	icarus->device_path = strdup(devpath);
 	icarus->device_path = strdup(devpath);
 	icarus->threads = 1;
 	icarus->threads = 1;
-	devices[total_devices++] = icarus;
+	add_cgpu(icarus);
 
 
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 	       devpath, icarus->device_id);
 	       devpath, icarus->device_id);
@@ -333,7 +332,8 @@ static void icarus_shutdown(struct thr_info *thr)
 }
 }
 
 
 struct device_api icarus_api = {
 struct device_api icarus_api = {
-	.name = "ICA",
+	.dname = "icarus",
+	.name = "PGA",
 	.api_detect = icarus_detect,
 	.api_detect = icarus_detect,
 	.thread_prepare = icarus_prepare,
 	.thread_prepare = icarus_prepare,
 	.scanhash = icarus_scanhash,
 	.scanhash = icarus_scanhash,

+ 23 - 2
device-gpu.c → driver-opencl.c

@@ -28,7 +28,7 @@
 
 
 #include "compat.h"
 #include "compat.h"
 #include "miner.h"
 #include "miner.h"
-#include "device-gpu.h"
+#include "driver-opencl.h"
 #include "findnonce.h"
 #include "findnonce.h"
 #include "ocl.h"
 #include "ocl.h"
 #include "adl.h"
 #include "adl.h"
@@ -1107,12 +1107,13 @@ static void opencl_detect()
 	for (i = 0; i < nDevs; ++i) {
 	for (i = 0; i < nDevs; ++i) {
 		struct cgpu_info *cgpu;
 		struct cgpu_info *cgpu;
 
 
-		cgpu = devices[total_devices++] = &gpus[i];
+		cgpu = &gpus[i];
 		cgpu->deven = DEV_ENABLED;
 		cgpu->deven = DEV_ENABLED;
 		cgpu->api = &opencl_api;
 		cgpu->api = &opencl_api;
 		cgpu->device_id = i;
 		cgpu->device_id = i;
 		cgpu->threads = opt_g_threads;
 		cgpu->threads = opt_g_threads;
 		cgpu->virtual_gpu = i;
 		cgpu->virtual_gpu = i;
+		add_cgpu(cgpu);
 	}
 	}
 
 
 	if (!opt_noadl)
 	if (!opt_noadl)
@@ -1208,6 +1209,25 @@ static bool opencl_thread_prepare(struct thr_info *thr)
 
 
 		return false;
 		return false;
 	}
 	}
+	if (name && !cgpu->name)
+		cgpu->name = strdup(name);
+	if (!cgpu->kname)
+	{
+		switch (clStates[i]->chosen_kernel) {
+		case KL_DIABLO:
+			cgpu->kname = "diablo";
+			break;
+		case KL_DIAKGCN:
+			cgpu->kname = "diakgcn";
+			break;
+		case KL_PHATK:
+			cgpu->kname = "phatk";
+			break;
+		case KL_POCLBM:
+			cgpu->kname = "poclbm";
+		default:
+		}
+	}
 	applog(LOG_INFO, "initCl() finished. Found %s", name);
 	applog(LOG_INFO, "initCl() finished. Found %s", name);
 	gettimeofday(&now, NULL);
 	gettimeofday(&now, NULL);
 	get_datestamp(cgpu->init, &now);
 	get_datestamp(cgpu->init, &now);
@@ -1404,6 +1424,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
 }
 }
 
 
 struct device_api opencl_api = {
 struct device_api opencl_api = {
+	.dname = "opencl",
 	.name = "GPU",
 	.name = "GPU",
 	.api_detect = opencl_detect,
 	.api_detect = opencl_detect,
 	.reinit_device = reinit_opencl_device,
 	.reinit_device = reinit_opencl_device,

+ 0 - 0
device-gpu.h → driver-opencl.h


+ 5 - 0
miner.h

@@ -187,6 +187,7 @@ struct thr_info;
 struct work;
 struct work;
 
 
 struct device_api {
 struct device_api {
+	char*dname;
 	char*name;
 	char*name;
 
 
 	// API-global functions
 	// API-global functions
@@ -247,6 +248,7 @@ struct cgpu_info {
 	int cgminer_id;
 	int cgminer_id;
 	struct device_api *api;
 	struct device_api *api;
 	int device_id;
 	int device_id;
+	char *name;
 	char *device_path;
 	char *device_path;
 	FILE *device_file;
 	FILE *device_file;
 	int device_fd;
 	int device_fd;
@@ -270,6 +272,7 @@ struct cgpu_info {
 	int virtual_gpu;
 	int virtual_gpu;
 	int intensity;
 	int intensity;
 	bool dynamic;
 	bool dynamic;
+	char *kname;
 #ifdef HAVE_OPENCL
 #ifdef HAVE_OPENCL
 	cl_uint vwidth;
 	cl_uint vwidth;
 	size_t work_size;
 	size_t work_size;
@@ -308,6 +311,8 @@ struct cgpu_info {
 	int dev_thermal_cutoff_count;
 	int dev_thermal_cutoff_count;
 };
 };
 
 
+extern bool add_cgpu(struct cgpu_info*);
+
 struct thread_q {
 struct thread_q {
 	struct list_head	q;
 	struct list_head	q;
 
 

+ 1 - 1
sha256_4way.c

@@ -4,7 +4,7 @@
 
 
 // tcatm's 4-way 128-bit SSE2 SHA-256
 // tcatm's 4-way 128-bit SSE2 SHA-256
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #ifdef WANT_SSE2_4WAY
 #ifdef WANT_SSE2_4WAY
 
 

+ 1 - 1
sha256_altivec_4way.c

@@ -9,7 +9,7 @@
 //
 //
 
 
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #ifdef WANT_ALTIVEC_4WAY
 #ifdef WANT_ALTIVEC_4WAY
 
 

+ 1 - 1
sha256_sse2_amd64.c

@@ -9,7 +9,7 @@
  *
  *
  */
  */
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #ifdef WANT_X8664_SSE2
 #ifdef WANT_X8664_SSE2
 
 

+ 1 - 1
sha256_sse2_i386.c

@@ -9,7 +9,7 @@
  *
  *
  */
  */
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #ifdef WANT_X8632_SSE2
 #ifdef WANT_X8632_SSE2
 
 

+ 1 - 1
sha256_sse4_amd64.c

@@ -9,7 +9,7 @@
  *
  *
  */
  */
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #ifdef WANT_X8664_SSE4
 #ifdef WANT_X8664_SSE4
 
 

+ 1 - 1
sha256_via.c

@@ -1,5 +1,5 @@
 
 
-#include "device-cpu.h"
+#include "driver-cpu.h"
 
 
 #include <stdint.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdlib.h>