Browse Source

Merge branch 'cgminer' of git://github.com/ckolivas/cgminer into cgminer

nfactor-troky
Ycros 14 years ago
parent
commit
a636a6744f
  1. 4
      findnonce.c
  2. 3
      findnonce.h
  3. 22
      main.c
  4. 9
      miner.h
  5. 2
      ocl.c
  6. 4
      ocl.h

4
findnonce.c

@ -8,6 +8,9 @@
* any later version. See COPYING for more details. * any later version. See COPYING for more details.
*/ */
#include "config.h"
#ifdef HAVE_OPENCL
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include <pthread.h> #include <pthread.h>
@ -252,3 +255,4 @@ void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res)
return; return;
} }
} }
#endif /* HAVE_OPENCL */

3
findnonce.h

@ -1,12 +1,15 @@
#ifndef __FINDNONCE_H__ #ifndef __FINDNONCE_H__
#define __FINDNONCE_H__ #define __FINDNONCE_H__
#include "miner.h" #include "miner.h"
#include "config.h"
#define MAXTHREADS (0xFFFFFFFEULL) #define MAXTHREADS (0xFFFFFFFEULL)
/* Maximum worksize 512 * maximum vectors 4 plus one flag entry */ /* Maximum worksize 512 * maximum vectors 4 plus one flag entry */
#define MAXBUFFERS (4 * 512) #define MAXBUFFERS (4 * 512)
#define BUFFERSIZE (sizeof(uint32_t) * (MAXBUFFERS + 1)) #define BUFFERSIZE (sizeof(uint32_t) * (MAXBUFFERS + 1))
#ifdef HAVE_OPENCL
extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data); extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data);
extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res); extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t *res);
#endif /* HAVE_OPENCL */
#endif /*__FINDNONCE_H__*/ #endif /*__FINDNONCE_H__*/

22
main.c

