Browse Source

Merge pull request #157 from luke-jr/unify_drivers

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

8
Makefile.am

@ -37,7 +37,7 @@ cgminer_SOURCES += logging.c @@ -37,7 +37,7 @@ cgminer_SOURCES += logging.c
# GPU sources, TODO: make them selectable
# 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
cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
@ -53,7 +53,7 @@ cgminer_SOURCES += \ @@ -53,7 +53,7 @@ cgminer_SOURCES += \
sha256_altivec_4way.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
AM_CFLAGS = -DHAS_YASM
@ -68,9 +68,9 @@ endif # HAS_YASM @@ -68,9 +68,9 @@ endif # HAS_YASM
endif # HAS_CPUMINE
if HAS_BITFORCE
cgminer_SOURCES += bitforce.c
cgminer_SOURCES += driver-bitforce.c
endif
if HAS_ICARUS
cgminer_SOURCES += icarus.c
cgminer_SOURCES += driver-icarus.c
endif

3
adl.c

@ -352,6 +352,9 @@ void init_adl(int nDevs) @@ -352,6 +352,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;

2
api.c

@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
#include "compat.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__)
#include <errno.h>

35
cgminer.c

@ -44,8 +44,8 @@ @@ -44,8 +44,8 @@
#include "miner.h"
#include "findnonce.h"
#include "adl.h"
#include "device-cpu.h"
#include "device-gpu.h"
#include "driver-cpu.h"
#include "driver-opencl.h"
#include "bench_block.h"
#if defined(unix)
@ -4425,6 +4425,31 @@ void enable_device(struct cgpu_info *cgpu) @@ -4425,6 +4425,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;
@ -4604,7 +4629,11 @@ int main(int argc, char *argv[]) @@ -4604,7 +4629,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", 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);
}

14
bitforce.c → driver-bitforce.c

@ -91,8 +91,8 @@ static void BFwrite(int fd, const void *buf, ssize_t bufLen) @@ -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) @@ -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()
@ -358,7 +361,8 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6 @@ -358,7 +361,8 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
}
struct device_api bitforce_api = {
.name = "BFL",
.dname = "bitforce",
.name = "PGA",
.api_detect = bitforce_detect,
.get_statline_before = get_bitforce_statline_before,
.thread_prepare = bitforce_thread_prepare,

9
device-cpu.c → driver-cpu.c

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
#include "compat.h"
#include "miner.h"
#include "bench_block.h"
#include "device-cpu.h"
#include "driver-cpu.h"
#if defined(unix)
#include <errno.h>
@ -739,13 +739,13 @@ static void cpu_detect() @@ -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)
@ -827,6 +827,7 @@ CPUSearch: @@ -827,6 +827,7 @@ CPUSearch:
}
struct device_api cpu_api = {
.dname = "cpu",
.name = "CPU",
.api_detect = cpu_detect,
.reinit_device = reinit_cpu_device,

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

6
icarus.c → driver-icarus.c

@ -194,10 +194,9 @@ static bool icarus_detect_one(const char *devpath) @@ -194,10 +194,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);
@ -333,7 +332,8 @@ static void icarus_shutdown(struct thr_info *thr) @@ -333,7 +332,8 @@ static void icarus_shutdown(struct thr_info *thr)
}
struct device_api icarus_api = {
.name = "ICA",
.dname = "icarus",
.name = "PGA",
.api_detect = icarus_detect,
.thread_prepare = icarus_prepare,
.scanhash = icarus_scanhash,

25
device-gpu.c → driver-opencl.c

@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
#include "compat.h"
#include "miner.h"
#include "device-gpu.h"
#include "driver-opencl.h"
#include "findnonce.h"
#include "ocl.h"
#include "adl.h"
@ -1107,12 +1107,13 @@ static void opencl_detect() @@ -1107,12 +1107,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)
@ -1208,6 +1209,25 @@ static bool opencl_thread_prepare(struct thr_info *thr) @@ -1208,6 +1209,25 @@ static bool opencl_thread_prepare(struct thr_info *thr)
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);
@ -1404,6 +1424,7 @@ static void opencl_thread_shutdown(struct thr_info *thr) @@ -1404,6 +1424,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
}
struct device_api opencl_api = {
.dname = "opencl",
.name = "GPU",
.api_detect = opencl_detect,
.reinit_device = reinit_opencl_device,

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

5
miner.h

@ -187,6 +187,7 @@ struct thr_info; @@ -187,6 +187,7 @@ struct thr_info;
struct work;
struct device_api {
char*dname;
char*name;
// API-global functions
@ -247,6 +248,7 @@ struct cgpu_info { @@ -247,6 +248,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;
@ -270,6 +272,7 @@ struct cgpu_info { @@ -270,6 +272,7 @@ struct cgpu_info {
int virtual_gpu;
int intensity;
bool dynamic;
char *kname;
#ifdef HAVE_OPENCL
cl_uint vwidth;
size_t work_size;
@ -308,6 +311,8 @@ struct cgpu_info { @@ -308,6 +311,8 @@ struct cgpu_info {
int dev_thermal_cutoff_count;
};
extern bool add_cgpu(struct cgpu_info*);
struct thread_q {
struct list_head q;

2
sha256_4way.c

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

2
sha256_altivec_4way.c

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

2
sha256_sse2_amd64.c

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

2
sha256_sse2_i386.c

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

2
sha256_sse4_amd64.c

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

2
sha256_via.c

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

Loading…
Cancel
Save