1 Commits
Author SHA1 Message Date
Tanguy Pruvot 52788a5962 Import new SpreadCoin algo from tsiv spreadminer
Note: stratum doesn't exists for spreadcoin yet...
and this version have a problem to fix (PoK) to allow solo mining

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
2015-09-28 18:28:37 +02:00
11 changed files with 2295 additions and 47 deletions

No files matched your search

+3 -2
View File
@@ -33,7 +33,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
myriadgroestl.cpp cuda_myriadgroestl.cu \
lyra2/Lyra2.c lyra2/Sponge.c \
lyra2/lyra2RE.cu lyra2/cuda_lyra2.cu \
lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \
lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \
Algo256/cuda_bmw256.cu Algo256/cuda_cubehash256.cu \
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
Algo256/blake256.cu Algo256/keccak256.cu \
@@ -57,7 +57,8 @@ ccminer_SOURCES = elist.h miner.h compat.h \
x15/x14.cu x15/x15.cu x15/cuda_x14_shabal512.cu x15/cuda_x15_whirlpool.cu \
x15/whirlpoolx.cu x15/cuda_whirlpoolx.cu \
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
x11/c11.cu x11/s3.cu
x11/c11.cu x11/s3.cu \
spreadx11/spreadx11.cu spreadx11/cuda_blake.cu spreadx11/cuda_spreadx11_sign.cu spreadx11/cuda_sha256.cu
# scrypt
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
+135 -24
View File
@@ -110,6 +110,7 @@ enum sha_algos {
ALGO_SCRYPT_JANE,
ALGO_SKEIN,
ALGO_SKEIN2,
ALGO_SPREAD,
ALGO_S3,
ALGO_X11,
ALGO_X13,
@@ -148,6 +149,7 @@ static const char *algo_names[] = {
"scrypt-jane",
"skein",
"skein2",
"spread",
"s3",
"x11",
"x13",
@@ -159,6 +161,8 @@ static const char *algo_names[] = {
""
};
#include "spreadx11/spreadx11.h"
bool opt_debug = false;
bool opt_debug_diff = false;
bool opt_debug_threads = false;
@@ -309,6 +313,7 @@ Options:\n\
scrypt-jane Scrypt-jane Chacha\n\
skein Skein SHA2 (Skeincoin)\n\
skein2 Double Skein (Woodcoin)\n\
spread SpreadCoin\n\
s3 S3 (1Coin)\n\
x11 X11 (DarkCoin)\n\
x13 X13 (MaruCoin)\n\
@@ -634,25 +639,26 @@ static bool work_decode(const json_t *val, struct work *work)
case ALGO_NEOSCRYPT:
data_size = 84; // typo in FTC wallet ? and clones..
break;
case ALGO_SPREAD:
data_size = 185;
break;
default:
data_size = 128; // sizeof(work->data);
}
adata_sz = data_size / 4; // sizeof(uint32_t);
if (unlikely(!jobj_binary(val, "data", work->data, data_size))) {
applog(LOG_ERR, "JSON inval data");
if (opt_algo != ALGO_SPREAD && !jobj_binary(val, "data", work->data, data_size)) {
applog(LOG_ERR, "JSON invalid data");
return false;
}
if (unlikely(!jobj_binary(val, "target", work->target, target_size))) {
applog(LOG_ERR, "JSON inval target");
applog(LOG_ERR, "JSON invalid target");
return false;
}
if (opt_algo == ALGO_HEAVY) {
if (unlikely(!jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote)))) {
work->maxvote = 2048;
}
if (opt_algo == ALGO_HEAVY && !jobj_binary(val, "maxvote", &work->maxvote, sizeof(work->maxvote))) {
work->maxvote = 2048;
} else work->maxvote = 0;
for (i = 0; i < adata_sz; i++)
@@ -698,6 +704,35 @@ static bool work_decode(const json_t *val, struct work *work)
}
}
if (opt_algo == ALGO_SPREAD) {
int len;
struct spreadwork* swork = (struct spreadwork*) work->extradata;
if(!swork) {
applog(LOG_ERR, "SpreadCoin custom data not allocated!");
return false;
}
if( (len = jobj_binary(val, "data", swork->data, sizeof(swork->data))) == -1 ) {
applog(LOG_ERR, "JSON invalid data");
return false;
}
if( (len = jobj_binary(val, "pmr", swork->privkey, sizeof(swork->privkey))) == -1 ) {
applog(LOG_ERR, "JSON invalid privkey");
return false;
}
if( (len = jobj_binary(val, "kinv", swork->kinv, sizeof(swork->kinv))) == -1 ) {
applog(LOG_ERR, "JSON invalid kinv");
return false;
}
if( (len = jobj_binary(val, "tx", swork->tx, sizeof(swork->tx))) == -1 ) {
applog(LOG_ERR, "JSON invalid tx");
return false;
}
swork->txsize = len; // todo tx_count ?
if (len)
applog(LOG_DEBUG, "spreak block len=%d", len);
}
json_t *jr = json_object_get(val, "noncerange");
if (jr) {
const char * hexstr = json_string_value(jr);
@@ -779,7 +814,6 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
struct pool_infos *pool = &pools[work->pooln];
json_t *val, *res, *reason;
bool stale_work = false;
char s[384];
/* discard if a newer block was received */
stale_work = work->height && work->height < g_work.height;
@@ -812,6 +846,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
}
if (pool->type & POOL_STRATUM) {
char s[384];
uint32_t sent = 0;
uint32_t ntime, nonce;
uint16_t nvote;
@@ -889,33 +924,57 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
} else {
uchar* data = (uchar*)work->data;
int data_size = sizeof(work->data);
int adata_sz = ARRAY_SIZE(work->data);
char *json = NULL, *hex = NULL;
/* build hex string */
char *str = NULL;
if (opt_algo == ALGO_ZR5) {
switch (opt_algo) {
case ALGO_ZR5:
data_size = 80; adata_sz = 20;
break;
case ALGO_SPREAD:
{
struct spreadwork* swork = (struct spreadwork*) work->extradata;
if (!swork) {
applog(LOG_ERR, "submit_upstream_work spread OOM");
return false;
}
data = (uchar*) swork->data;
data_size = sizeof(swork->data); // 185
adata_sz = 0; // no endian encode
}
break;
case ALGO_HEAVY:
case ALGO_MJOLLNIR:
adata_sz = 0; // no endian encode
break;
default:
break;
}
if (opt_algo != ALGO_HEAVY && opt_algo != ALGO_MJOLLNIR) {
for (int i = 0; i < adata_sz; i++)
le32enc(work->data + i, work->data[i]);
for (int i = 0; i < adata_sz; i++)
le32enc(&work->data[i], work->data[i]);
hex = bin2hex(data, data_size);
if (unlikely(!hex)) {
applog(LOG_ERR, "submit_upstream_work OOM");
return false;
}
str = bin2hex((uchar*)work->data, data_size);
if (unlikely(!str)) {
json = (char*) malloc(strlen(hex) + 64);
if (unlikely(!json)) {
applog(LOG_ERR, "submit_upstream_work OOM");
return false;
}
/* build JSON-RPC request */
sprintf(s,
sprintf(json,
"{\"method\": \"getwork\", \"params\": [\"%s\"], \"id\":4}\r\n",
str);
hex);
/* issue JSON-RPC request */
val = json_rpc_call_pool(curl, pool, s, false, false, NULL);
val = json_rpc_call_pool(curl, pool, json, false, false, NULL);
if (unlikely(!val)) {
applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
return false;
@@ -932,7 +991,8 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
json_decref(val);
free(str);
free(hex);
free(json);
}
return true;
@@ -1148,6 +1208,11 @@ static bool workio_get_work(struct workio_cmd *wc, CURL *curl)
if (!ret_work)
return false;
if (opt_algo == ALGO_SPREAD) {
ret_work->extradata = calloc(1, sizeof(struct spreadwork));
//applog(LOG_DEBUG, "spread work alloc %p", ret_work->extradata);
}
/* assign pool number before rpc calls */
ret_work->pooln = wc->pooln;
// applog(LOG_DEBUG, "%s: pool %d", __func__, wc->pooln);
@@ -1175,8 +1240,9 @@ static bool workio_get_work(struct workio_cmd *wc, CURL *curl)
}
/* send work to requesting thread */
if (!tq_push(wc->thr->q, ret_work))
if (!tq_push(wc->thr->q, ret_work)) {
aligned_free(ret_work);
}
return true;
}
@@ -1272,6 +1338,11 @@ bool get_work(struct thr_info *thr, struct work *work)
work->data[20] = 0x80000000;
work->data[31] = 0x00000280;
memset(work->target, 0x00, sizeof(work->target));
if (opt_algo == ALGO_SPREAD) {
work->extradata = calloc(1, sizeof(struct spreadwork)); // todo: free in benchmark
struct spreadwork *swork = (struct spreadwork *) work->extradata;
memcpy(swork->data, work->data, 128);
}
return true;
}
@@ -1295,6 +1366,13 @@ bool get_work(struct thr_info *thr, struct work *work)
if (!work_heap)
return false;
/* if allocated in previous work */
if (opt_algo == ALGO_SPREAD && work->extradata) {
//applog(LOG_DEBUG, "spread work free %p", work->extradata);
if (work_heap->extradata != work->extradata)
free(work->extradata);
}
/* copy returned work into storage provided by caller */
memcpy(work, work_heap, sizeof(*work));
aligned_free(work_heap);
@@ -1529,6 +1607,7 @@ void miner_free_device(int thr_id)
free_qubit(thr_id);
free_skeincoin(thr_id);
free_skein2(thr_id);
free_spreadx11(thr_id);
free_s3(thr_id);
free_whirlx(thr_id);
free_x11(thr_id);
@@ -1665,10 +1744,30 @@ static void *miner_thread(void *userdata)
uint64_t target64 = g_work.target[7] * 0x100000000ULL + g_work.target[6];
applog(LOG_DEBUG, "job %s target change: %llx (%.1f)", g_work.job_id, target64, g_work.targetdiff);
}
memcpy(work.target, g_work.target, sizeof(work.target));
work.targetdiff = g_work.targetdiff;
work.height = g_work.height;
//nonceptr[0] = (UINT32_MAX / opt_n_threads) * thr_id; // 0 if single thr
}
work.extradata = g_work.extradata;
if (opt_algo == ALGO_SPREAD) {
struct spreadwork *swork = (struct spreadwork *) g_work.extradata;
if (!swork) {
applog(LOG_ERR, "SpreadCoin work data not allocated!");
continue;
}
nonceptr = (uint32_t*) &swork->data[84]; //data[21]
wcmplen = 80;
if (memcmp(swork->data, work.data, wcmplen)) {
memcpy(&work, &g_work, sizeof(struct work));
nonceptr[0] = (UINT32_MAX / opt_n_threads) * thr_id; // 0 if single thr
nonceptr[0] += (((rand()*4) & UINT32_MAX) / opt_n_threads) / 16;
} else {
nonceptr[0] += 0xC0;
}
nonceptr[0] &= 0xFFFFFFC0U; // make sure the 6 lowest bits are zero (%64)
}
if (opt_algo == ALGO_ZR5) {
@@ -1691,8 +1790,9 @@ static void *miner_thread(void *userdata)
#endif
memcpy(&work, &g_work, sizeof(struct work));
nonceptr[0] = (UINT32_MAX / opt_n_threads) * thr_id; // 0 if single thr
} else
} else {
nonceptr[0]++; //??
}
pthread_mutex_unlock(&g_work_lock);
@@ -1802,6 +1902,7 @@ static void *miner_thread(void *userdata)
break;
case ALGO_LYRA2:
case ALGO_NEOSCRYPT:
case ALGO_SPREAD:
case ALGO_X15:
minmax = 0x300000;
break;
@@ -1818,6 +1919,11 @@ static void *miner_thread(void *userdata)
start_nonce = nonceptr[0];
if (opt_algo == ALGO_SPREAD) {
start_nonce &= 0xFFFFFFC0; // make sure the 6 lowest bits are zero
nonceptr[0] = start_nonce;
}
/* never let small ranges at end */
if (end_nonce >= UINT32_MAX - 256)
end_nonce = UINT32_MAX;
@@ -1926,6 +2032,9 @@ static void *miner_thread(void *userdata)
case ALGO_SKEIN2:
rc = scanhash_skein2(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_SPREAD:
rc = scanhash_spreadx11(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_S3:
rc = scanhash_s3(thr_id, &work, max_nonce, &hashes_done);
break;
@@ -2435,6 +2544,8 @@ void parse_arg(int key, char *arg)
i = opt_algo = ALGO_LYRA2;
else if (!strcasecmp("lyra2rev2", arg))
i = opt_algo = ALGO_LYRA2v2;
else if (!strcasecmp("spreadx11", arg))
i = opt_algo = ALGO_SPREAD;
else if (!strcasecmp("ziftr", arg))
i = opt_algo = ALGO_ZR5;
else
+6
View File
@@ -336,6 +336,8 @@
<ClInclude Include="lyra2\Sponge.h" />
<ClInclude Include="quark\groestl_transf_quad.h" />
<ClInclude Include="quark\groestl_functions_quad.h" />
<ClInclude Include="spreadx11\bignum_fp.h" />
<ClInclude Include="spreadx11\spreadx11.h" />
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cpp" />
@@ -454,6 +456,10 @@
<CudaCompile Include="cuda_skeincoin.cu">
<MaxRegCount>48</MaxRegCount>
</CudaCompile>
<CudaCompile Include="spreadx11\spreadx11.cu" />
<CudaCompile Include="spreadx11\cuda_blake.cu" />
<CudaCompile Include="spreadx11\cuda_spreadx11_sign.cu" />
<CudaCompile Include="spreadx11\cuda_sha256.cu" />
<CudaCompile Include="x11\cuda_x11_aes.cu">
<ExcludedFromBuild>true</ExcludedFromBuild>
</CudaCompile>
+8
View File
@@ -285,6 +285,7 @@ extern int scanhash_quark(int thr_id, struct work *work, uint32_t max_nonce, uns
extern int scanhash_qubit(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_skeincoin(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_skein2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_s3(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_whirlx(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_x11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
@@ -294,6 +295,8 @@ extern int scanhash_x15(int thr_id, struct work* work, uint32_t max_nonce, unsig
extern int scanhash_x17(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_sha256d(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_scrypt(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done,
unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end);
@@ -324,6 +327,7 @@ extern void free_quark(int thr_id);
extern void free_qubit(int thr_id);
extern void free_skeincoin(int thr_id);
extern void free_skein2(int thr_id);
extern void free_spreadx11(int thr_id);
extern void free_s3(int thr_id);
extern void free_whirlx(int thr_id);
extern void free_x11(int thr_id);
@@ -606,6 +610,9 @@ struct work {
uint32_t scanned_from;
uint32_t scanned_to;
/* custom stuff */
void * extradata;
/* pok getwork txs */
uint32_t tx_count;
struct tx txs[POK_MAX_TXS];
@@ -756,6 +763,7 @@ void scrypthash(void* output, const void* input);
void scryptjane_hash(void* output, const void* input);
void skeincoinhash(void *output, const void *input);
void skein2hash(void *output, const void *input);
void spreadhash(void *output, const void *input);
void s3hash(void *output, const void *input);
void whirlxHash(void *state, const void *input);
void x11hash(void *output, const void *input);
+695
View File
@@ -0,0 +1,695 @@
/*
Based on libtommath and tomsfastmath by Tom St Denis
This is basically Barret reduction and it's setup from libtommath and
basic bignum types and functions from tomsfastmath with some application
specific optimizations like dropping sign handling and branches that are
never reached, hard coding for a specific digit size (replacing slow ops like
x % DIGIT_BIT with x & 31 etc).
Could probably do a lot better with CUDA, this code spills to local memory
like a mofo due to dynamic array indexes.
*/
#include <stdint.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef MAX
#define MAX(x,y) ((x)>(y)?(x):(y))
#endif
#define DIGIT_BIT 32
#define FP_SIZE 20
typedef uint32_t fp_digit;
typedef uint64_t fp_word;
typedef fp_digit fp_min_u32;
/* return codes */
#define FP_OKAY 0
#define FP_VAL 1
#define FP_MEM 2
/* equalities */
#define FP_LT -1 /* less than */
#define FP_EQ 0 /* equal to */
#define FP_GT 1 /* greater than */
/* replies */
#define FP_YES 1 /* yes response */
#define FP_NO 0 /* no response */
typedef int fp_err;
typedef struct {
int used;
fp_digit dp[FP_SIZE];
} fp_int;
#define USED(m) ((m)->used)
#define DIGIT(m,k) ((m)->dp[(k)])
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
#define fp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
#define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
#define fp_init(a) fp_zero((a))
#define fp_mul(a,b,c) fp_mul_comba((a), (b), (c))
/* clamp digits */
#define fp_clamp(a) { while ((a)->used && (a)->dp[(a)->used-1] == 0) --((a)->used); }
__device__ __host__ void fp_zero( fp_int *a )
{
for( int i = 0; i < FP_SIZE; i++ ) a->dp[i] = 0;
a->used = 0;
}
__device__ __host__ void fp_set( fp_int *a, fp_digit b )
{
fp_zero(a);
a->dp[0] = b;
a->used = a->dp[0] ? 1 : 0;
}
__device__ __host__ int fp_cmp_mag( fp_int *a, fp_int *b )
{
if( a->used > b->used ) return FP_GT;
else if( a->used < b->used ) return FP_LT;
for( int x = a->used - 1; x >= 0; x-- ) {
if( a->dp[x] > b->dp[x] ) return FP_GT;
else if( a->dp[x] < b->dp[x] ) return FP_LT;
}
return FP_EQ;
}
/* unsigned addition */
__device__ __host__ void s_fp_add(fp_int *a, fp_int *b, fp_int *c)
{
int x, y, oldused;
fp_word t;
y = MAX(a->used, b->used);
oldused = c->used;
c->used = y;
t = 0;
for (x = 0; x < y; x++) {
t += ((fp_word)a->dp[x]) + ((fp_word)b->dp[x]);
c->dp[x] = (fp_digit)t;
t >>= DIGIT_BIT;
}
if (t != 0 && x < FP_SIZE) {
c->dp[c->used++] = (fp_digit)t;
++x;
}
c->used = x;
for (; x < oldused; x++) {
c->dp[x] = 0;
}
fp_clamp(c);
}
/* unsigned subtraction ||a|| >= ||b|| ALWAYS! */
__device__ __host__ void s_fp_sub(fp_int *a, fp_int *b, fp_int *c)
{
int x, oldbused, oldused;
fp_word t;
oldused = c->used;
oldbused = b->used;
c->used = a->used;
t = 0;
for (x = 0; x < oldbused; x++) {
t = ((fp_word)a->dp[x]) - (((fp_word)b->dp[x]) + t);
c->dp[x] = (fp_digit)t;
t = (t >> DIGIT_BIT)&1;
}
for (; x < a->used; x++) {
t = ((fp_word)a->dp[x]) - t;
c->dp[x] = (fp_digit)t;
t = (t >> DIGIT_BIT)&1;
}
for (; x < oldused; x++) {
c->dp[x] = 0;
}
fp_clamp(c);
}
__device__ __host__ void fp_add( fp_int *a, fp_int *b, fp_int *c )
{
s_fp_add (a, b, c);
}
/* c = a - b */
__device__ __host__ void fp_sub(fp_int *a, fp_int *b, fp_int *c)
{
// int sa, sb;
/* The first has a larger or equal magnitude */
s_fp_sub (a, b, c);
}
__device__ __host__ int fp_cmp(fp_int *a, fp_int *b)
{
return fp_cmp_mag(a, b);
}
__device__ __host__ void fp_copy( fp_int *a, fp_int *b )
{
for( int i = 0; i < FP_SIZE; i++ ) b->dp[i] = a->dp[i];
b->used = a->used;
}
// TODO: use clz, return a->used - clz(a->dp[a->used-1])
__device__ __host__ int fp_count_bits( fp_int *a )
{
int r;
fp_digit q;
/* shortcut */
if (a->used == 0) return 0;
/* get number of digits and add that */
r = (a->used - 1) << 5;
/* take the last digit and count the bits in it */
q = a->dp[a->used - 1];
while (q > ((fp_digit) 0)) {
++r;
q >>= ((fp_digit) 1);
}
return r;
}
__device__ __host__ void fp_rshd( fp_int *a, int x )
{
int y;
/* too many digits just zero and return */
if (x >= a->used) {
fp_zero(a);
return;
}
/* shift */
for (y = 0; y < a->used - x; y++) a->dp[y] = a->dp[y+x];
/* zero rest */
for (; y < a->used; y++) a->dp[y] = 0;
/* decrement count */
a->used -= x;
fp_clamp(a);
}
__device__ __host__ void fp_lshd(fp_int *a, int x)
{
int y;
/* move up and truncate as required */
y = MIN(a->used + x - 1, (int)(FP_SIZE-1));
/* store new size */
a->used = y + 1;
/* move digits */
for (; y >= x; y--) a->dp[y] = a->dp[y-x];
/* zero lower digits */
for (; y >= 0; y--) a->dp[y] = 0;
/* clamp digits */
fp_clamp(a);
}
/* c = a * 2**d */
__device__ __host__ void fp_mul_2d( fp_int *a, int b, fp_int *c )
{
fp_digit carry, carrytmp, shift;
int x;
/* copy it */
fp_copy(a, c);
/* handle whole digits */
if (b >= DIGIT_BIT) {
fp_lshd(c, b >> 5);
}
b &= 31;
/* shift the digits */
if (b != 0) {
carry = 0;
shift = DIGIT_BIT - b;
for (x = 0; x < c->used; x++) {
carrytmp = c->dp[x] >> shift;
c->dp[x] = (c->dp[x] << b) + carry;
carry = carrytmp;
}
/* store last carry if room */
if (carry && x < FP_SIZE) c->dp[c->used++] = carry;
}
fp_clamp(c);
}
/* c = a * b */
__device__ __host__ void fp_mul_d( fp_int *a, fp_digit b, fp_int *c )
{
fp_word w;
int x, oldused;
oldused = c->used;
c->used = a->used;
w = 0;
for (x = 0; x < a->used; x++) {
w = ((fp_word)a->dp[x]) * ((fp_word)b) + w;
c->dp[x] = (fp_digit)w;
w = w >> DIGIT_BIT;
}
if (w != 0 && (a->used != FP_SIZE)) {
c->dp[c->used++] = w;
++x;
}
for (; x < oldused; x++) c->dp[x] = 0;
fp_clamp(c);
}
/* c = a mod 2**d */
__device__ __host__ void fp_mod_2d( fp_int *a, int b, fp_int *c )
{
int x;
/* zero if count less than or equal to zero */
if (b <= 0) {
fp_zero(c);
return;
}
/* get copy of input */
fp_copy(a, c);
/* if 2**d is larger than we just return */
if (b >= (a->used << 5)) return;
/* zero digits above the last digit of the modulus */
for (x = (b >> 5) + ((b & 31) == 0 ? 0 : 1); x < c->used; x++) {
c->dp[x] = 0;
}
/* clear the digit that is not completely outside/inside the modulus */
c->dp[b >> 5] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
fp_clamp (c);
}
/* c = a / 2**b */
__device__ __host__ void fp_div_2d( fp_int *a, int b, fp_int *c, fp_int *d )
{
fp_digit D, r, rr;
int x;
fp_int t;
/* if the shift count is <= 0 then we do no work */
if (b <= 0) {
fp_copy (a, c);
if (d != NULL) fp_zero (d);
return;
}
fp_zero(&t);
/* get the remainder */
if (d != NULL) fp_mod_2d (a, b, &t);
/* copy */
fp_copy(a, c);
/* shift by as many digits in the bit count */
if (b >= (int)DIGIT_BIT) fp_rshd (c, b >> 5);
/* shift any bit count < DIGIT_BIT */
D = (fp_digit) (b & 31);
if (D != 0) {
fp_digit *tmpc, mask, shift;
/* mask */
mask = (((fp_digit)1) << D) - 1;
/* shift for lsb */
shift = DIGIT_BIT - D;
/* alias */
tmpc = c->dp + (c->used - 1);
/* carry */
r = 0;
for (x = c->used - 1; x >= 0; x--) {
/* get the lower bits of this word in a temp */
rr = *tmpc & mask;
/* shift the current word and mix in the carry bits from the previous word */
*tmpc = (*tmpc >> D) | (r << shift);
--tmpc;
/* set the carry to the carry bits of the current word found above */
r = rr;
}
}
fp_clamp (c);
if (d != NULL) fp_copy (&t, d);
}
/* a/b => cb + d == a */
__device__ __host__ void fp_div( fp_int *a, fp_int *b, fp_int *c, fp_int *d )
{
fp_int q, x, y, t1, t2;
int n, t, i, norm;
/* if a < b then q=0, r = a */
if( fp_cmp_mag(a, b) == FP_LT ) {
if (d != NULL) fp_copy(a, d);
if (c != NULL) fp_zero(c);
return;
}
fp_init(&q);
q.used = a->used + 2;
fp_init(&t1);
fp_init(&t2);
fp_copy(a, &x);
fp_copy(b, &y);
/* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
norm = fp_count_bits(&y) & 31;
if (norm < (int)(DIGIT_BIT-1)) {
norm = (DIGIT_BIT-1) - norm;
fp_mul_2d (&x, norm, &x);
fp_mul_2d (&y, norm, &y);
}
else {
norm = 0;
}
/* note hac does 0 based, so if used==5 then its 0,1,2,3,4, e.g. use 4 */
n = x.used - 1;
t = y.used - 1;
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
fp_lshd (&y, n - t); /* y = y*b**{n-t} */
while (fp_cmp (&x, &y) != FP_LT) {
++(q.dp[n - t]);
fp_sub (&x, &y, &x);
}
/* reset y by shifting it back down */
fp_rshd (&y, n - t);
/* step 3. for i from n down to (t + 1) */
for (i = n; i >= (t + 1); i--) {
if (i > x.used) continue;
/* step 3.1 if xi == yt then set q{i-t-1} to b-1,
* otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
if (x.dp[i] == y.dp[t]) {
q.dp[i - t - 1] = ((((fp_word)1) << DIGIT_BIT) - 1);
}
else {
fp_word tmp;
tmp = ((fp_word) x.dp[i]) << ((fp_word) DIGIT_BIT);
tmp |= ((fp_word) x.dp[i - 1]);
tmp /= ((fp_word) y.dp[t]);
q.dp[i - t - 1] = (fp_digit) (tmp);
}
/* while (q{i-t-1} * (yt * b + y{t-1})) >
xi * b**2 + xi-1 * b + xi-2
do q{i-t-1} -= 1;
*/
q.dp[i - t - 1] = (q.dp[i - t - 1] + 1);
do {
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1);
/* find left hand */
fp_zero (&t1);
t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1];
t1.dp[1] = y.dp[t];
t1.used = 2;
fp_mul_d (&t1, q.dp[i - t - 1], &t1);
/* find right hand */
t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2];
t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1];
t2.dp[2] = x.dp[i];
t2.used = 3;
} while (fp_cmp_mag(&t1, &t2) == FP_GT);
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
fp_mul_d (&y, q.dp[i - t - 1], &t1);
fp_lshd (&t1, i - t - 1);
fp_sub (&x, &t1, &x);
}
/* now q is the quotient and x is the remainder
* [which we have to normalize]
*/
if (c != NULL) {
fp_clamp (&q);
fp_copy (&q, c);
}
if (d != NULL) {
fp_div_2d (&x, norm, &x, NULL);
/* the following is a kludge, essentially we were seeing the right remainder but
with excess digits that should have been zero
*/
for (i = b->used; i < x.used; i++) x.dp[i] = 0;
fp_clamp(&x);
fp_copy (&x, d);
}
}
__device__ __host__ void fp_2expt( fp_int *a, int b )
{
int z;
fp_zero (a);
z = b >> 5;
/* set the used count of where the bit will go */
a->used = z + 1;
/* put the single bit in its place */
a->dp[z] = ((fp_digit)1) << (b & 31);
}
/* generic PxQ multiplier */
__device__ __host__ void fp_mul_comba(fp_int *A, fp_int *B, fp_int *C)
{
int ix, iy, iz, tx, ty, pa;
fp_digit c0, c1, c2, *tmpx, *tmpy;
fp_int tmp, *dst;
c0 = c1 = c2 = 0;
/* get size of output and trim */
pa = A->used + B->used;
if (pa >= FP_SIZE) pa = FP_SIZE-1;
if (A == C || B == C) {
fp_zero(&tmp);
dst = &tmp;
}
else {
fp_zero(C);
dst = C;
}
for (ix = 0; ix < pa; ix++) {
/* get offsets into the two bignums */
ty = MIN(ix, B->used-1);
tx = ix - ty;
/* setup temp aliases */
tmpx = A->dp + tx;
tmpy = B->dp + ty;
/* this is the number of times the loop will iterrate, essentially its
while (tx++ < a->used && ty-- >= 0) { ... }
*/
iy = MIN(A->used-tx, ty+1);
/* execute loop */
c0 = c1; c1 = c2; c2 = 0;
for (iz = 0; iz < iy; ++iz) {
fp_word t;
t = (fp_word)c0 + ((fp_word)*tmpx++) * ((fp_word)*tmpy--);
c0 = t;
t = (fp_word)c1 + (t >> DIGIT_BIT);
c1 = t;
c2 += t >> DIGIT_BIT;
}
/* store term */
dst->dp[ix] = c0;
}
dst->used = pa;
fp_clamp(dst);
fp_copy(dst, C);
}
__device__ __host__ void fp_read_unsigned_bin(fp_int *a, unsigned char *b, int c)
{
/* zero the int */
fp_zero (a);
unsigned char *pd = (unsigned char *)a->dp;
if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) {
int excess = c - (FP_SIZE * sizeof(fp_digit));
c -= excess;
b += excess;
}
a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
/* read the bytes in */
for (c -= 1; c >= 0; c -= 1) {
pd[c] = *b++;
}
fp_clamp (a);
}
__device__ __host__ void fp_reverse( unsigned char *s, int len )
{
int ix, iy;
unsigned char t;
ix = 0;
iy = len - 1;
while (ix < iy) {
t = s[ix];
s[ix] = s[iy];
s[iy] = t;
++ix;
--iy;
}
}
__device__ __host__ void fp_to_unsigned_bin( fp_int *a, unsigned char *b )
{
int x;
fp_int t;
fp_copy(a, &t);
x = 0;
while (fp_iszero (&t) == FP_NO) {
b[x++] = (unsigned char) (t.dp[0] & 255);
fp_div_2d (&t, 8, &t, NULL);
}
fp_reverse (b, x);
}
__device__ __host__ void fp_reduce_setup( fp_int *a, fp_int *b )
{
fp_2expt (a, b->used << 6);
fp_div (a, b, a, NULL);
}
/* compare against a single digit */
__device__ __host__ int fp_cmp_d( fp_int *a, fp_digit b )
{
/* compare based on magnitude */
if (a->used > 1) return FP_GT;
/* compare the only digit of a to b */
if (a->dp[0] > b) return FP_GT;
else if (a->dp[0] < b) return FP_LT;
return FP_EQ;
}
__device__ __host__ void fp_reduce( fp_int *x, fp_int *m, fp_int *mu )
{
fp_int q;
int um = m->used;
if( fp_cmp (x, m) == FP_LT ) return;
/* q = x */
fp_copy (x, &q);
/* q1 = x / b**(k-1) */
fp_rshd (&q, um - 1);
fp_mul (&q, mu, &q);
/* q3 = q2 / b**(k+1) */
fp_rshd (&q, um + 1);
/* x = x mod b**(k+1), quick (no division) */
fp_mod_2d (x, ((um + 1) << 5), x);
/* q = q * m mod b**(k+1), quick (no division) */
//s_fp_mul_digs (&q, m, &q, um + 1);
// FIXME: actually multiply up to required digits instead of full multiply + truncation
fp_mul(&q, m, &q);
q.used = um + 1;
for( int i = q.used; i < FP_SIZE; i++ ) q.dp[i] = 0;
/* x = x - q */
fp_sub (x, &q, x);
/* If x < 0, add b**(k+1) to it */
// FIXME: does this ever happen..?
if (fp_cmp_d (x, 0) == FP_LT) {
fp_set (&q, 1);
fp_lshd (&q, um + 1);
fp_add (x, &q, x);
}
int count = 0;
/* Back off if it's too big */
while( fp_cmp (x, m) != FP_LT ) {
s_fp_sub (x, m, x);
count++;
if( count > 100 ) {
//printf("FUCK ME I GOT STUCK IN THE REDUCE WHILE LOOP, AGAIN!!!!\n");
break;
}
}
}
+291
View File
@@ -0,0 +1,291 @@
#include <stdint.h>
#include <stdio.h>
#include <memory.h>
#include "../cuda_helper.h"
__constant__ uint64_t c_PaddedMessage[32];
__constant__ uint32_t c_sigma[16][16];
const uint32_t host_sigma[16][16] =
{
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
};
static __device__ uint32_t HIWORD(const uint64_t x)
{
uint32_t result;
asm(
"{\n\t"
".reg .u32 xl; \n\t"
"mov.b64 {xl,%0},%1; \n\t"
"}" : "=r"(result) : "l"(x)
);
return result;
}
static __device__ uint32_t LOWORD(const uint64_t x)
{
uint32_t result;
asm(
"{\n\t"
".reg .u32 xh; \n\t"
"mov.b64 {%0,xh},%1; \n\t"
"}" : "=r"(result) : "l"(x)
);
return result;
}
__device__ __forceinline__ uint64_t SWAP64( const uint64_t x)
{
uint64_t temp[2];
temp[0] = __byte_perm(HIWORD(x), 0, 0x0123);
temp[1] = __byte_perm(LOWORD(x), 0, 0x0123);
return temp[0] | (temp[1]<<32);
}
__host__ uint64_t host_SWAP64( uint64_t x )
{
return
((x & 0xff00000000000000) >> 56) |
((x & 0x00ff000000000000) >> 40) |
((x & 0x0000ff0000000000) >> 24) |
((x & 0x000000ff00000000) >> 8) |
((x & 0x00000000ff000000) << 8) |
((x & 0x0000000000ff0000) << 24) |
((x & 0x000000000000ff00) << 40) |
((x & 0x00000000000000ff) << 56);
}
__constant__ uint64_t c_u512[16];
const uint64_t host_u512[16] =
{
0x243f6a8885a308d3ULL, 0x13198a2e03707344ULL,
0xa4093822299f31d0ULL, 0x082efa98ec4e6c89ULL,
0x452821e638d01377ULL, 0xbe5466cf34e90c6cULL,
0xc0ac29b7c97c50ddULL, 0x3f84d5b5b5470917ULL,
0x9216d5d98979fb1bULL, 0xd1310ba698dfb5acULL,
0x2ffd72dbd01adfb7ULL, 0xb8e1afed6a267e96ULL,
0xba7c9045f12c7f99ULL, 0x24a19947b3916cf7ULL,
0x0801f2e2858efc16ULL, 0x636920d871574e69ULL
};
__forceinline__ __device__ uint64_t ROTR(const uint64_t value, const int offset) {
uint64_t result;
#if __CUDA_ARCH__ >= 320
if(offset < 32) {
asm("{\n\t"
" .reg .u32 tl,th,vl,vh; \n\t"
"mov.b64 {tl,th},%1; \n\t"
"shf.r.wrap.b32 vl,tl,th,%2; \n\t"
"shf.r.wrap.b32 vh,th,tl,%2; \n\t"
"mov.b64 %0,{vl,vh}; \n\t"
"}"
: "=l"(result) : "l"(value) , "r"(offset));
} else {
asm("{\n\t"
" .reg .u32 tl,th,vl,vh; \n\t"
"mov.b64 {tl,th},%1; \n\t"
"shf.r.wrap.b32 vh,tl,th,%2; \n\t"
"shf.r.wrap.b32 vl,th,tl,%2; \n\t"
"mov.b64 %0,{vl,vh}; \n\t"
"}"
: "=l"(result) : "l"(value) , "r"(offset));
}
#else
result = (value >> offset) | (value << (64-offset));
#endif
return result;
}
__device__ __forceinline__ uint64_t ROTR64_32( uint64_t val )
{
asm("{\n\t"
".reg .u32 tl,th; \n\t"
"mov.b64 {tl,th},%1; \n\t"
"mov.b64 %0,{th,tl}; \n\t"
"}"
: "=l"(val) : "l"(val));
return val;
}
__device__ __forceinline__ uint64_t ROTR64_16( uint64_t val )
{
asm("{\n\t"
".reg .u16 b0, b1, b2, b3; \n\t"
"mov.b64 { b0, b1, b2, b3 }, %1; \n\t"
"mov.b64 %0, {b1, b2, b3, b0}; \n\t"
"}"
: "=l"(val) : "l"(val));
return val;
}
#define G(a,b,c,d,e) \
v[a] += (m[c_sigma[i][e]] ^ c_u512[c_sigma[i][e+1]]) + v[b]; \
v[d] = ROTR64_32(v[d] ^ v[a]); \
v[c] += v[d]; \
v[b] = ROTR( v[b] ^ v[c],25); \
v[a] += (m[c_sigma[i][e+1]] ^ c_u512[c_sigma[i][e]])+v[b]; \
v[d] = ROTR64_16(v[d] ^ v[a]); \
v[c] += v[d]; \
v[b] = ROTR( v[b] ^ v[c],11); \
__device__ void blake_compress( uint64_t *h, const uint64_t *m, const int bits )
{
uint64_t v[16];
#pragma unroll 8
for( int i = 0; i < 8; ++i ) v[i] = h[i];
v[ 8] = c_u512[0];
v[ 9] = c_u512[1];
v[10] = c_u512[2];
v[11] = c_u512[3];
v[12] = c_u512[4] ^ bits;
v[13] = c_u512[5] ^ bits;
v[14] = c_u512[6];
v[15] = c_u512[7];
#pragma unroll 2
for( int i = 0; i < 16; ++i )
{
/* column step */
G( 0, 4, 8, 12, 0 );
G( 1, 5, 9, 13, 2 );
G( 2, 6, 10, 14, 4 );
G( 3, 7, 11, 15, 6 );
/* diagonal step */
G( 0, 5, 10, 15, 8 );
G( 1, 6, 11, 12, 10 );
G( 2, 7, 8, 13, 12 );
G( 3, 4, 9, 14, 14 );
}
#pragma unroll 8
for( int i = 0; i < 8; ++i ) h[i] ^= v[i] ^ v[i+8];
}
static __device__ uint32_t cuda_swap32(uint32_t x)
{
return __byte_perm(x, 0, 0x0123);
}
static __constant__ uint64_t d_IV[8];
static const uint64_t h_IV[8] = {
0x6a09e667f3bcc908ULL,
0xbb67ae8584caa73bULL,
0x3c6ef372fe94f82bULL,
0xa54ff53a5f1d36f1ULL,
0x510e527fade682d1ULL,
0x9b05688c2b3e6c1fULL,
0x1f83d9abfb41bd6bULL,
0x5be0cd19137e2179ULL
};
__global__ void blake_gpu_hash_185(uint32_t threads, uint32_t startNonce, uint32_t *outputHash, uint32_t *g_signature, uint32_t *g_hashwholeblock)
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
// bestimme den aktuellen Zähler
uint32_t nonce = startNonce + thread;
uint32_t idx64 = thread >> 6;
uint64_t h[8];
uint64_t buf[16];
uint64_t *hashwholeblock = (uint64_t *)&g_hashwholeblock[idx64 << 3];
uint64_t *signature = (uint64_t *)&g_signature[idx64 << 3];
#pragma unroll 8
for(int i=0;i<8;i++)
h[i] = d_IV[i];
#pragma unroll 11
for (int i=0; i < 11; ++i) buf[i] = SWAP64(c_PaddedMessage[i]);
((uint32_t *)buf)[20] = cuda_swap32(nonce);
#pragma unroll 4
for (int i=0; i < 4; ++i) buf[i+11] = SWAP64(hashwholeblock[i]);
buf[15] = SWAP64(c_PaddedMessage[15]);
blake_compress( h, buf, 1024 );
#pragma unroll 16
for (int i=0; i < 16; ++i) buf[i] = c_PaddedMessage[i+16];
#pragma unroll 32
for (int i=0; i < 32; ++i) ((unsigned char *)buf)[25+i] = ((unsigned char *)signature)[i];//SWAP64(signature[i]);
for (int i=0; i < 16; ++i) buf[i] = SWAP64(buf[i]);
blake_compress( h, buf, 1480 );
uint32_t *outHash = (uint32_t *)outputHash + 16 * thread;
#pragma unroll 8
for (int i=0; i < 8; ++i) {
outHash[2*i+0] = cuda_swap32( HIWORD(h[i]) );
outHash[2*i+1] = cuda_swap32( LOWORD(h[i]) );
}
}
}
__host__
void blake_cpu_init(int thr_id, uint32_t threads)
{
cudaMemcpyToSymbol(c_sigma, host_sigma, sizeof(host_sigma), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(c_u512, host_u512, sizeof(host_u512), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(d_IV, h_IV, sizeof(h_IV), 0, cudaMemcpyHostToDevice);
}
__host__
void blake_cpu_setBlock_185(void *pdata)
{
unsigned char PaddedMessage[256];
memcpy(PaddedMessage, pdata, 185);
memset(PaddedMessage+185, 0, 71);
PaddedMessage[185] = 0x80;
PaddedMessage[239] = 1;
PaddedMessage[254] = 0x05;
PaddedMessage[255] = 0xC8;
//for( int i = 0; i < 32; i++ ) ((uint64_t *)PaddedMessage)[i] = host_SWAP64(((uint64_t *)PaddedMessage)[i]);
cudaMemcpyToSymbol(c_PaddedMessage, PaddedMessage, 32*sizeof(uint64_t), 0, cudaMemcpyHostToDevice);
}
__host__
void blake_cpu_hash_185(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_outputHash, uint32_t *d_signature, uint32_t *d_hashwholeblock)
{
const int threadsperblock = 64;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
size_t shared_size = 0;
blake_gpu_hash_185<<<grid, block, shared_size>>>(threads, startNonce, d_outputHash, d_signature, d_hashwholeblock);
cudaDeviceSynchronize();
}
+501
View File
@@ -0,0 +1,501 @@
#include <stdio.h>
#include <stdint.h>
#include <memory.h>
#include "miner.h"
#include "spreadx11.h"
__constant__ uint32_t c_PaddedMessage88[32]; // padded message, 88 bytes + padding to 128 bytes
// precalculated state for sha256double_88
static __constant__ uint32_t d_state[8];
// init vector
static __constant__ uint32_t d_IV[8];
static const uint32_t h_IV[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
// round constants
static __constant__ uint32_t d_K[64];
static const uint32_t h_K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
// padding for 400000 bytes of input data
static __constant__ uint32_t padding400000[16] = {
0x80000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x0030d400
};
// padding for 32 bytes of input data
static __constant__ uint32_t padding32[16] = {
0x80000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000100
};
__device__ __host__ __forceinline__ uint32_t ROTR32( const uint32_t val, const size_t offset )
{
#if __CUDA_ARCH__ >= 320
return __funnelshift_r(val, val, offset);
#else
return (val >> offset) | (val << (32-offset));
#endif
}
static __device__ uint32_t cuda_swab32(uint32_t x)
{
return __byte_perm(x, x, 0x0123);
}
__host__ uint32_t bswap32( const uint32_t x )
{
return
((x & 0xff000000) >> 24 ) |
((x & 0x00ff0000) >> 8 ) |
((x & 0x0000ff00) << 8 ) |
((x & 0x000000ff) << 24 );
}
__device__ __host__ __forceinline__ uint32_t BSG2_0( const uint32_t x )
{
return
ROTR32(x, 2) ^
ROTR32(x, 13) ^
ROTR32(x, 22);
}
__device__ __host__ __forceinline__ uint32_t BSG2_1( const uint32_t x )
{
return
ROTR32(x, 6) ^
ROTR32(x, 11) ^
ROTR32(x, 25);
}
__device__ __host__ __forceinline__ uint32_t SSG2_0( const uint32_t x )
{
return
ROTR32(x, 7) ^
ROTR32(x, 18) ^
(x >> 3);
}
__device__ __host__ __forceinline__ uint32_t SSG2_1( const uint32_t x )
{
return
ROTR32(x, 17) ^
ROTR32(x, 19) ^
(x >> 10);
}
__device__ __host__ __forceinline__ uint32_t CH( const uint32_t x, const uint32_t y, const uint32_t z )
{
return ((y ^ z) & x) ^ z;
}
__device__ __host__ __forceinline__ uint32_t MAJ( const uint32_t x, const uint32_t y, const uint32_t z )
{
return (x & y) | ((x | y) & z);
}
__device__ __host__ __forceinline__ void sha2_step1( uint32_t *W, const uint32_t *K, const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d,
const uint32_t e, const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t *in, const uint32_t pc, const uint32_t pcount )
{
W[pc] = in[pc];
uint32_t t1 =
h + BSG2_1(e) + CH(e, f, g) +
K[pcount + pc] + W[pc];
d += t1;
h = t1 + BSG2_0(a) + MAJ(a, b, c);
}
__device__ __host__ __forceinline__ void sha2_step2( uint32_t *W, const uint32_t *K, const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d,
const uint32_t e, const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t *in, const uint32_t pc, const uint32_t pcount )
{
uint32_t t1;
W[pc] = SSG2_1(W[(pc - 2) & 0x0F])
+ W[(pc - 7) & 0x0F]
+ SSG2_0(W[(pc - 15) & 0x0F]) + W[pc];
t1 = h + BSG2_1(e) + CH(e, f, g)
+ K[pcount + (pc)] + W[(pc)];
d += t1;
h = t1 + BSG2_0(a) + MAJ(a, b, c);
}
__device__
void sha2_transform(const uint32_t *in, uint32_t *state)
{
uint32_t a, b, c, d, e, f, g, h;
uint32_t w[16];
uint32_t pcount;
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
f = state[5];
g = state[6];
h = state[7];
pcount = 0;
sha2_step1(w, d_K, a, b, c, d, e, f, g, h, in, 0, pcount);
sha2_step1(w, d_K, h, a, b, c, d, e, f, g, in, 1, pcount);
sha2_step1(w, d_K, g, h, a, b, c, d, e, f, in, 2, pcount);
sha2_step1(w, d_K, f, g, h, a, b, c, d, e, in, 3, pcount);
sha2_step1(w, d_K, e, f, g, h, a, b, c, d, in, 4, pcount);
sha2_step1(w, d_K, d, e, f, g, h, a, b, c, in, 5, pcount);
sha2_step1(w, d_K, c, d, e, f, g, h, a, b, in, 6, pcount);
sha2_step1(w, d_K, b, c, d, e, f, g, h, a, in, 7, pcount);
sha2_step1(w, d_K, a, b, c, d, e, f, g, h, in, 8, pcount);
sha2_step1(w, d_K, h, a, b, c, d, e, f, g, in, 9, pcount);
sha2_step1(w, d_K, g, h, a, b, c, d, e, f, in, 10, pcount);
sha2_step1(w, d_K, f, g, h, a, b, c, d, e, in, 11, pcount);
sha2_step1(w, d_K, e, f, g, h, a, b, c, d, in, 12, pcount);
sha2_step1(w, d_K, d, e, f, g, h, a, b, c, in, 13, pcount);
sha2_step1(w, d_K, c, d, e, f, g, h, a, b, in, 14, pcount);
sha2_step1(w, d_K, b, c, d, e, f, g, h, a, in, 15, pcount);
for (pcount = 16; pcount < 64; pcount += 16) {
sha2_step2(w, d_K, a, b, c, d, e, f, g, h, in, 0, pcount);
sha2_step2(w, d_K, h, a, b, c, d, e, f, g, in, 1, pcount);
sha2_step2(w, d_K, g, h, a, b, c, d, e, f, in, 2, pcount);
sha2_step2(w, d_K, f, g, h, a, b, c, d, e, in, 3, pcount);
sha2_step2(w, d_K, e, f, g, h, a, b, c, d, in, 4, pcount);
sha2_step2(w, d_K, d, e, f, g, h, a, b, c, in, 5, pcount);
sha2_step2(w, d_K, c, d, e, f, g, h, a, b, in, 6, pcount);
sha2_step2(w, d_K, b, c, d, e, f, g, h, a, in, 7, pcount);
sha2_step2(w, d_K, a, b, c, d, e, f, g, h, in, 8, pcount);
sha2_step2(w, d_K, h, a, b, c, d, e, f, g, in, 9, pcount);
sha2_step2(w, d_K, g, h, a, b, c, d, e, f, in, 10, pcount);
sha2_step2(w, d_K, f, g, h, a, b, c, d, e, in, 11, pcount);
sha2_step2(w, d_K, e, f, g, h, a, b, c, d, in, 12, pcount);
sha2_step2(w, d_K, d, e, f, g, h, a, b, c, in, 13, pcount);
sha2_step2(w, d_K, c, d, e, f, g, h, a, b, in, 14, pcount);
sha2_step2(w, d_K, b, c, d, e, f, g, h, a, in, 15, pcount);
}
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
state[5] += f;
state[6] += g;
state[7] += h;
}
__host__
void host_sha2_transform(const uint32_t *in, uint32_t *state)
{
uint32_t a, b, c, d, e, f, g, h;
uint32_t w[16];
uint32_t pcount;
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
f = state[5];
g = state[6];
h = state[7];
pcount = 0;
sha2_step1(w, h_K, a, b, c, d, e, f, g, h, in, 0, pcount);
sha2_step1(w, h_K, h, a, b, c, d, e, f, g, in, 1, pcount);
sha2_step1(w, h_K, g, h, a, b, c, d, e, f, in, 2, pcount);
sha2_step1(w, h_K, f, g, h, a, b, c, d, e, in, 3, pcount);
sha2_step1(w, h_K, e, f, g, h, a, b, c, d, in, 4, pcount);
sha2_step1(w, h_K, d, e, f, g, h, a, b, c, in, 5, pcount);
sha2_step1(w, h_K, c, d, e, f, g, h, a, b, in, 6, pcount);
sha2_step1(w, h_K, b, c, d, e, f, g, h, a, in, 7, pcount);
sha2_step1(w, h_K, a, b, c, d, e, f, g, h, in, 8, pcount);
sha2_step1(w, h_K, h, a, b, c, d, e, f, g, in, 9, pcount);
sha2_step1(w, h_K, g, h, a, b, c, d, e, f, in, 10, pcount);
sha2_step1(w, h_K, f, g, h, a, b, c, d, e, in, 11, pcount);
sha2_step1(w, h_K, e, f, g, h, a, b, c, d, in, 12, pcount);
sha2_step1(w, h_K, d, e, f, g, h, a, b, c, in, 13, pcount);
sha2_step1(w, h_K, c, d, e, f, g, h, a, b, in, 14, pcount);
sha2_step1(w, h_K, b, c, d, e, f, g, h, a, in, 15, pcount);
for (pcount = 16; pcount < 64; pcount += 16) {
sha2_step2(w, h_K, a, b, c, d, e, f, g, h, in, 0, pcount);
sha2_step2(w, h_K, h, a, b, c, d, e, f, g, in, 1, pcount);
sha2_step2(w, h_K, g, h, a, b, c, d, e, f, in, 2, pcount);
sha2_step2(w, h_K, f, g, h, a, b, c, d, e, in, 3, pcount);
sha2_step2(w, h_K, e, f, g, h, a, b, c, d, in, 4, pcount);
sha2_step2(w, h_K, d, e, f, g, h, a, b, c, in, 5, pcount);
sha2_step2(w, h_K, c, d, e, f, g, h, a, b, in, 6, pcount);
sha2_step2(w, h_K, b, c, d, e, f, g, h, a, in, 7, pcount);
sha2_step2(w, h_K, a, b, c, d, e, f, g, h, in, 8, pcount);
sha2_step2(w, h_K, h, a, b, c, d, e, f, g, in, 9, pcount);
sha2_step2(w, h_K, g, h, a, b, c, d, e, f, in, 10, pcount);
sha2_step2(w, h_K, f, g, h, a, b, c, d, e, in, 11, pcount);
sha2_step2(w, h_K, e, f, g, h, a, b, c, d, in, 12, pcount);
sha2_step2(w, h_K, d, e, f, g, h, a, b, c, in, 13, pcount);
sha2_step2(w, h_K, c, d, e, f, g, h, a, b, in, 14, pcount);
sha2_step2(w, h_K, b, c, d, e, f, g, h, a, in, 15, pcount);
}
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
state[5] += f;
state[6] += g;
state[7] += h;
}
__global__
void spreadx11_sha256_gpu_hash_wholeblock(uint32_t threads, uint32_t startNonce, uint32_t *g_input, uint32_t *g_hash, uint32_t *g_signature)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t state[8];
uint32_t input[16];
uint32_t *outputHash = (uint32_t *)&g_hash[thread<<3];
uint8_t *signature = (uint8_t *)&g_signature[thread<<3];
#pragma unroll 8
for( int i=0; i < 8; i++ ) state[i] = d_IV[i];
/*
Input is as follows, we need to replace nonce and MinerSignature for each hash.
This means the first two blocks need to be handled separately.
4 bytes (nNonce & ~NONCE_MASK)
8 bytes nTime;
65 bytes MinerSignature;
4 bytes nVersion;
and so on....
*/
// we process the same 200000 bytes of data twice
for( int round = 0; round < 2; round++ ) {
// insert nonce
input[0] = startNonce + (thread << 6);
// read the rest of the block
#pragma unroll 15
for( int i=1; i < 16; i++ ) input[i] = g_input[i];
// first 19 bytes of signature go into the first block
#pragma unroll 19
for( int i = 0; i < 19; i++ ) ((uint8_t *)input)[45+i] = signature[i];
// endian swap the block and transform
#pragma unroll 16
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(input[i]);
sha2_transform(input, state);
// read the second block
#pragma unroll 16
for( int i=0; i < 16; i++ ) input[i] = g_input[i+16];
// replace in the remaining bytes of the signature
#pragma unroll 13
for( int i = 0; i < 13; i++ ) ((uint8_t *)input)[i] = signature[i+19];
// endian swap the second block and transform
#pragma unroll 16
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(input[i]);
sha2_transform(input, state);
// transform the remaining blocks as they are
for( int block = 2; block < 3125; block++ ) {
#pragma unroll 16
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(g_input[i+(block << 4)]);
sha2_transform(input, state);
}
}
// load and transform the padding block
#pragma unroll 16
for( int i = 0; i < 16; i++ ) input[i] = padding400000[i];
sha2_transform(input, state);
#pragma unroll 8
for( int i=0; i < 8; i++ ) outputHash[i] = cuda_swab32(state[i]);
}
}
__global__
void spreadx11_sha256double_gpu_hash_88(uint32_t threads, uint32_t startNonce, uint32_t *g_hash)
{
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
uint32_t state[8];
uint32_t input[16];
uint32_t nonce = startNonce + (thread << 6);
uint32_t *outputHash = (uint32_t *)&g_hash[thread<<3];
// load precalculated state from the first block
#pragma unroll 8
for( int i = 0; i < 8; i++ ) state[i] = d_state[i];
#pragma unroll 16
for( int i = 0; i < 16; i++ ) input[i] = cuda_swab32(c_PaddedMessage88[i+16]);
input[5] = cuda_swab32(nonce);
sha2_transform(input, state);
// finished hashing the input data, next step: hash the first result hash
#pragma unroll 8
for( int i = 0; i < 8; i++ ) {
input[i] = state[i];
input[i+8] = padding32[i];
state[i] = d_IV[i];
}
sha2_transform(input, state);
#pragma unroll 8
for( int i = 0; i < 8; i++ ) outputHash[i] = cuda_swab32(state[i]);
}
}
__host__
void spreadx11_sha256_cpu_init(int thr_id, uint32_t threads)
{
cudaMemcpyToSymbol(d_K, h_K, sizeof(h_K), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(d_IV, h_IV, sizeof(h_IV), 0, cudaMemcpyHostToDevice);
}
__host__
void spreadx11_sha256double_cpu_hash_88(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
spreadx11_sha256double_gpu_hash_88<<<grid, block>>>(threads, startNonce, d_hash);
cudaDeviceSynchronize();
}
__host__
void spreadx11_sha256double_setBlock_88(void *data)
{
unsigned char PaddedMessage[128];
uint32_t tmpstate[8], tmpinput[16];
memcpy(PaddedMessage, data, 88);
memset(PaddedMessage+88, 0, 40);
PaddedMessage[ 88] = 0x80;
PaddedMessage[126] = 0x02;
PaddedMessage[127] = 0xC0;
// we can transform the first block here and start the CUDA kernel with the precalculated state
for( int i = 0; i < 8; i++ ) tmpstate[i] = h_IV[i];
for( int i = 0; i < 16; i++ ) tmpinput[i] = bswap32(((uint32_t *)PaddedMessage)[i]);
host_sha2_transform(tmpinput, tmpstate);
cudaMemcpyToSymbol(d_state, tmpstate, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(c_PaddedMessage88, PaddedMessage, 128, 0, cudaMemcpyHostToDevice);
}
__host__
void spreadx11_sha256_setBlock_wholeblock(struct work *work, uint32_t *d_wholeblock)
{
unsigned char paddedmessage[200000];
struct spreadwork *swork = (struct spreadwork *) work->extradata;
/*
We need a hash of:
offset size field
0 4 nNonce & 0xffffffc0
4 8 nTime
12 65 MinerSignature
77 4 nVersion
81 32 hashPrevBlock
113 32 hashMerkleRoot
145 4 nBits
149 4 nHeight
153 x transactions, variable length
padding calculated backwards from the copy of hashPrevBlock at the end
199968 32 hashPrevBlock
We have in work->data:
offset size field data
0 4 nVersion 02000000
4 32 hashPrevBlock 83ac9d7e96c4bb15d1a9a2fe3dbc81747768125009efc14e3824fbacaec65fad
36 32 HashMerkleRoot 4e06a8366a959df705ea34dfe7eafea0d8a9e6fe3ba6b83afddb145b27da2362
68 8 nTime ed71585400000000
76 4 nBits 19850d1d
80 4 nHeight 33d20100
84 4 nNonce 00000000
88 32 hashWholeBlock 0000000000000000000000000000000000000000000000000000000000000000
120 33 MinerSignature1 1cad95a3e3e3598b74a1b8e2e3c013ababf6c45c83534029dbe8b4698916f78255
153 32 MinerSignature2 0000000000000000000000000000000000000000000000000000000000000000
*/
memcpy(paddedmessage+0, swork->data+84, 4); // nNonce
memcpy(paddedmessage+4, swork->data+68, 8); // nTime
memcpy(paddedmessage+12, swork->data+120, 65); // MinerSignature
memcpy(paddedmessage+77, swork->data+0, 4); // nVersion
memcpy(paddedmessage+81, swork->data+4, 32); // hashPrevBlock
memcpy(paddedmessage+113, swork->data+36, 32); // HashMerkleRoot
memcpy(paddedmessage+145, swork->data+76, 4); // nBits
memcpy(paddedmessage+149, swork->data+80, 4); // nHeight
memcpy(paddedmessage+153, swork->tx, swork->txsize); // tx
// the total amount of bytes in our data
int blocksize = 153 + swork->txsize;
// pad the block with 0x07 bytes to make it a multiple of uint32_t
while( blocksize & 3 ) paddedmessage[blocksize++] = 0x07;
// figure out the offsets for the padding
uint32_t *pFillBegin = (uint32_t*)&paddedmessage[blocksize];
uint32_t *pFillEnd = (uint32_t*)&paddedmessage[MAX_BLOCK_SIZE]; // FIXME: isn't this out of bounds by one... but it seems to work out...
uint32_t *pFillFooter = pFillBegin > pFillEnd - 8 ? pFillBegin : pFillEnd - 8;
memcpy(pFillFooter, swork->data+4, (pFillEnd - pFillFooter)*4);
for (uint32_t *pI = pFillFooter; pI < pFillEnd; pI++)
*pI |= 1;
for (uint32_t *pI = pFillFooter - 1; pI >= pFillBegin; pI--)
pI[0] = pI[3]*pI[7];
// copy the whole monstrosity into device memory for processing
cudaMemcpy(d_wholeblock, paddedmessage, 200000, cudaMemcpyHostToDevice);
}
__host__
void spreadx11_sha256_cpu_hash_wholeblock(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_wholeblock)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
spreadx11_sha256_gpu_hash_wholeblock<<<grid, block>>>(threads, startNonce, d_wholeblock, d_hash, d_signature);
cudaDeviceSynchronize();
}
+97
View File
@@ -0,0 +1,97 @@
#include <stdint.h>
#include <stdio.h>
#include <memory.h>
#include "miner.h"
#include "bignum_fp.h"
#include "spreadx11.h"
__constant__ uint32_t d_privkey_data[8]; // 32 bytes
__constant__ uint32_t d_kinv_data[8]; // 32 bytes
__constant__ uint32_t d_m_data[8] = {
0xd0364141, 0xbfd25e8c, 0xaf48a03b, 0xbaaedce6,
0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff
};
__constant__ uint32_t d_mu_data[9] = {
0x2fc9bec0, 0x402da173, 0x50b75fc4, 0x45512319,
0x00000001, 0x00000000, 0x00000000, 0x00000000,
0x00000001
};
__global__
void spreadx11_sign_gpu(uint32_t threads, uint32_t startNonce, uint32_t *g_sha256hash, uint32_t *g_signature )
{
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
if (thread < threads)
{
fp_int hash, result, m, mu, privkey, kinv;
unsigned char *sha256hash = (unsigned char *)&g_sha256hash[thread<<3];
uint32_t *signature = (uint32_t *)&g_signature[thread<<3];
fp_zero(&result);
fp_read_unsigned_bin(&hash, sha256hash, 32);
privkey.used = 8;
kinv.used = 8;
m.used = 8;
mu.used = 9;
#pragma unroll 8
for( int i = 0; i < 8; i++ ) {
privkey.dp[i] = d_privkey_data[i];
kinv.dp[i] = d_kinv_data[i];
m.dp[i] = d_m_data[i];
mu.dp[i] = d_mu_data[i];
signature[i] = 0;
}
mu.dp[8] = d_mu_data[8];
m.dp[8] = 0;
#pragma unroll
for( int i = 9; i < FP_SIZE; i++ ) {
m.dp[i] = 0;
mu.dp[i] = 0;
}
fp_add(&hash, &privkey, &result);
fp_mul(&result, &kinv, &result);
fp_reduce(&result, &m, &mu);
fp_to_unsigned_bin(&result, &((unsigned char *)signature)[32-(fp_count_bits(&result)+7)/8]);
}
}
__host__
void spreadx11_sign_cpu_init(int thr_id, uint32_t throughput)
{
}
__host__
void spreadx11_sign_cpu_setInput(struct work *work)
{
fp_int fp_privkey, fp_kinv;
struct spreadwork* swork = (struct spreadwork*) work->extradata;
fp_read_unsigned_bin(&fp_privkey, swork->privkey, 32);
fp_read_unsigned_bin(&fp_kinv, swork->kinv, 32);
cudaMemcpyToSymbol(d_privkey_data, fp_privkey.dp, 32, 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(d_kinv_data, fp_kinv.dp, 32, 0, cudaMemcpyHostToDevice);
}
__host__
void spreadx11_sign_cpu(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature)
{
const uint32_t threadsperblock = 256;
dim3 grid((threads + threadsperblock-1)/threadsperblock);
dim3 block(threadsperblock);
spreadx11_sign_gpu<<<grid, block>>>(threads, startNonce, d_hash, d_signature);
cudaDeviceSynchronize();
}
+540
View File
@@ -0,0 +1,540 @@
/**
* From the SpreadX11 spreadminer Cuda Implementation by tsiv
*
* Adapted to common ccminer by tpruvot@github - 2015
*/
#include <string.h>
#ifndef _WIN32
#include <unistd.h>
#endif
extern "C"
{
#include "sph/sph_blake.h"
#include "sph/sph_bmw.h"
#include "sph/sph_groestl.h"
#include "sph/sph_skein.h"
#include "sph/sph_jh.h"
#include "sph/sph_keccak.h"
#include "sph/sph_luffa.h"
#include "sph/sph_cubehash.h"
#include "sph/sph_shavite.h"
#include "sph/sph_simd.h"
#include "sph/sph_echo.h"
#include <openssl/bn.h>
#include <openssl/sha.h>
}
#include "miner.h"
#include "spreadx11.h"
#include "cuda_helper.h"
static uint32_t *d_sha256hash[MAX_GPUS];
static uint32_t *d_signature[MAX_GPUS];
static uint32_t *d_hashwholeblock[MAX_GPUS];
static uint32_t *d_hash[MAX_GPUS];
static uint32_t *d_wholeblockdata[MAX_GPUS];
extern void spreadx11_sha256double_cpu_hash_88(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash);
extern void spreadx11_sha256double_setBlock_88(void *data);
extern void spreadx11_sha256_cpu_init( int thr_id, uint32_t threads);
extern void spreadx11_sha256_cpu_hash_wholeblock(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_wholeblock);
extern void spreadx11_sha256_setBlock_wholeblock(struct work *work, uint32_t *d_wholeblock);
extern void spreadx11_sign_cpu_init(int thr_id, uint32_t threads);
extern void spreadx11_sign_cpu_setInput(struct work *work);
extern void spreadx11_sign_cpu(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature);
extern void blake_cpu_init(int thr_id, uint32_t threads);
extern void blake_cpu_setBlock_185(void *pdata);
extern void blake_cpu_hash_185(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_hashwholeblock);
extern void quark_bmw512_cpu_init(int thr_id, uint32_t threads);
extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void x11_luffa512_cpu_init(int thr_id, uint32_t threads);
extern void x11_luffa512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void x11_cubehash512_cpu_init(int thr_id, uint32_t threads);
extern void x11_cubehash512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void x11_shavite512_cpu_init(int thr_id, uint32_t threads);
extern void x11_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
extern void x11_simd512_cpu_init(int thr_id, uint32_t threads);
extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
//extern void spreadx11_echo512_cpu_init(int thr_id, uint32_t threads);
//extern void spreadx11_echo512_cpu_setTarget(const void *ptarget);
//extern uint32_t spreadx11_echo512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, uint32_t *hashidx);
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
#define PROFILE 0
#if PROFILE == 1
#define PRINTTIME(s) do { \
double duration; \
gettimeofday(&tv_end, NULL); \
duration = 1e-6 * (tv_end.tv_usec-tv_start.tv_usec) + (tv_end.tv_sec-tv_start.tv_sec); \
printf("%s: %.2f ms, %.2f MH/s\n", s, duration*1000.0, (double)throughput / 1000000.0 / duration); \
} while(0)
#define TRACE(algo) { \
if (nonce == first_nonce) { \
uint32_t* debugbuf = NULL; \
cudaMallocHost(&debugbuf, 8*sizeof(uint32_t)); \
cudaMemcpy(debugbuf, d_hash[thr_id], 32, cudaMemcpyDeviceToHost); \
printf(" %s %08x %08x %08x %08x...\n", algo, swab32(debugbuf[0]), swab32(debugbuf[1]), \
swab32(debugbuf[2]), swab32(debugbuf[3])); \
cudaFreeHost(debugbuf); \
} \
}
#else
#define PRINTTIME(s)
#define TRACE(s)
#endif
void hextobin(unsigned char *p, const char *hexstr, size_t len)
{
char hex_byte[3];
char *ep;
hex_byte[2] = '\0';
while (*hexstr && len) {
if (!hexstr[1]) {
applog(LOG_ERR, "hex2bin str truncated");
return;
}
hex_byte[0] = hexstr[0];
hex_byte[1] = hexstr[1];
*p = (unsigned char) strtol(hex_byte, &ep, 16);
if (*ep) {
applog(LOG_ERR, "hex2bin failed on '%s'", hex_byte);
return;
}
p++;
hexstr += 2;
len--;
}
}
static void spreadx11_hash(void *output, struct work *work, uint32_t nonce)
{
SHA256_CTX ctx_sha;
sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_skein512_context ctx_skein;
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_echo512_context ctx_echo;
unsigned char mod[32] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
};
unsigned char tmp[185];
unsigned char hashforsig[32];
unsigned char wholeblock[MAX_BLOCK_SIZE];
unsigned char finalhash[64];
BIGNUM *bn_hash, *bn_privkey, *bn_kinv, *bn_mod, *bn_res;
BN_CTX *bn_ctx;
struct spreadwork* swork = (struct spreadwork*) work->extradata;
uint32_t *nonceptr = (uint32_t *)&tmp[84];
unsigned char *hashwholeblockptr = &tmp[88];
unsigned char *signatureptr = &tmp[153];
memcpy(tmp, swork->data, 185);
nonceptr[0] = nonce & 0xffffffc0;
SHA256_Init(&ctx_sha);
SHA256_Update(&ctx_sha, tmp, 88);
SHA256_Final(hashforsig, &ctx_sha);
SHA256_Init(&ctx_sha);
SHA256_Update(&ctx_sha, hashforsig, 32);
SHA256_Final(hashforsig, &ctx_sha);
bn_ctx = BN_CTX_new();
bn_hash = BN_new();
bn_privkey = BN_new();
bn_kinv = BN_new();
bn_mod = BN_new();
bn_res = BN_new();
BN_bin2bn(hashforsig, 32, bn_hash);
BN_bin2bn(swork->privkey, 32, bn_privkey);
BN_bin2bn(swork->kinv, 32, bn_kinv);
BN_bin2bn(mod, 32, bn_mod);
BN_mod_add_quick(bn_privkey, bn_privkey, bn_hash, bn_mod);
BN_mod_mul(bn_res, bn_privkey, bn_kinv, bn_mod, bn_ctx);
int nBitsS = BN_num_bits(bn_res);
memset(signatureptr, 0, 32);
BN_bn2bin(bn_res, &signatureptr[32-(nBitsS+7)/8]);
BN_CTX_free(bn_ctx);
BN_clear_free(bn_hash);
BN_clear_free(bn_privkey);
BN_clear_free(bn_kinv);
BN_clear_free(bn_mod);
BN_clear_free(bn_res);
memcpy(wholeblock+0, tmp+84, 4); // nNonce
memcpy(wholeblock+4, tmp+68, 8); // nTime
memcpy(wholeblock+12, tmp+120, 65); // MinerSignature
memcpy(wholeblock+77, tmp+0, 4); // nVersion
memcpy(wholeblock+81, tmp+4, 32); // hashPrevBlock
memcpy(wholeblock+113, tmp+36, 32); // HashMerkleRoot
memcpy(wholeblock+145, tmp+76, 4); // nBits
memcpy(wholeblock+149, tmp+80, 4); // nHeight
memcpy(wholeblock+153, swork->tx, swork->txsize); // tx
// the total amount of bytes in our data
int blocksize = 153 + swork->txsize;
// pad the block with 0x07 bytes to make it a multiple of uint32_t
while( blocksize & 3 ) wholeblock[blocksize++] = 0x07;
// figure out the offsets for the padding
uint32_t *pFillBegin = (uint32_t*)&wholeblock[blocksize];
uint32_t *pFillEnd = (uint32_t*)&wholeblock[MAX_BLOCK_SIZE]; // FIXME: isn't this out of bounds by one... but it seems to work out...
uint32_t *pFillFooter = pFillBegin > pFillEnd - 8 ? pFillBegin : pFillEnd - 8;
memcpy(pFillFooter, tmp+4, (pFillEnd - pFillFooter)*4);
for (uint32_t *pI = pFillFooter; pI < pFillEnd; pI++)
*pI |= 1;
for (uint32_t *pI = pFillFooter - 1; pI >= pFillBegin; pI--)
pI[0] = pI[3]*pI[7];
SHA256_Init(&ctx_sha);
SHA256_Update(&ctx_sha, wholeblock, MAX_BLOCK_SIZE);
SHA256_Update(&ctx_sha, wholeblock, MAX_BLOCK_SIZE);
SHA256_Final(hashwholeblockptr, &ctx_sha);
//applog_hash(hashwholeblockptr);
nonceptr[0] = nonce;
sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, tmp, 185);
sph_blake512_close(&ctx_blake, (void*) finalhash);
//applog_hash(finalhash);
sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, (const void*) finalhash, 64);
sph_bmw512_close(&ctx_bmw, (void*) finalhash);
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, (const void*) finalhash, 64);
sph_groestl512_close(&ctx_groestl, (void*) finalhash);
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, (const void*) finalhash, 64);
sph_skein512_close(&ctx_skein, (void*) finalhash);
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, (const void*) finalhash, 64);
sph_jh512_close(&ctx_jh, (void*) finalhash);
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, (const void*) finalhash, 64);
sph_keccak512_close(&ctx_keccak, (void*) finalhash);
sph_luffa512_init(&ctx_luffa);
sph_luffa512 (&ctx_luffa, (const void*) finalhash, 64);
sph_luffa512_close (&ctx_luffa, (void*) finalhash);
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512 (&ctx_cubehash, (const void*) finalhash, 64);
sph_cubehash512_close(&ctx_cubehash, (void*) finalhash);
sph_shavite512_init(&ctx_shavite);
sph_shavite512 (&ctx_shavite, (const void*) finalhash, 64);
sph_shavite512_close(&ctx_shavite, (void*) finalhash);
sph_simd512_init(&ctx_simd);
sph_simd512 (&ctx_simd, (const void*) finalhash, 64);
sph_simd512_close(&ctx_simd, (void*) finalhash);
sph_echo512_init(&ctx_echo);
sph_echo512 (&ctx_echo, (const void*) finalhash, 64);
sph_echo512_close(&ctx_echo, (void*) finalhash);
memcpy(output, finalhash, 32);
}
// cpu hash only used as dev test (--cputest)
extern "C" void spreadhash(void *output, const void *input)
{
struct work work;
struct spreadwork swork;
memset(&work, 0, sizeof(struct work));
memset(&swork, 0, sizeof(struct spreadwork));
memcpy(swork.data, input, 128); // 185 but made for a simple empty
const char hextest[371] = { 0 };
hex2bin(swork.data, &hextest[0], 185);
work.extradata = (void*) &swork;
uint32_t *nonceptr = (uint32_t*) (&swork.data[84]);
spreadx11_hash(output, &work, nonceptr[0]);
}
static bool init[MAX_GPUS] = { 0 };
// GPU Search
extern "C" int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
int dev_id = device_map[thr_id % MAX_GPUS];
// multiple of 64 to keep things simple with signatures
//const uint32_t throughput = opt_throughput * 1024 * 64;
uint32_t *ptarget = work->target;
struct spreadwork* swork = (struct spreadwork*) work->extradata;
if (!swork) {
work->extradata = swork = (struct spreadwork*) calloc(1, sizeof(struct spreadwork));
applog(LOG_ERR, "GPU #%d: missing block data!", dev_id);
sleep(1);
//return -1;
}
unsigned char *blocktemplate = swork->data;
uint32_t *pnonce = (uint32_t*) (&blocktemplate[84]);
uint32_t nonce = (*pnonce);
uint32_t first_nonce = nonce;
int intensity = (device_sm[dev_id] >= 500 && !is_windows()) ? 19 : 18;
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 19=256*256*8;
throughput = min(throughput, max_nonce - first_nonce) & 0xFFFFFFC0UL;
if (opt_benchmark)
ptarget[7] = 0x00ff;
if (!init[thr_id])
{
cudaSetDevice(device_map[thr_id]);
//cudaDeviceReset();
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
// a 512-bit buffer for every nonce to hold the x11 intermediate hashes
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)64 * throughput));
// sha256 hashes used for signing, 32 bytes for every 64 nonces
cudaMalloc(&d_sha256hash[thr_id], (size_t)32*(throughput>>6));
// changing part of MinerSignature, 32 bytes for every 64 nonces
cudaMalloc(&d_signature[thr_id], (size_t)32*(throughput>>6));
// sha256 hashes for the whole block, 32 bytes for every 64 nonces
cudaMalloc(&d_hashwholeblock[thr_id], (size_t)32*(throughput>>6));
spreadx11_sha256_cpu_init(thr_id, throughput);
spreadx11_sign_cpu_init(thr_id, throughput);
blake_cpu_init(thr_id, throughput);
quark_groestl512_cpu_init(thr_id, throughput);
quark_skein512_cpu_init(thr_id, throughput);
quark_bmw512_cpu_init(thr_id, throughput);
quark_keccak512_cpu_init(thr_id, throughput);
quark_jh512_cpu_init(thr_id, throughput);
x11_luffa512_cpu_init(thr_id, throughput);
x11_cubehash512_cpu_init(thr_id, throughput);
x11_shavite512_cpu_init(thr_id, throughput);
x11_simd512_cpu_init(thr_id, throughput);
//spreadx11_echo512_cpu_init(thr_id, throughput);
x11_echo512_cpu_init(thr_id, throughput);
cuda_check_cpu_init(thr_id, throughput);
// single buffer to hold the padded whole block data
CUDA_SAFE_CALL(cudaMalloc(&d_wholeblockdata[thr_id], 200000));
init[thr_id] = true;
}
struct timeval tv_start;
#if PROFILE == 1
struct timeval tv_end;
#endif
spreadx11_sign_cpu_setInput(work);
spreadx11_sha256_setBlock_wholeblock(work, d_wholeblockdata[thr_id]);
spreadx11_sha256double_setBlock_88((void *)blocktemplate);
blake_cpu_setBlock_185((void *)blocktemplate);
//spreadx11_echo512_cpu_setTarget(ptarget);
cuda_check_cpu_setTarget(ptarget);
do {
int order = 0;
gettimeofday(&tv_start, NULL);
spreadx11_sha256double_cpu_hash_88(thr_id, throughput>>6, nonce, d_sha256hash[thr_id]);
//PRINTTIME("sha256 sig");
gettimeofday(&tv_start, NULL);
spreadx11_sign_cpu(thr_id, throughput>>6, nonce, d_sha256hash[thr_id], d_signature[thr_id]);
//PRINTTIME("signing ");
gettimeofday(&tv_start, NULL);
spreadx11_sha256_cpu_hash_wholeblock(thr_id, throughput>>6, nonce, d_hashwholeblock[thr_id], d_signature[thr_id], d_wholeblockdata[thr_id]);
//PRINTTIME("hashwhole ");
gettimeofday(&tv_start, NULL);
blake_cpu_hash_185(thr_id, throughput, nonce, d_hash[thr_id], d_signature[thr_id], d_hashwholeblock[thr_id]);
TRACE("blake ");
gettimeofday(&tv_start, NULL);
quark_bmw512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("bmw ");
gettimeofday(&tv_start, NULL);
quark_groestl512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("groestl ");
gettimeofday(&tv_start, NULL);
quark_skein512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("skein ");
gettimeofday(&tv_start, NULL);
quark_jh512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("jh ");
gettimeofday(&tv_start, NULL);
quark_keccak512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("keccak ");
gettimeofday(&tv_start, NULL);
x11_luffa512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("luffa ");
gettimeofday(&tv_start, NULL);
x11_cubehash512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("cubehash ");
gettimeofday(&tv_start, NULL);
x11_shavite512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("shavite ");
gettimeofday(&tv_start, NULL);
x11_simd512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("simd ");
uint32_t winnerthread = 0;
uint32_t foundNonce;
gettimeofday(&tv_start, NULL);
//foundNonce = spreadx11_echo512_cpu_hash_64_final(thr_id, throughput, nonce, NULL, d_hash[thr_id], &winnerthread);
x11_echo512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
TRACE("echo ");
*hashes_done = nonce - first_nonce + throughput;
foundNonce = cuda_check_hash(thr_id, throughput, nonce, d_hash[thr_id]);
if (foundNonce != UINT32_MAX)
{
uint32_t cpuhash[8], hash[8];
char hexbuffer[MAX_BLOCK_SIZE*2] = { 0 };
uint32_t *resnonce = (uint32_t*) (&swork->data[84]);
uint32_t *reshashwholeblock = (uint32_t*) (&swork->data[88]);
uint32_t *ressignature = (uint32_t*) (&swork->data[153]);
for (uint32_t u = 0; u < swork->txsize && u < MAX_BLOCK_SIZE; u++)
sprintf(&hexbuffer[u*2], "%02x", swork->tx[u]);
winnerthread = (foundNonce - nonce);
uint32_t idx64 = winnerthread >> 6;
if (opt_debug)
applog(LOG_DEBUG,
"Thread %d found a solution\n"
"First nonce : %08x\n"
"Found nonce : %08x\n"
"Threadidx : %d\n"
"Threadidx64 : %d\n"
"VTX (%d) : %s\n",
dev_id, first_nonce, foundNonce, winnerthread, idx64, swork->txsize, hexbuffer);
else applog(LOG_INFO, "GPU #%d: found a solution, nonce %08x", dev_id, foundNonce);
*resnonce = foundNonce;
cudaMemcpy(reshashwholeblock, d_hashwholeblock[thr_id] + idx64 * 8, 32, cudaMemcpyDeviceToHost);
cudaMemcpy(ressignature, d_signature[thr_id] + idx64 * 8, 32, cudaMemcpyDeviceToHost);
cudaMemcpy(hash, d_hash[thr_id] + winnerthread * 16, 32, cudaMemcpyDeviceToHost);
if (opt_debug) {
memset(hexbuffer, 0, sizeof(hexbuffer));
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)hash)[i]);
applog(LOG_DEBUG, "Final hash 256 : %s", hexbuffer);
memset(hexbuffer, 0, sizeof(hexbuffer));
for( int i = 0; i < 185; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)swork->data)[i]);
applog(LOG_DEBUG, "Submit data : %s", hexbuffer);
memset(hexbuffer, 0, sizeof(hexbuffer));
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)reshashwholeblock)[i]);
applog(LOG_DEBUG, "HashWholeBlock : %s", hexbuffer);
memset(hexbuffer, 0, sizeof(hexbuffer));
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)ressignature)[i]);
applog(LOG_DEBUG, "MinerSignature : %s", hexbuffer);
}
spreadx11_hash((void *)cpuhash, work, foundNonce);
if(cpuhash[7] == hash[7] && fulltest(hash, ptarget) ) {
bn_store_hash_target_ratio(cpuhash, ptarget, work);
return 1;
} else if(cpuhash[7] != hash[7]) {
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU %08x<>%08x!", dev_id, foundNonce, cpuhash[7], hash[7]);
applog_hash((uchar*)cpuhash);
} else {
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not pass the full test!", dev_id, foundNonce);
}
}
nonce += throughput;
} while (nonce < max_nonce && !work_restart[thr_id].restart);
return 0;
}
// cleanup
extern "C" void free_spreadx11(int thr_id)
{
if (!init[thr_id])
return;
cudaSetDevice(device_map[thr_id]);
cudaFree(d_hash[thr_id]);
cuda_check_cpu_free(thr_id);
init[thr_id] = false;
cudaDeviceSynchronize();
}
+9
View File
@@ -0,0 +1,9 @@
#define MAX_BLOCK_SIZE 200000
struct spreadwork {
unsigned char data[185];
unsigned char privkey[32];
unsigned char kinv[32];
unsigned char tx[MAX_BLOCK_SIZE];
size_t txsize;
};
+10 -21
View File
@@ -1824,33 +1824,19 @@ void do_gpu_tests(void)
unsigned long done;
char s[128] = { '\0' };
uchar buf[160];
uint32_t tgt[8] = { 0 };
struct work work;
memset(&work, 0, sizeof(work));
opt_tracegpu = true;
work_restart = (struct work_restart*) malloc(sizeof(struct work_restart));
work_restart[0].restart = 1;
tgt[7] = 0xffff;
work.target[7] = 0xffff;
//memset(buf, 0, sizeof buf);
//scanhash_skeincoin(0, (uint32_t*)buf, tgt, 1, &done);
//memset(work.data, 0, sizeof(work.data));
//scanhash_spreadx11(0, &work, 1, &done);
//memset(buf, 0, sizeof buf);
//memcpy(buf, zrtest, 80);
//scanhash_zr5(0, (uint32_t*)buf, tgt, zrtest[19]+1, &done);
//struct timeval tv;
//memset(buf, 0, sizeof buf);
//scanhash_scrypt_jane(0, (uint32_t*)buf, tgt, NULL, 1, &done, &tv, &tv);
memset(buf, 0, sizeof buf);
scanhash_lyra2(0, (uint32_t*)buf, tgt, 1, &done);
//memset(buf, 0, sizeof buf);
// buf[0] = 1; buf[64] = 2; // for endian tests
//scanhash_blake256(0, (uint32_t*)buf, tgt, 1, &done, 14);
//memset(buf, 0, sizeof buf);
//scanhash_heavy(0, (uint32_t*)buf, tgt, 1, &done, 1, 84); // HEAVYCOIN_BLKHDR_SZ=84
memset(work.data, 0, sizeof(work.data));
scanhash_lyra2(0, &work, 1, &done);
free(work_restart);
work_restart = NULL;
@@ -1945,6 +1931,9 @@ void print_hash_tests(void)
skein2hash(&hash[0], &buf[0]);
printpfx("skein2", hash);
spreadhash(&hash[0], &buf[0]);
printpfx("spread", hash);
s3hash(&hash[0], &buf[0]);
printpfx("S3", hash);