@ -190,18 +190,20 @@ static struct option_help options_help[] = {
{ "debug", { "debug",
"(-D) Enable debug output (default: off)" }, "(-D) Enable debug output (default: off)" },
#ifdef HAVE_OPENCL
{ "gpu-threads N", { "gpu-threads N",
"(-g N) Number of threads per-GPU (0 - 10, default: 2)" }, "(-g N) Number of threads per-GPU (0 - 10, default: 2)" },
{ "intensity N", { "intensity N",
"(-I N) Intensity of GPU scanning (0 - 14, default 4)" }, "(-I N) Intensity of GPU scanning (0 - 14, default 4)" },
#endif
{ "log N", { "log N",
"(-l N) Interval in seconds between log output (default: 5)" }, "(-l N) Interval in seconds between log output (default: 5)" },
#ifdef HAVE_OPENCL
{ "ndevs", { "ndevs",
"(-n) Display number of detected GPUs and exit" }, "(-n) Display number of detected GPUs and exit" },
#endif
{ "no-longpoll", { "no-longpoll",
"Disable X-Long-Polling support (default: enabled)" }, "Disable X-Long-Polling support (default: enabled)" },
@ -247,12 +249,13 @@ static struct option_help options_help[] = {
"(-u USERNAME) Username for bitcoin JSON-RPC server " "(-u USERNAME) Username for bitcoin JSON-RPC server "
"(default: " DEF_RPC_USERNAME ")" }, "(default: " DEF_RPC_USERNAME ")" },
#ifdef HAVE_OPENCL
{ "vectors N", { "vectors N",
"(-v N) Override detected optimal vector width (default: detected, 1,2 or 4)" }, "(-v N) Override detected optimal vector width (default: detected, 1,2 or 4)" },
{ "worksize N", { "worksize N",
"(-w N) Override detected optimal worksize (default: detected)" }, "(-w N) Override detected optimal worksize (default: detected)" },
#endif
}; };
static struct option options[] = { static struct option options[] = {
@ -984,6 +987,7 @@ enum {
FAILURE_INTERVAL = 30, FAILURE_INTERVAL = 30,
}; };
#ifdef HAVE_OPENCL
static _clState *clStates[16]; static _clState *clStates[16];
static inline cl_int queue_kernel_parameters(_clState *clState, dev_blk_ctx *blk) static inline cl_int queue_kernel_parameters(_clState *clState, dev_blk_ctx *blk)
@ -1172,6 +1176,7 @@ out:
return NULL; return NULL;
} }
#endif /* HAVE_OPENCL */
static void restart_threads(void) static void restart_threads(void)
{ {
@ -1270,7 +1275,12 @@ static void show_usage(void)
{ {
int i; int i;
printf("cgminer version %s\n\n", VERSION); printf("cgminer version %s\n", VERSION);
#ifdef HAVE_OPENCL
printf("Built with CPU and GPU mining support.\n\n");
#else
printf("Built with CPU mining support only.\n\n");
#endif
printf("Usage:\tcgminer [options]\n\nSupported options:\n"); printf("Usage:\tcgminer [options]\n\nSupported options:\n");
for (i = 0; i < ARRAY_SIZE(options_help); i++) { for (i = 0; i < ARRAY_SIZE(options_help); i++) {
struct option_help *h; struct option_help *h;
@ -1482,11 +1492,13 @@ int main (int argc, char *argv[])
opt_n_threads = num_processors; opt_n_threads = num_processors;
#endif /* !WIN32 */ #endif /* !WIN32 */
#ifdef HAVE_OPENCL
nDevs = clDevicesNum(); nDevs = clDevicesNum();
if (opt_ndevs) { if (opt_ndevs) {
applog(LOG_INFO, "%i", nDevs); applog(LOG_INFO, "%i", nDevs);
return nDevs; return nDevs;
} }
#endif
/* Invert the value to determine if we manually set it in cmdline /* Invert the value to determine if we manually set it in cmdline
* or disable gpu threads */ * or disable gpu threads */
if (nDevs) if (nDevs)
@ -1596,6 +1608,7 @@ int main (int argc, char *argv[])
} }
} }
#ifdef HAVE_OPENCL
/* start GPU mining threads */ /* start GPU mining threads */
for (i = 0; i < gpu_threads; i++) { for (i = 0; i < gpu_threads; i++) {
int gpu = gpu_from_thr_id(i); int gpu = gpu_from_thr_id(i);
@ -1628,6 +1641,7 @@ int main (int argc, char *argv[])
} }
applog(LOG_INFO, "%d gpu miner threads started", i); applog(LOG_INFO, "%d gpu miner threads started", i);
#endif
/* start CPU mining threads */ /* start CPU mining threads */
for (i = gpu_threads; i < gpu_threads + opt_n_threads; i++) { for (i = gpu_threads; i < gpu_threads + opt_n_threads; i++) {

9
miner.h

@ -9,11 +9,14 @@
#include <pthread.h> #include <pthread.h>
#include <jansson.h> #include <jansson.h>
#include <curl/curl.h> #include <curl/curl.h>
#ifdef HAVE_OPENCL
#ifdef __APPLE_CC__ #ifdef __APPLE_CC__
#include <OpenCL/opencl.h> #include <OpenCL/opencl.h>
#else #else
#include <CL/cl.h> #include <CL/cl.h>
#endif #endif
#endif /* HAVE_OPENCL */
#ifdef STDC_HEADERS #ifdef STDC_HEADERS
# include <stdlib.h> # include <stdlib.h>
@ -211,6 +214,7 @@ extern struct thr_info *thr_info;
extern int longpoll_thr_id; extern int longpoll_thr_id;
extern struct work_restart *work_restart; extern struct work_restart *work_restart;
#ifdef HAVE_OPENCL
typedef struct { typedef struct {
cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d; cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h; cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
@ -222,6 +226,11 @@ typedef struct {
cl_uint W16; cl_uint W17; cl_uint W2; cl_uint W16; cl_uint W17; cl_uint W2;
cl_uint PreVal4; cl_uint T1; cl_uint PreVal4; cl_uint T1;
} dev_blk_ctx; } dev_blk_ctx;
#else
typedef struct {
uint32_t nonce;
} dev_blk_ctx;
#endif
struct work { struct work {
unsigned char data[128]; unsigned char data[128];

2
ocl.c

@ -2,6 +2,7 @@
* Copyright 2011 Con Kolivas * Copyright 2011 Con Kolivas
*/ */
#include "config.h" #include "config.h"
#ifdef HAVE_OPENCL
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
@ -631,4 +632,5 @@ built:
return clState; return clState;
} }
#endif /* HAVE_OPENCL */

4
ocl.h

@ -1,5 +1,7 @@
#ifndef __OCL_H__ #ifndef __OCL_H__
#define __OCL_H__ #define __OCL_H__
#include "config.h"
#ifdef HAVE_OPENCL
#ifdef __APPLE_CC__ #ifdef __APPLE_CC__
#include <OpenCL/opencl.h> #include <OpenCL/opencl.h>
#else #else
@ -21,5 +23,5 @@ typedef struct {
extern char *file_contents(const char *filename, int *length); extern char *file_contents(const char *filename, int *length);
extern int clDevicesNum(); extern int clDevicesNum();
extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize); extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
#endif /* HAVE_OPENCL */
#endif /* __OCL_H__ */ #endif /* __OCL_H__ */

Loading…
Cancel
Save