mirror of https://github.com/GOSTSec/ccminer
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
491 lines
13 KiB
491 lines
13 KiB
10 years ago
|
/**
|
||
|
* Blake-256 Cuda Kernel (Tested on SM 5.0)
|
||
|
*
|
||
10 years ago
|
* Tanguy Pruvot - Nov. 2014
|
||
10 years ago
|
*/
|
||
|
|
||
10 years ago
|
#define PRECALC64 1
|
||
|
|
||
10 years ago
|
#include "miner.h"
|
||
|
|
||
|
extern "C" {
|
||
|
#include "sph/sph_blake.h"
|
||
|
#include <stdint.h>
|
||
|
#include <memory.h>
|
||
|
}
|
||
|
|
||
10 years ago
|
/* threads per block and throughput (intensity) */
|
||
10 years ago
|
#define TPB 128
|
||
|
|
||
10 years ago
|
/* added in sph_blake.c */
|
||
10 years ago
|
extern "C" int blake256_rounds = 14;
|
||
|
|
||
10 years ago
|
/* hash by cpu with blake 256 */
|
||
10 years ago
|
extern "C" void blake256hash(void *output, const void *input, int8_t rounds = 14)
|
||
10 years ago
|
{
|
||
10 years ago
|
uchar hash[64];
|
||
10 years ago
|
sph_blake256_context ctx;
|
||
10 years ago
|
|
||
|
blake256_rounds = rounds;
|
||
|
|
||
10 years ago
|
sph_blake256_init(&ctx);
|
||
|
sph_blake256(&ctx, input, 80);
|
||
|
sph_blake256_close(&ctx, hash);
|
||
10 years ago
|
|
||
10 years ago
|
memcpy(output, hash, 32);
|
||
|
}
|
||
|
|
||
|
#include "cuda_helper.h"
|
||
|
|
||
10 years ago
|
#if PRECALC64
|
||
10 years ago
|
__constant__ uint32_t _ALIGN(32) d_data[12];
|
||
10 years ago
|
#else
|
||
10 years ago
|
__constant__ static uint32_t _ALIGN(32) c_data[20];
|
||
10 years ago
|
/* midstate hash cache, this algo is run on 2 parts */
|
||
|
__device__ static uint32_t cache[8];
|
||
|
__device__ static uint32_t prevsum = 0;
|
||
|
/* crc32.c */
|
||
|
extern "C" uint32_t crc32_u32t(const uint32_t *buf, size_t size);
|
||
|
#endif
|
||
10 years ago
|
|
||
10 years ago
|
/* 8 adapters max */
|
||
10 years ago
|
static uint32_t *d_resNonce[8];
|
||
|
static uint32_t *h_resNonce[8];
|
||
10 years ago
|
|
||
10 years ago
|
/* max count of found nonces in one call */
|
||
10 years ago
|
#define NBN 2
|
||
10 years ago
|
static uint32_t extra_results[NBN] = { UINT32_MAX };
|
||
10 years ago
|
|
||
10 years ago
|
/* prefer uint32_t to prevent size conversions = speed +5/10 % */
|
||
10 years ago
|
__constant__
|
||
10 years ago
|
static uint32_t _ALIGN(32) c_sigma[16][16] = {
|
||
10 years ago
|
{ 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 }
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
#if !PRECALC64
|
||
10 years ago
|
__device__ __constant__
|
||
10 years ago
|
static const uint32_t __align__(32) c_IV256[8] = {
|
||
10 years ago
|
SPH_C32(0x6A09E667), SPH_C32(0xBB67AE85),
|
||
|
SPH_C32(0x3C6EF372), SPH_C32(0xA54FF53A),
|
||
|
SPH_C32(0x510E527F), SPH_C32(0x9B05688C),
|
||
|
SPH_C32(0x1F83D9AB), SPH_C32(0x5BE0CD19)
|
||
|
};
|
||
10 years ago
|
#endif
|
||
10 years ago
|
|
||
|
__device__ __constant__
|
||
10 years ago
|
static const uint32_t __align__(32) c_u256[16] = {
|
||
10 years ago
|
SPH_C32(0x243F6A88), SPH_C32(0x85A308D3),
|
||
|
SPH_C32(0x13198A2E), SPH_C32(0x03707344),
|
||
|
SPH_C32(0xA4093822), SPH_C32(0x299F31D0),
|
||
|
SPH_C32(0x082EFA98), SPH_C32(0xEC4E6C89),
|
||
|
SPH_C32(0x452821E6), SPH_C32(0x38D01377),
|
||
|
SPH_C32(0xBE5466CF), SPH_C32(0x34E90C6C),
|
||
|
SPH_C32(0xC0AC29B7), SPH_C32(0xC97C50DD),
|
||
|
SPH_C32(0x3F84D5B5), SPH_C32(0xB5470917)
|
||
|
};
|
||
|
|
||
10 years ago
|
#define GS(a,b,c,d,x) { \
|
||
10 years ago
|
const uint32_t idx1 = c_sigma[r][x]; \
|
||
|
const uint32_t idx2 = c_sigma[r][x+1]; \
|
||
10 years ago
|
v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
|
||
10 years ago
|
v[d] = SPH_ROTL32(v[d] ^ v[a], 16); \
|
||
10 years ago
|
v[c] += v[d]; \
|
||
10 years ago
|
v[b] = SPH_ROTR32(v[b] ^ v[c], 12); \
|
||
10 years ago
|
\
|
||
10 years ago
|
v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
|
||
10 years ago
|
v[d] = SPH_ROTR32(v[d] ^ v[a], 8); \
|
||
10 years ago
|
v[c] += v[d]; \
|
||
10 years ago
|
v[b] = SPH_ROTR32(v[b] ^ v[c], 7); \
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
/* Second part (64-80) msg never change, store it */
|
||
|
__device__ __constant__
|
||
|
static const uint32_t __align__(32) c_Padding[16] = {
|
||
|
0, 0, 0, 0,
|
||
|
0x80000000UL, 0, 0, 0,
|
||
|
0, 0, 0, 0,
|
||
|
0, 1, 0, 640,
|
||
|
};
|
||
|
|
||
10 years ago
|
__device__ static
|
||
10 years ago
|
void blake256_compress(uint32_t *h, const uint32_t *block, const uint32_t T0, const int rounds)
|
||
10 years ago
|
{
|
||
10 years ago
|
uint32_t /*_ALIGN(8)*/ m[16];
|
||
|
uint32_t v[16];
|
||
10 years ago
|
|
||
10 years ago
|
m[0] = block[0];
|
||
|
m[1] = block[1];
|
||
|
m[2] = block[2];
|
||
|
m[3] = block[3];
|
||
10 years ago
|
|
||
10 years ago
|
for (uint32_t i = 4; i < 16; i++) {
|
||
10 years ago
|
#if PRECALC64
|
||
|
m[i] = c_Padding[i];
|
||
|
#else
|
||
10 years ago
|
m[i] = (T0 == 0x200) ? block[i] : c_Padding[i];
|
||
10 years ago
|
#endif
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
//#pragma unroll 8
|
||
10 years ago
|
for(uint32_t i = 0; i < 8; i++)
|
||
10 years ago
|
v[i] = h[i];
|
||
|
|
||
10 years ago
|
v[ 8] = c_u256[0];
|
||
|
v[ 9] = c_u256[1];
|
||
|
v[10] = c_u256[2];
|
||
|
v[11] = c_u256[3];
|
||
10 years ago
|
|
||
10 years ago
|
v[12] = c_u256[4] ^ T0;
|
||
|
v[13] = c_u256[5] ^ T0;
|
||
|
v[14] = c_u256[6];
|
||
|
v[15] = c_u256[7];
|
||
10 years ago
|
|
||
10 years ago
|
for (int r = 0; r < rounds; r++) {
|
||
10 years ago
|
/* column step */
|
||
10 years ago
|
GS(0, 4, 0x8, 0xC, 0x0);
|
||
|
GS(1, 5, 0x9, 0xD, 0x2);
|
||
|
GS(2, 6, 0xA, 0xE, 0x4);
|
||
|
GS(3, 7, 0xB, 0xF, 0x6);
|
||
10 years ago
|
/* diagonal step */
|
||
|
GS(0, 5, 0xA, 0xF, 0x8);
|
||
|
GS(1, 6, 0xB, 0xC, 0xA);
|
||
|
GS(2, 7, 0x8, 0xD, 0xC);
|
||
|
GS(3, 4, 0x9, 0xE, 0xE);
|
||
|
}
|
||
10 years ago
|
#if PRECALC64
|
||
|
// only compute h6 & 7
|
||
|
h[6U] ^= v[6U] ^ v[14U];
|
||
|
h[7U] ^= v[7U] ^ v[15U];
|
||
|
#else
|
||
10 years ago
|
//#pragma unroll 16
|
||
10 years ago
|
for (uint32_t i = 0; i < 16; i++) {
|
||
10 years ago
|
uint32_t j = i % 8U;
|
||
10 years ago
|
h[j] ^= v[i];
|
||
|
}
|
||
10 years ago
|
#endif
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
#if !PRECALC64 /* original method */
|
||
10 years ago
|
__global__
|
||
10 years ago
|
void blake256_gpu_hash_80(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce,
|
||
10 years ago
|
const uint64_t highTarget, const int crcsum, const int rounds)
|
||
10 years ago
|
{
|
||
10 years ago
|
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||
10 years ago
|
if (thread < threads)
|
||
10 years ago
|
{
|
||
10 years ago
|
const uint32_t nonce = startNonce + thread;
|
||
10 years ago
|
uint32_t h[8];
|
||
10 years ago
|
|
||
|
#pragma unroll
|
||
10 years ago
|
for(int i=0; i<8; i++) {
|
||
10 years ago
|
h[i] = c_IV256[i];
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
if (crcsum != prevsum) {
|
||
|
prevsum = crcsum;
|
||
10 years ago
|
blake256_compress(h, c_data, 512, rounds);
|
||
10 years ago
|
#pragma unroll
|
||
|
for(int i=0; i<8; i++) {
|
||
|
cache[i] = h[i];
|
||
|
}
|
||
|
} else {
|
||
|
#pragma unroll
|
||
|
for(int i=0; i<8; i++) {
|
||
|
h[i] = cache[i];
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
|
// ------ Close: Bytes 64 to 80 ------
|
||
10 years ago
|
|
||
10 years ago
|
uint32_t ending[4];
|
||
|
ending[0] = c_data[16];
|
||
|
ending[1] = c_data[17];
|
||
|
ending[2] = c_data[18];
|
||
10 years ago
|
ending[3] = nonce; /* our tested value */
|
||
10 years ago
|
|
||
10 years ago
|
blake256_compress(h, ending, 640, rounds);
|
||
|
|
||
|
// not sure why, h[7] is ok
|
||
|
h[6] = cuda_swab32(h[6]);
|
||
|
|
||
|
// compare count of leading zeros h[6] + h[7]
|
||
|
uint64_t high64 = ((uint64_t*)h)[3];
|
||
10 years ago
|
if (high64 <= highTarget)
|
||
10 years ago
|
#if NBN == 2
|
||
10 years ago
|
/* keep the smallest nonce, + extra one if found */
|
||
|
if (resNonce[0] > nonce) {
|
||
10 years ago
|
// printf("%llx %llx \n", high64, highTarget);
|
||
10 years ago
|
resNonce[1] = resNonce[0];
|
||
|
resNonce[0] = nonce;
|
||
10 years ago
|
}
|
||
|
else
|
||
10 years ago
|
resNonce[1] = nonce;
|
||
10 years ago
|
#else
|
||
10 years ago
|
resNonce[0] = nonce;
|
||
10 years ago
|
#endif
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
__host__
|
||
10 years ago
|
uint32_t blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint64_t highTarget,
|
||
10 years ago
|
const uint32_t crcsum, const int8_t rounds)
|
||
10 years ago
|
{
|
||
10 years ago
|
const int threadsperblock = TPB;
|
||
10 years ago
|
uint32_t result = UINT32_MAX;
|
||
10 years ago
|
|
||
|
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||
|
dim3 block(threadsperblock);
|
||
|
size_t shared_size = 0;
|
||
|
|
||
10 years ago
|
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
|
||
10 years ago
|
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
|
||
10 years ago
|
return result;
|
||
10 years ago
|
|
||
10 years ago
|
blake256_gpu_hash_80<<<grid, block, shared_size>>>(threads, startNonce, d_resNonce[thr_id], highTarget, crcsum, (int) rounds);
|
||
10 years ago
|
cudaDeviceSynchronize();
|
||
10 years ago
|
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
|
||
10 years ago
|
//cudaThreadSynchronize(); /* seems no more required */
|
||
10 years ago
|
result = h_resNonce[thr_id][0];
|
||
10 years ago
|
for (int n=0; n < (NBN-1); n++)
|
||
10 years ago
|
extra_results[n] = h_resNonce[thr_id][n+1];
|
||
10 years ago
|
}
|
||
10 years ago
|
return result;
|
||
|
}
|
||
|
|
||
|
__host__
|
||
10 years ago
|
void blake256_cpu_setBlock_80(uint32_t *pdata, const uint32_t *ptarget)
|
||
10 years ago
|
{
|
||
10 years ago
|
uint32_t data[20];
|
||
|
memcpy(data, pdata, 80);
|
||
|
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, data, sizeof(data), 0, cudaMemcpyHostToDevice));
|
||
10 years ago
|
}
|
||
10 years ago
|
#else
|
||
|
|
||
|
/* ############################################################################################################################### */
|
||
|
/* Precalculated 1st 64-bytes block (midstate) method */
|
||
|
|
||
|
__global__
|
||
10 years ago
|
void blake256_gpu_hash_16(const uint32_t threads, const uint32_t startNonce, uint32_t *resNonce,
|
||
10 years ago
|
const uint64_t highTarget, const int rounds, const bool trace)
|
||
|
{
|
||
|
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||
|
if (thread < threads)
|
||
|
{
|
||
10 years ago
|
const uint32_t nonce = startNonce + thread;
|
||
|
uint32_t _ALIGN(16) h[8];
|
||
10 years ago
|
|
||
|
#pragma unroll
|
||
10 years ago
|
for(int i=0; i < 8; i++) {
|
||
|
h[i] = d_data[i];
|
||
10 years ago
|
}
|
||
|
|
||
|
// ------ Close: Bytes 64 to 80 ------
|
||
|
|
||
10 years ago
|
uint32_t _ALIGN(16) ending[4];
|
||
|
ending[0] = d_data[8];
|
||
|
ending[1] = d_data[9];
|
||
|
ending[2] = d_data[10];
|
||
|
ending[3] = nonce; /* our tested value */
|
||
10 years ago
|
|
||
|
blake256_compress(h, ending, 640, rounds);
|
||
10 years ago
|
|
||
|
if (h[7] == 0 && cuda_swab32(h[6]) <= highTarget) {
|
||
10 years ago
|
#if NBN == 2
|
||
10 years ago
|
/* keep the smallest nonce, + extra one if found */
|
||
|
if (resNonce[0] > nonce) {
|
||
|
resNonce[1] = resNonce[0];
|
||
|
resNonce[0] = nonce;
|
||
10 years ago
|
}
|
||
|
else
|
||
10 years ago
|
resNonce[1] = nonce;
|
||
10 years ago
|
#else
|
||
10 years ago
|
resNonce[0] = nonce;
|
||
10 years ago
|
#endif
|
||
|
#ifdef _DEBUG
|
||
10 years ago
|
if (trace) {
|
||
10 years ago
|
uint64_t high64 = ((uint64_t*)h)[3];
|
||
|
printf("gpu: %16llx\n", high64);
|
||
10 years ago
|
printf("gpu: %08x.%08x\n", h[7], h[6]);
|
||
|
printf("tgt: %16llx\n", highTarget);
|
||
10 years ago
|
}
|
||
10 years ago
|
#endif
|
||
10 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
__host__
|
||
|
static uint32_t blake256_cpu_hash_16(const int thr_id, const uint32_t threads, const uint32_t startNonce, const uint64_t highTarget,
|
||
|
const int8_t rounds)
|
||
|
{
|
||
|
const int threadsperblock = TPB;
|
||
10 years ago
|
uint32_t result = UINT32_MAX;
|
||
10 years ago
|
|
||
|
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||
|
dim3 block(threadsperblock);
|
||
|
|
||
|
/* Check error on Ctrl+C or kill to prevent segfaults on exit */
|
||
|
if (cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)) != cudaSuccess)
|
||
|
return result;
|
||
|
|
||
|
blake256_gpu_hash_16 <<<grid, block>>> (threads, startNonce, d_resNonce[thr_id], highTarget, (int) rounds, opt_tracegpu);
|
||
|
cudaDeviceSynchronize();
|
||
|
if (cudaSuccess == cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost)) {
|
||
|
//cudaThreadSynchronize(); /* seems no more required */
|
||
|
result = h_resNonce[thr_id][0];
|
||
|
for (int n=0; n < (NBN-1); n++)
|
||
|
extra_results[n] = h_resNonce[thr_id][n+1];
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
__host__
|
||
|
static void blake256mid(uint32_t *output, const uint32_t *input, int8_t rounds = 14)
|
||
|
{
|
||
|
sph_blake256_context ctx;
|
||
|
|
||
|
/* in sph_blake.c */
|
||
|
blake256_rounds = rounds;
|
||
|
|
||
|
sph_blake256_init(&ctx);
|
||
|
sph_blake256(&ctx, input, 64);
|
||
|
|
||
10 years ago
|
memcpy(output, (void*)ctx.H, 32);
|
||
10 years ago
|
}
|
||
|
|
||
|
__host__
|
||
|
void blake256_cpu_setBlock_16(uint32_t *penddata, const uint32_t *midstate, const uint32_t *ptarget)
|
||
|
{
|
||
10 years ago
|
uint32_t _ALIGN(64) data[11];
|
||
10 years ago
|
memcpy(data, midstate, 32);
|
||
|
data[8] = penddata[0];
|
||
|
data[9] = penddata[1];
|
||
|
data[10]= penddata[2];
|
||
10 years ago
|
CUDA_SAFE_CALL(cudaMemcpyToSymbol(d_data, data, 32 + 12, 0, cudaMemcpyHostToDevice));
|
||
10 years ago
|
}
|
||
|
#endif
|
||
10 years ago
|
|
||
10 years ago
|
static bool init[8] = { 0 };
|
||
|
|
||
10 years ago
|
extern "C" int scanhash_blake256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||
10 years ago
|
uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds=14)
|
||
10 years ago
|
{
|
||
|
const uint32_t first_nonce = pdata[19];
|
||
10 years ago
|
uint64_t targetHigh = ((uint64_t*)ptarget)[3];
|
||
10 years ago
|
uint32_t _ALIGN(64) endiandata[20];
|
||
10 years ago
|
#if PRECALC64
|
||
10 years ago
|
uint32_t _ALIGN(64) midstate[8];
|
||
10 years ago
|
#else
|
||
|
uint32_t crcsum;
|
||
|
#endif
|
||
10 years ago
|
int intensity = (device_sm[device_map[thr_id]] > 500) ? 22 : 20;
|
||
|
uint32_t throughput = opt_work_size ? opt_work_size : (1 << intensity);
|
||
10 years ago
|
throughput = min(throughput, max_nonce - first_nonce);
|
||
10 years ago
|
|
||
10 years ago
|
int rc = 0;
|
||
10 years ago
|
|
||
10 years ago
|
if (opt_benchmark) {
|
||
10 years ago
|
targetHigh = 0x1ULL << 32;
|
||
10 years ago
|
((uint32_t*)ptarget)[6] = swab32(0xff);
|
||
|
}
|
||
10 years ago
|
|
||
|
if (opt_tracegpu) {
|
||
|
/* test call from util.c */
|
||
|
throughput = 1;
|
||
|
for (int k = 0; k < 20; k++)
|
||
|
pdata[k] = swab32(pdata[k]);
|
||
|
}
|
||
10 years ago
|
|
||
|
if (!init[thr_id]) {
|
||
10 years ago
|
if (active_gpus > 1)
|
||
10 years ago
|
cudaSetDevice(device_map[thr_id]);
|
||
|
CUDA_CALL_OR_RET_X(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)), 0);
|
||
|
CUDA_CALL_OR_RET_X(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)), 0);
|
||
10 years ago
|
init[thr_id] = true;
|
||
|
}
|
||
|
|
||
10 years ago
|
#if PRECALC64
|
||
|
for (int k = 0; k < 16; k++)
|
||
|
be32enc(&endiandata[k], pdata[k]);
|
||
|
blake256mid(midstate, endiandata, blakerounds);
|
||
|
blake256_cpu_setBlock_16(&pdata[16], midstate, ptarget);
|
||
|
#else
|
||
10 years ago
|
blake256_cpu_setBlock_80(pdata, ptarget);
|
||
10 years ago
|
crcsum = crc32_u32t(pdata, 64);
|
||
10 years ago
|
#endif /* PRECALC64 */
|
||
10 years ago
|
|
||
10 years ago
|
do {
|
||
10 years ago
|
uint32_t foundNonce =
|
||
|
#if PRECALC64
|
||
|
// GPU HASH (second block only, first is midstate)
|
||
|
blake256_cpu_hash_16(thr_id, throughput, pdata[19], targetHigh, blakerounds);
|
||
|
#else
|
||
|
// GPU FULL HASH
|
||
|
blake256_cpu_hash_80(thr_id, throughput, pdata[19], targetHigh, crcsum, blakerounds);
|
||
|
#endif
|
||
10 years ago
|
if (foundNonce != UINT32_MAX)
|
||
10 years ago
|
{
|
||
|
uint32_t vhashcpu[8];
|
||
10 years ago
|
uint32_t Htarg = (uint32_t)targetHigh;
|
||
10 years ago
|
|
||
10 years ago
|
for (int k=0; k < 19; k++)
|
||
10 years ago
|
be32enc(&endiandata[k], pdata[k]);
|
||
|
|
||
10 years ago
|
be32enc(&endiandata[19], foundNonce);
|
||
10 years ago
|
blake256hash(vhashcpu, endiandata, blakerounds);
|
||
10 years ago
|
|
||
10 years ago
|
//applog(LOG_BLUE, "%08x %16llx", vhashcpu[6], targetHigh);
|
||
10 years ago
|
if (vhashcpu[6] <= Htarg && fulltest(vhashcpu, ptarget))
|
||
10 years ago
|
{
|
||
10 years ago
|
rc = 1;
|
||
10 years ago
|
*hashes_done = pdata[19] - first_nonce + throughput;
|
||
|
pdata[19] = foundNonce;
|
||
|
#if NBN > 1
|
||
10 years ago
|
if (extra_results[0] != UINT32_MAX) {
|
||
10 years ago
|
be32enc(&endiandata[19], extra_results[0]);
|
||
|
blake256hash(vhashcpu, endiandata, blakerounds);
|
||
10 years ago
|
if (vhashcpu[6] <= Htarg /* && fulltest(vhashcpu, ptarget) */) {
|
||
10 years ago
|
pdata[21] = extra_results[0];
|
||
10 years ago
|
rc = 2;
|
||
10 years ago
|
}
|
||
10 years ago
|
extra_results[0] = UINT32_MAX;
|
||
10 years ago
|
}
|
||
10 years ago
|
#endif
|
||
10 years ago
|
//applog_hash((uint8_t*)ptarget);
|
||
|
//applog_compare_hash((uint8_t*)vhashcpu,(uint8_t*)ptarget);
|
||
10 years ago
|
return rc;
|
||
10 years ago
|
}
|
||
10 years ago
|
else if (opt_debug) {
|
||
10 years ago
|
applog_hash((uchar*)ptarget);
|
||
|
applog_compare_hash((uchar*)vhashcpu, (uchar*)ptarget);
|
||
10 years ago
|
applog(LOG_DEBUG, "GPU #%d: result for nonce %08x does not validate on CPU!", thr_id, foundNonce);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
if ((uint64_t) pdata[19] + throughput > (uint64_t) max_nonce) {
|
||
10 years ago
|
pdata[19] = max_nonce;
|
||
10 years ago
|
break;
|
||
|
}
|
||
|
|
||
10 years ago
|
pdata[19] += throughput;
|
||
|
|
||
10 years ago
|
} while (!work_restart[thr_id].restart);
|
||
10 years ago
|
|
||
10 years ago
|
*hashes_done = pdata[19] - first_nonce + 1; // (+1 to prevent locks)
|
||
10 years ago
|
return rc;
|
||
10 years ago
|
}
|