Browse Source

Merge branch 'unify_drivers' into myfork

Luke Dashjr 14 years ago
parent
commit
56e4345a84
7 changed files with 69 additions and 11 deletions
  1. 3 0
      adl.c
  2. 30 1
      cgminer.c
  3. 7 4
      driver-bitforce.c
  4. 3 3
      driver-cpu.c
  5. 1 2
      driver-icarus.c
  6. 21 1
      driver-opencl.c
  7. 4 0
      miner.h

+ 3 - 0
adl.c

@@ -343,6 +343,9 @@ void init_adl(int nDevs)
 		}
 
 		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;
 		/* Flag adl as active if any card is successfully activated */
 		adl_active = true;

+ 30 - 1
cgminer.c

@@ -4330,6 +4330,31 @@ void enable_device(struct cgpu_info *cgpu)
 #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[])
 {
 	struct block *block, *tmpblock;
@@ -4504,7 +4529,11 @@ int main (int argc, char *argv[])
 	if (devices_enabled == -1) {
 		applog(LOG_ERR, "Devices detected:");
 		for (i = 0; i < total_devices; ++i) {
-			applog(LOG_ERR, " %2d. %s%d (driver: %s)", i, devices[i]->api->name, devices[i]->device_id, devices[i]->api->dname);
+			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);
 	}

+ 7 - 4
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)
 {
+	char *s;
 	char pdevbuf[0x100];
-	static int i = 0;
 
 	if (total_devices == MAX_DEVICES)
 		return false;
@@ -117,14 +117,17 @@ static bool bitforce_detect_one(const char *devpath)
 	// We have a real BitForce!
 	struct cgpu_info *bitforce;
 	bitforce = calloc(1, sizeof(*bitforce));
-	devices[total_devices++] = bitforce;
 	bitforce->api = &bitforce_api;
-	bitforce->device_id = i++;
 	bitforce->device_path = strdup(devpath);
 	bitforce->deven = DEV_ENABLED;
 	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()

+ 3 - 3
driver-cpu.c

@@ -739,13 +739,13 @@ static void cpu_detect()
 	for (i = 0; i < opt_n_threads; ++i) {
 		struct cgpu_info *cgpu;
 
-		cgpu = devices[total_devices + i] = &cpus[i];
+		cgpu = &cpus[i];
 		cgpu->api = &cpu_api;
 		cgpu->deven = DEV_ENABLED;
-		cgpu->device_id = i;
 		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)

+ 1 - 2
driver-icarus.c

@@ -191,10 +191,9 @@ static bool icarus_detect_one(const char *devpath)
 	struct cgpu_info *icarus;
 	icarus = calloc(1, sizeof(struct cgpu_info));
 	icarus->api = &icarus_api;
-	icarus->device_id = total_devices;
 	icarus->device_path = strdup(devpath);
 	icarus->threads = 1;
-	devices[total_devices++] = icarus;
+	add_cgpu(icarus);
 
 	applog(LOG_INFO, "Found Icarus at %s, mark as %d",
 	       devpath, icarus->device_id);

+ 21 - 1
driver-opencl.c

@@ -1101,12 +1101,13 @@ static void opencl_detect()
 	for (i = 0; i < nDevs; ++i) {
 		struct cgpu_info *cgpu;
 
-		cgpu = devices[total_devices++] = &gpus[i];
+		cgpu = &gpus[i];
 		cgpu->deven = DEV_ENABLED;
 		cgpu->api = &opencl_api;
 		cgpu->device_id = i;
 		cgpu->threads = opt_g_threads;
 		cgpu->virtual_gpu = i;
+		add_cgpu(cgpu);
 	}
 
 	if (!opt_noadl)
@@ -1197,6 +1198,25 @@ static bool opencl_thread_prepare(struct thr_info *thr)
 		cgpu->status = LIFE_NOSTART;
 		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);
 	gettimeofday(&now, NULL);
 	get_datestamp(cgpu->init, &now);

+ 4 - 0
miner.h

@@ -226,6 +226,7 @@ struct cgpu_info {
 	int cgminer_id;
 	struct device_api *api;
 	int device_id;
+	char *name;
 	char *device_path;
 	FILE *device_file;
 	int device_fd;
@@ -249,6 +250,7 @@ struct cgpu_info {
 	int virtual_gpu;
 	int intensity;
 	bool dynamic;
+	char *kname;
 #ifdef HAVE_OPENCL
 	cl_uint vwidth;
 	size_t work_size;
@@ -275,6 +277,8 @@ struct cgpu_info {
 	time_t last_share_pool_time;
 };
 
+extern bool add_cgpu(struct cgpu_info*);
+
 struct thread_q {
 	struct list_head	q;