mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-22 20:44:19 +00:00
Abstract add_cgpu function, to handle device id numbering and devices array
This commit is contained in:
parent
e131dfab31
commit
303dbf4664
25
cgminer.c
25
cgminer.c
@ -4263,6 +4263,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;
|
||||
|
@ -92,7 +92,6 @@ static void BFwrite(int fd, const void *buf, ssize_t bufLen)
|
||||
static bool bitforce_detect_one(const char *devpath)
|
||||
{
|
||||
char pdevbuf[0x100];
|
||||
static int i = 0;
|
||||
|
||||
if (total_devices == MAX_DEVICES)
|
||||
return false;
|
||||
@ -117,14 +116,11 @@ 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;
|
||||
|
||||
return true;
|
||||
return add_cgpu(bitforce);
|
||||
}
|
||||
|
||||
static bool bitforce_detect_auto_udev()
|
||||
|
@ -739,13 +739,12 @@ 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;
|
||||
add_cgpu(cgpu);
|
||||
}
|
||||
total_devices += opt_n_threads;
|
||||
}
|
||||
|
||||
static void reinit_cpu_device(struct cgpu_info *cpu)
|
||||
|
@ -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);
|
||||
|
@ -1093,12 +1093,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user