Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Make postcalc_hash asynchronous as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckolivas committed Jul 4, 2011
1 parent 378d18f commit a45c54a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
16 changes: 1 addition & 15 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,6 @@ static struct option options[] = {
{ "userpass", 1, NULL, 1002 },
};

struct work {
unsigned char data[128];
unsigned char hash1[64];
unsigned char midstate[32];
unsigned char target[32];

unsigned char hash[32];

uint32_t output[1];
uint32_t res_nonce;
uint32_t valid;
dev_blk_ctx blk;
};

static bool jobj_binary(const json_t *obj, const char *key,
void *buf, size_t buflen)
{
Expand Down Expand Up @@ -964,7 +950,7 @@ static void *gpuminer_thread(void *userdata)
for (i = 0; i < 127; i++) {
if (res[i]) {
applog(LOG_INFO, "GPU %d found something?", gpu_from_thr_id(thr_id));
postcalc_hash(mythr, &work->blk, work, res[i]);
postcalc_hash_async(mythr, work, res[i]);
} else
break;
}
Expand Down
38 changes: 37 additions & 1 deletion findnonce.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

#include <stdio.h>
#include <inttypes.h>
#include <pthread.h>
#include <string.h>

#include "ocl.h"
#include "findnonce.h"
#include "miner.h"

const uint32_t SHA256_K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
Expand Down Expand Up @@ -131,8 +134,21 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) {
R(E, F, G, H, A, B, C, D, P(u+4), SHA256_K[u+4]); \
R(D, E, F, G, H, A, B, C, P(u+5), SHA256_K[u+5])

void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, uint32_t start)
struct pc_data {
struct thr_info *thr;
struct work work;
uint32_t start;
pthread_t pth;
};

static void *postcalc_hash(void *userdata)
{
struct pc_data *pcd = (struct pc_data *)userdata;
struct thr_info *thr = pcd->thr;
dev_blk_ctx *blk = &pcd->work.blk;
struct work *work = &pcd->work;
uint32_t start = pcd->start;

cl_uint A, B, C, D, E, F, G, H;
cl_uint W[16];
cl_uint nonce;
Expand Down Expand Up @@ -185,4 +201,24 @@ void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, ui
out:
if (unlikely(best_g == ~0))
applog(LOG_ERR, "No best_g found! Error in OpenCL code?");
free(pcd);
}

void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t start)
{
struct pc_data *pcd = malloc(sizeof(struct pc_data));
if (unlikely(!pcd)) {
applog(LOG_ERR, "Failed to malloc pc_data in postcalc_hash_async");
return;
}

pcd->thr = thr;
memcpy(&pcd->work, work, sizeof(struct work));
pcd->start = start;

if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {
applog(LOG_ERR, "Failed to create postcalc_hash thread");
return;
}
pthread_detach(pcd->pth);
}
20 changes: 4 additions & 16 deletions findnonce.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
#ifdef __APPLE_CC__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#ifndef __FINDNONCE_H__
#define __FINDNONCE_H__
#include "miner.h"

#define MAXTHREADS (0xFFFFFFFF)
#define BUFFERSIZE (sizeof(uint32_t) * 128)

typedef struct {
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 cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
} dev_blk_ctx;

extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data);
extern void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, uint32_t start);
extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t start);
#endif /*__FINDNONCE_H__*/
31 changes: 30 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <pthread.h>
#include <jansson.h>
#include <curl/curl.h>
#ifdef __APPLE_CC__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif

#ifdef STDC_HEADERS
# include <stdlib.h>
Expand Down Expand Up @@ -194,7 +199,31 @@ extern bool use_syslog;
extern struct thr_info *thr_info;
extern int longpoll_thr_id;
extern struct work_restart *work_restart;
struct work;

typedef struct {
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 cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
} dev_blk_ctx;

struct work {
unsigned char data[128];
unsigned char hash1[64];
unsigned char midstate[32];
unsigned char target[32];

unsigned char hash[32];

uint32_t output[1];
uint32_t res_nonce;
uint32_t valid;
dev_blk_ctx blk;
};

bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);

extern void applog(int prio, const char *fmt, ...);
Expand Down

0 comments on commit a45c54a

Please sign in to comment.