Files

1428 lines
49 KiB
C
Raw Permalink Normal View History

2014-03-06 20:55:56 +02:00
/*
* Copyright 2014 sgminer developers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version. See COPYING for more details.
*/
#include "algorithm.h"
2016-11-29 18:44:45 +01:00
#include "findnonce.h"
#include "sph/sph_sha2.h"
#include "ocl.h"
#include "ocl/build_kernel.h"
2014-06-08 03:17:29 +02:00
#include "algorithm/scrypt.h"
#include "algorithm/animecoin.h"
#include "algorithm/inkcoin.h"
#include "algorithm/quarkcoin.h"
#include "algorithm/qubitcoin.h"
#include "algorithm/sifcoin.h"
#include "algorithm/darkcoin.h"
#include "algorithm/myriadcoin-groestl.h"
#include "algorithm/fuguecoin.h"
#include "algorithm/groestlcoin.h"
#include "algorithm/twecoin.h"
#include "algorithm/marucoin.h"
#include "algorithm/maxcoin.h"
2014-06-15 19:21:10 +04:00
#include "algorithm/talkcoin.h"
2014-06-28 03:08:47 +07:00
#include "algorithm/bitblock.h"
2014-06-30 15:13:13 -04:00
#include "algorithm/x14.h"
#include "algorithm/fresh.h"
2014-12-03 10:09:55 -05:00
#include "algorithm/whirlcoin.h"
2014-11-19 12:06:16 +01:00
#include "algorithm/neoscrypt.h"
2015-03-09 11:01:20 +01:00
#include "algorithm/whirlpoolx.h"
2015-03-10 09:47:46 +01:00
#include "algorithm/lyra2re.h"
2016-02-11 21:33:56 +01:00
#include "algorithm/lyra2rev2.h"
2015-03-10 10:26:58 +01:00
#include "algorithm/pluck.h"
#include "algorithm/yescrypt.h"
#include "algorithm/credits.h"
2016-02-06 12:50:16 +01:00
#include "algorithm/blake256.h"
#include "algorithm/blakecoin.h"
2016-08-30 10:16:08 +02:00
#include "algorithm/ethash.h"
2016-12-01 05:53:30 -06:00
#include "algorithm/cryptonight.h"
2019-06-17 12:15:51 -06:00
#include "algorithm/lbry.h"
2014-03-06 20:55:56 +02:00
2014-05-29 22:48:25 +02:00
#include "compat.h"
2014-03-06 20:55:56 +02:00
#include <inttypes.h>
#include <string.h>
2014-06-28 00:54:17 -04:00
const char *algorithm_type_str[] = {
"Unknown",
"Credits",
2014-06-28 00:54:17 -04:00
"Scrypt",
"NScrypt",
"X11",
"X13",
2014-06-30 15:13:13 -04:00
"X14",
"X15",
2014-06-28 00:54:17 -04:00
"Keccak",
"Quarkcoin",
"Twecoin",
"Fugue256",
"NIST",
2014-12-03 10:09:55 -05:00
"Fresh",
"Whirlcoin",
2015-03-09 11:01:20 +01:00
"Neoscrypt",
2015-03-10 09:47:46 +01:00
"WhirlpoolX",
2015-03-10 10:26:58 +01:00
"Lyra2RE",
2016-02-11 21:33:56 +01:00
"Lyra2REV2"
2015-03-10 10:26:58 +01:00
"Pluck"
"Yescrypt",
2016-02-06 12:50:16 +01:00
"Yescrypt-multi",
"Blakecoin",
"Blake",
2016-08-30 10:16:08 +02:00
"Vanilla",
2016-09-19 09:07:22 -05:00
"Ethash",
2016-12-01 05:53:30 -06:00
"Cryptonight",
2019-06-17 12:15:51 -06:00
"LBRY"
2014-06-28 00:54:17 -04:00
};
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
{
sph_sha256_context ctx_sha2;
sph_sha256_init(&ctx_sha2);
sph_sha256(&ctx_sha2, message, len);
sph_sha256_close(&ctx_sha2, (void*)digest);
}
2014-03-06 20:55:56 +02:00
void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash)
{
2014-06-13 17:50:55 +02:00
unsigned char hash1[32];
sph_sha256_context ctx_sha2;
2014-06-13 17:50:55 +02:00
sph_sha256_init(&ctx_sha2);
sph_sha256(&ctx_sha2, data, len);
sph_sha256_close(&ctx_sha2, hash1);
sph_sha256(&ctx_sha2, hash1, 32);
sph_sha256_close(&ctx_sha2, hash);
}
#define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar)
#define CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)
2014-06-17 18:05:19 +02:00
#define CL_SET_ARG_N(n, var) do { status |= clSetKernelArg(*kernel, n, sizeof(var), (void *)&var); } while (0)
#define CL_SET_ARG_0(var) CL_SET_ARG_N(0, var)
#define CL_SET_ARG(var) CL_SET_ARG_N(num++, var)
#define CL_NEXTKERNEL_SET_ARG_N(n, var) do { kernel++; CL_SET_ARG_N(n, var); } while (0)
#define CL_NEXTKERNEL_SET_ARG_0(var) CL_NEXTKERNEL_SET_ARG_N(0, var)
#define CL_NEXTKERNEL_SET_ARG(var) CL_NEXTKERNEL_SET_ARG_N(num++, var)
static void append_scrypt_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
{
char buf[255];
sprintf(buf, " -D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%u -D NFACTOR=%d",
2015-03-10 10:26:58 +01:00
cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, algorithm->nfactor);
strcat(data->compiler_options, buf);
sprintf(buf, "lg%utc%unf%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, algorithm->nfactor);
strcat(data->binary_filename, buf);
}
static void append_ethash_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
{
2017-01-27 02:45:17 +01:00
#ifdef WIN32
strcat(data->compiler_options, "-DWINDOWS");
#endif
}
2014-11-19 12:06:16 +01:00
static void append_neoscrypt_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
{
char buf[255];
2014-12-03 10:09:55 -05:00
sprintf(buf, " %s-D MAX_GLOBAL_THREADS=%lu ",
2015-03-10 10:26:58 +01:00
((cgpu->lookup_gap > 0) ? " -D LOOKUP_GAP=2 " : ""), (unsigned long)cgpu->thread_concurrency);
2014-11-19 12:06:16 +01:00
strcat(data->compiler_options, buf);
2014-12-03 10:09:55 -05:00
2015-03-10 10:26:58 +01:00
sprintf(buf, "%stc%lu", ((cgpu->lookup_gap > 0) ? "lg" : ""), (unsigned long)cgpu->thread_concurrency);
2014-11-19 12:06:16 +01:00
strcat(data->binary_filename, buf);
}
2014-07-28 14:43:11 -04:00
static void append_x11_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
{
char buf[255];
2014-07-28 14:43:11 -04:00
sprintf(buf, " -D SPH_COMPACT_BLAKE_64=%d -D SPH_LUFFA_PARALLEL=%d -D SPH_KECCAK_UNROLL=%u ",
2015-03-10 10:26:58 +01:00
((opt_blake_compact) ? 1 : 0), ((opt_luffa_parallel) ? 1 : 0), (unsigned int)opt_keccak_unroll);
strcat(data->compiler_options, buf);
2015-03-10 10:26:58 +01:00
sprintf(buf, "ku%u%s%s", (unsigned int)opt_keccak_unroll, ((opt_blake_compact) ? "bc" : ""), ((opt_luffa_parallel) ? "lp" : ""));
2014-07-28 14:43:11 -04:00
strcat(data->binary_filename, buf);
}
static void append_x13_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
{
char buf[255];
2014-07-28 21:46:36 -04:00
append_x11_compiler_options(data, cgpu, algorithm);
sprintf(buf, " -D SPH_HAMSI_EXPAND_BIG=%d -D SPH_HAMSI_SHORT=%d ",
2015-03-10 10:26:58 +01:00
(unsigned int)opt_hamsi_expand_big, ((opt_hamsi_short) ? 1 : 0));
2014-07-28 14:43:11 -04:00
strcat(data->compiler_options, buf);
2015-03-10 10:26:58 +01:00
sprintf(buf, "big%u%s", (unsigned int)opt_hamsi_expand_big, ((opt_hamsi_short) ? "hs" : ""));
strcat(data->binary_filename, buf);
}
static cl_int queue_scrypt_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2014-06-13 17:50:55 +02:00
unsigned char *midstate = blk->work->midstate;
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_uint le_target;
cl_int status = 0;
2014-06-13 17:50:55 +02:00
le_target = *(cl_uint *)(blk->work->device_target + 28);
memcpy(clState->cldata, blk->work->data, 80);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-13 17:50:55 +02:00
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->padbuffer8);
CL_SET_VARG(4, &midstate[0]);
CL_SET_VARG(4, &midstate[16]);
CL_SET_ARG(le_target);
2014-06-13 17:50:55 +02:00
return status;
}
2014-11-19 12:06:16 +01:00
static cl_int queue_neoscrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_uint le_target;
cl_int status = 0;
2014-12-03 10:09:55 -05:00
2014-11-19 12:06:16 +01:00
/* This looks like a unnecessary double cast, but to make sure, that
* the target's most significant entry is adressed as a 32-bit value
* and not accidently by something else the double cast seems wise.
2014-12-03 10:09:55 -05:00
* The compiler will get rid of it anyway. */
2014-11-19 12:06:16 +01:00
le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
memcpy(clState->cldata, blk->work->data, 80);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-12-03 10:09:55 -05:00
2014-11-19 12:06:16 +01:00
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(le_target);
2014-12-03 10:09:55 -05:00
2014-11-19 12:06:16 +01:00
return status;
}
static cl_int queue_credits_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_ulong le_target;
cl_int status = 0;
// le_target = (*(cl_uint *)(blk->work->device_target + 24));
le_target = (cl_ulong)le64toh(((uint64_t *)blk->work->/*device_*/target)[3]);
// le_target = (cl_uint)((uint32_t *)blk->work->target)[6];
memcpy(clState->cldata, blk->work->data, 168);
// flip168(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 168, clState->cldata, 0, NULL, NULL);
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
CL_SET_ARG(blk->work->midstate);
return status;
}
static cl_int queue_yescrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_uint le_target;
cl_int status = 0;
// le_target = (*(cl_uint *)(blk->work->device_target + 28));
le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
// le_target = (cl_uint)((uint32_t *)blk->work->target)[7];
// memcpy(clState->cldata, blk->work->data, 80);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->buffer1);
CL_SET_ARG(clState->buffer2);
CL_SET_ARG(le_target);
return status;
}
static cl_int queue_yescrypt_multikernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
// cl_kernel *kernel = &clState->kernel;
cl_kernel *kernel;
unsigned int num = 0;
cl_uint le_target;
cl_int status = 0;
// le_target = (*(cl_uint *)(blk->work->device_target + 28));
le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
memcpy(clState->cldata, blk->work->data, 80);
// flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
//pbkdf and initial sha
kernel = &clState->kernel;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->buffer1);
CL_SET_ARG(clState->buffer2);
CL_SET_ARG(clState->buffer3);
CL_SET_ARG(le_target);
//inactive kernel
num = 0;
kernel = clState->extra_kernels;
CL_SET_ARG_N(0,clState->buffer1);
CL_SET_ARG_N(1,clState->buffer2);
// CL_SET_ARG_N(3, clState->buffer3);
//mix2_2
num = 0;
CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
CL_SET_ARG_N(1,clState->buffer1);
CL_SET_ARG_N(2,clState->buffer2);
//mix2_2
//inactive kernel
num = 0;
CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
CL_SET_ARG_N(1, clState->buffer2);
//mix2_2
num = 0;
CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
CL_SET_ARG_N(1, clState->buffer1);
CL_SET_ARG_N(2, clState->buffer2);
//inactive kernel
num = 0;
CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
CL_SET_ARG_N(1, clState->buffer2);
//mix2_2
//pbkdf and finalization
num=0;
CL_NEXTKERNEL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->buffer2);
CL_SET_ARG(clState->buffer3);
CL_SET_ARG(le_target);
return status;
}
2014-05-27 03:13:30 +02:00
static cl_int queue_maxcoin_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2014-06-13 17:50:55 +02:00
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_int status = 0;
2014-05-27 03:13:30 +02:00
2014-06-13 17:50:55 +02:00
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-05-27 03:13:30 +02:00
2014-06-13 17:50:55 +02:00
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
2014-05-27 03:13:30 +02:00
2014-06-13 17:50:55 +02:00
return status;
2014-05-27 03:13:30 +02:00
}
static cl_int queue_sph_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2014-06-13 17:50:55 +02:00
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_ulong le_target;
cl_int status = 0;
2014-06-13 17:50:55 +02:00
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-13 17:50:55 +02:00
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
2014-06-13 17:50:55 +02:00
return status;
}
2014-05-27 03:13:30 +02:00
static cl_int queue_darkcoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
2014-05-27 01:01:09 +02:00
{
2014-05-27 03:13:30 +02:00
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
2014-05-27 01:01:09 +02:00
2014-05-27 03:13:30 +02:00
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-05-27 01:01:09 +02:00
2014-05-27 03:13:30 +02:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
2014-06-17 18:05:19 +02:00
CL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// groestl - search2
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// skein - search3
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// jh - search4
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// keccak - search5
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// luffa - search6
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// cubehash - search7
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// shavite - search8
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// simd - search9
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
// echo - search10
num = 0;
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
2014-05-27 03:13:30 +02:00
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
2014-05-27 01:01:09 +02:00
2014-05-27 03:13:30 +02:00
return status;
2014-05-27 01:01:09 +02:00
}
2014-06-28 03:08:47 +07:00
static cl_int queue_bitblock_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-28 03:08:47 +07:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// keccak - search5
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// luffa - search6
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// cubehash - search7
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shavite - search8
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// simd - search9
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// echo - search10
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// hamsi - search11
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// fugue - search12
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// hamsi - search11
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// fugue - search12
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
static cl_int queue_bitblockold_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-28 03:08:47 +07:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// keccak - search5
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// luffa - search6
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// cubehash - search7
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shavite - search8
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// simd - search9
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// combined echo, hamsi, fugue - shabal - whirlpool - search10
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2014-06-03 01:32:54 +02:00
static cl_int queue_marucoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-03 01:32:54 +02:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
2014-06-17 18:05:19 +02:00
CL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// groestl - search2
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// skein - search3
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// jh - search4
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// keccak - search5
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// luffa - search6
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// cubehash - search7
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// shavite - search8
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// simd - search9
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// echo - search10
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// hamsi - search11
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
// fugue - search12
num = 0;
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
2014-06-03 01:32:54 +02:00
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
static cl_int queue_marucoin_mod_old_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
2014-06-17 18:05:19 +02:00
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// keccak - search5
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// luffa - search6
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// cubehash - search7
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shavite - search8
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// simd - search9
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// combined echo, hamsi, fugue - search10
num = 0;
2014-06-17 18:05:19 +02:00
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2014-06-15 19:21:10 +04:00
static cl_int queue_talkcoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-15 19:21:10 +04:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// groestl - search1
kernel = clState->extra_kernels;
2014-06-21 23:35:48 +02:00
CL_SET_ARG_0(clState->padbuffer8);
2014-06-15 19:21:10 +04:00
// jh - search2
2014-06-21 23:35:48 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-15 19:21:10 +04:00
// keccak - search3
2014-06-21 23:35:48 +02:00
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
2014-06-15 19:21:10 +04:00
// skein - search4
num = 0;
2014-06-21 23:35:48 +02:00
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
2014-06-15 19:21:10 +04:00
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2014-06-30 15:13:13 -04:00
static cl_int queue_x14_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-30 15:13:13 -04:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// keccak - search5
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// luffa - search6
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// cubehash - search7
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shavite - search8
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// simd - search9
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// echo - search10
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// hamsi - search11
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// fugue - search12
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shabal - search13
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
static cl_int queue_x14_old_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-06-30 15:13:13 -04:00
// blake - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// bmw - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// keccak - search5
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// luffa - search6
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// cubehash - search7
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// shavite - search8
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// simd - search9
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// combined echo, hamsi, fugue - shabal - search10
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
static cl_int queue_fresh_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
// shavite 1 - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// smid 1 - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// shavite 2 - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// smid 2 - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// echo - search4
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2014-12-03 10:09:55 -05:00
static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-10 10:26:58 +01:00
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2014-12-03 10:09:55 -05:00
//clbuffer, hashes
kernel = &clState->kernel;
2015-03-10 10:26:58 +01:00
CL_SET_ARG_N(0, clState->CLbuffer0);
CL_SET_ARG_N(1, clState->padbuffer8);
2014-12-03 10:09:55 -05:00
kernel = clState->extra_kernels;
2015-03-10 10:26:58 +01:00
CL_SET_ARG_N(0, clState->padbuffer8);
2014-12-03 10:09:55 -05:00
2015-03-10 10:26:58 +01:00
CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
2014-12-03 10:09:55 -05:00
//hashes, output, target
2015-03-10 10:26:58 +01:00
CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
CL_SET_ARG_N(1, clState->outputBuffer);
CL_SET_ARG_N(2, le_target);
2014-12-03 10:09:55 -05:00
return status;
}
2015-03-09 11:01:20 +01:00
static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2015-03-26 12:11:17 +01:00
uint64_t midblock[8], key[8] = { 0 }, tmp[8] = { 0 };
2015-03-09 11:01:20 +01:00
cl_ulong le_target;
2015-03-25 15:40:20 +01:00
cl_int status;
2015-03-09 11:01:20 +01:00
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
2015-03-25 15:40:20 +01:00
memcpy(midblock, clState->cldata, 64);
2015-03-09 11:01:20 +01:00
2015-03-25 15:40:20 +01:00
// midblock = n, key = h
2015-03-26 12:11:17 +01:00
for (int i = 0; i < 10; ++i) {
2015-03-25 15:40:20 +01:00
tmp[0] = WHIRLPOOL_ROUND_CONSTANTS[i];
whirlpool_round(key, tmp);
tmp[0] = 0;
whirlpool_round(midblock, tmp);
2015-03-25 18:54:32 +01:00
for (int x = 0; x < 8; ++x) {
midblock[x] ^= key[x];
}
2015-03-25 15:40:20 +01:00
}
2015-03-25 18:54:32 +01:00
for (int i = 0; i < 8; ++i) {
midblock[i] ^= ((uint64_t *)(clState->cldata))[i];
}
2015-03-25 15:40:20 +01:00
status = clSetKernelArg(clState->kernel, 0, sizeof(cl_ulong8), (cl_ulong8 *)&midblock);
status |= clSetKernelArg(clState->kernel, 1, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 8));
status |= clSetKernelArg(clState->kernel, 2, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 9));
status |= clSetKernelArg(clState->kernel, 3, sizeof(cl_mem), (void *)&clState->outputBuffer);
status |= clSetKernelArg(clState->kernel, 4, sizeof(cl_ulong), (void *)&le_target);
2015-03-09 11:01:20 +01:00
return status;
}
2016-02-11 21:33:56 +01:00
static cl_int queue_lyra2re_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
2015-03-10 09:47:46 +01:00
{
2015-03-10 10:26:58 +01:00
cl_kernel *kernel;
unsigned int num;
cl_int status = 0;
cl_ulong le_target;
2015-03-10 09:47:46 +01:00
2015-03-10 10:26:58 +01:00
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2015-03-10 09:47:46 +01:00
2015-03-10 10:26:58 +01:00
// blake - search
kernel = &clState->kernel;
num = 0;
2015-03-10 09:47:46 +01:00
2015-03-10 10:26:58 +01:00
CL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(blk->work->blk.ctx_a);
CL_SET_ARG(blk->work->blk.ctx_b);
CL_SET_ARG(blk->work->blk.ctx_c);
CL_SET_ARG(blk->work->blk.ctx_d);
CL_SET_ARG(blk->work->blk.ctx_e);
CL_SET_ARG(blk->work->blk.ctx_f);
CL_SET_ARG(blk->work->blk.ctx_g);
CL_SET_ARG(blk->work->blk.ctx_h);
CL_SET_ARG(blk->work->blk.cty_a);
CL_SET_ARG(blk->work->blk.cty_b);
CL_SET_ARG(blk->work->blk.cty_c);
2015-03-10 09:47:46 +01:00
2015-03-10 10:26:58 +01:00
// bmw - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// groestl - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// skein - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// jh - search4
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
2015-03-10 09:47:46 +01:00
2015-03-10 10:26:58 +01:00
return status;
}
2016-02-11 21:33:56 +01:00
static cl_int queue_lyra2rev2_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_int status = 0;
cl_ulong le_target;
// le_target = *(cl_uint *)(blk->work->device_target + 28);
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
// blake - search
kernel = &clState->kernel;
num = 0;
// CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->buffer1);
CL_SET_ARG(blk->work->blk.ctx_a);
CL_SET_ARG(blk->work->blk.ctx_b);
CL_SET_ARG(blk->work->blk.ctx_c);
CL_SET_ARG(blk->work->blk.ctx_d);
CL_SET_ARG(blk->work->blk.ctx_e);
CL_SET_ARG(blk->work->blk.ctx_f);
CL_SET_ARG(blk->work->blk.ctx_g);
CL_SET_ARG(blk->work->blk.ctx_h);
CL_SET_ARG(blk->work->blk.cty_a);
CL_SET_ARG(blk->work->blk.cty_b);
CL_SET_ARG(blk->work->blk.cty_c);
// keccak - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->buffer1);
// cubehash - search2
num = 0;
CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
// lyra - search3
num = 0;
CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
CL_SET_ARG_N(1, clState->padbuffer8);
// skein -search4
num = 0;
CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
// cubehash - search5
num = 0;
CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
// bmw - search6
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->buffer1);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2015-03-10 10:26:58 +01:00
static cl_int queue_pluck_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_uint le_target;
cl_int status = 0;
le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(le_target);
return status;
2015-03-10 09:47:46 +01:00
}
2016-02-06 12:50:16 +01:00
static cl_int queue_blake_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2016-11-29 18:44:45 +01:00
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_int status = 0;
cl_ulong le_target;
2016-02-06 12:50:16 +01:00
2016-11-29 18:44:45 +01:00
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
2016-02-06 12:50:16 +01:00
2016-11-29 18:44:45 +01:00
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(blk->work->blk.ctx_a);
CL_SET_ARG(blk->work->blk.ctx_b);
CL_SET_ARG(blk->work->blk.ctx_c);
CL_SET_ARG(blk->work->blk.ctx_d);
CL_SET_ARG(blk->work->blk.ctx_e);
CL_SET_ARG(blk->work->blk.ctx_f);
CL_SET_ARG(blk->work->blk.ctx_g);
CL_SET_ARG(blk->work->blk.ctx_h);
2016-02-06 12:50:16 +01:00
2016-11-29 18:44:45 +01:00
CL_SET_ARG(blk->work->blk.cty_a);
CL_SET_ARG(blk->work->blk.cty_b);
CL_SET_ARG(blk->work->blk.cty_c);
2016-02-06 12:50:16 +01:00
2016-11-29 18:44:45 +01:00
return status;
2016-02-06 12:50:16 +01:00
}
2016-08-30 10:16:08 +02:00
extern pthread_mutex_t eth_nonce_lock;
extern uint32_t eth_nonce;
2016-11-29 18:44:45 +01:00
static const int eth_future_epochs = 6;
2016-08-30 10:16:08 +02:00
static cl_int queue_ethash_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2016-11-30 23:50:45 +01:00
struct pool *pool = blk->work->pool;
2016-11-30 19:44:23 +01:00
eth_dag_t *dag;
2016-11-29 18:44:45 +01:00
cl_kernel *kernel;
unsigned int num = 0;
cl_int status = 0;
cl_ulong le_target;
cl_uint Isolate = UINT32_MAX;
2018-02-13 12:07:18 +01:00
dag = &blk->work->thr->cgpu->eth_dag;
cg_ilock(&dag->lock);
2016-11-30 19:44:23 +01:00
cg_ilock(&pool->data_lock);
2016-11-30 23:50:45 +01:00
if (pool->eth_cache.disabled || pool->eth_cache.dag_cache == NULL) {
2016-11-30 19:44:23 +01:00
cg_iunlock(&pool->data_lock);
2018-02-13 12:07:18 +01:00
cg_iunlock(&dag->lock);
2016-11-29 18:44:45 +01:00
cgsleep_ms(200);
2018-02-13 12:07:18 +01:00
applog(LOG_DEBUG, "THR[%d]: stop ETHASH mining (%d, %p)", blk->work->thr_id, pool->eth_cache.disabled, pool->eth_cache.dag_cache);
2016-11-29 18:44:45 +01:00
return 1;
}
if (dag->current_epoch != blk->work->eth_epoch) {
2018-02-13 12:07:18 +01:00
applog(LOG_NOTICE, "GPU%d: begin DAG creation...", blk->work->thr->cgpu->device_id);
2016-11-29 18:44:45 +01:00
cl_ulong CacheSize = EthGetCacheSize(blk->work->eth_epoch);
cg_ulock(&dag->lock);
2018-02-13 12:07:18 +01:00
if (dag->dag_buffer == NULL || blk->work->eth_epoch >= dag->max_epoch + 1U) {
2016-11-29 18:44:45 +01:00
if (dag->dag_buffer != NULL) {
2018-02-13 12:07:18 +01:00
cg_dlock(&pool->data_lock);
2016-11-29 18:44:45 +01:00
clReleaseMemObject(dag->dag_buffer);
}
else {
2018-02-13 12:07:18 +01:00
cg_ulock(&pool->data_lock);
int size = ++pool->eth_cache.nDevs;
pool->eth_cache.dags = (eth_dag_t **) realloc(pool->eth_cache.dags, sizeof(void*) * size);
pool->eth_cache.dags[size-1] = dag;
dag->pool = pool;
cg_dwlock(&pool->data_lock);
2016-11-29 18:44:45 +01:00
}
dag->max_epoch = blk->work->eth_epoch + eth_future_epochs;
2018-02-13 12:07:18 +01:00
dag->dag_buffer = clCreateBuffer(clState->context, CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS, EthGetDAGSize(dag->max_epoch), NULL, &status);
2016-11-29 18:44:45 +01:00
if (status != CL_SUCCESS) {
2018-02-13 12:07:18 +01:00
cg_runlock(&pool->data_lock);
dag->max_epoch = 0;
dag->dag_buffer = NULL;
cg_wunlock(&dag->lock);
applog(LOG_ERR, "Error %d: Creating the DAG buffer failed.", status);
return status;
2016-11-29 18:44:45 +01:00
}
}
else
cg_dlock(&pool->data_lock);
2016-11-29 18:44:45 +01:00
applog(LOG_DEBUG, "DAG being regenerated.");
2018-02-13 12:07:18 +01:00
cl_mem eth_cache = clCreateBuffer(clState->context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY, CacheSize, pool->eth_cache.dag_cache, &status);
2016-11-29 18:44:45 +01:00
cg_runlock(&pool->data_lock);
if (status != CL_SUCCESS) {
clReleaseMemObject(eth_cache);
cg_wunlock(&dag->lock);
applog(LOG_ERR, "Error %d: Creating the ethash cache buffer failed.", status);
return status;
}
2016-11-29 18:44:45 +01:00
// enqueue DAG gen kernel
kernel = &clState->GenerateDAG;
2016-08-30 10:16:08 +02:00
2016-11-29 18:44:45 +01:00
cl_uint zero = 0;
cl_uint CacheSize64 = CacheSize / 64;
2016-11-29 18:44:45 +01:00
CL_SET_ARG(zero);
CL_SET_ARG(eth_cache);
CL_SET_ARG(dag->dag_buffer);
CL_SET_ARG(CacheSize64);
CL_SET_ARG(Isolate);
2016-11-29 18:44:45 +01:00
cl_ulong DAGSize = EthGetDAGSize(blk->work->eth_epoch);
size_t DAGItems = (size_t) (DAGSize / 64);
2018-02-13 12:07:18 +01:00
cgsleep_ms(128 * blk->work->thr->cgpu->device_id);
2016-11-29 18:44:45 +01:00
status |= clEnqueueNDRangeKernel(clState->commandQueue, clState->GenerateDAG, 1, NULL, &DAGItems, NULL, 0, NULL, NULL);
clFinish(clState->commandQueue);
2016-08-30 10:16:08 +02:00
2016-11-29 18:44:45 +01:00
clReleaseMemObject(eth_cache);
if (status != CL_SUCCESS) {
cg_wunlock(&dag->lock);
applog(LOG_ERR, "Error %d: Setting args for the DAG kernel and/or executing it.", status);
return status;
}
dag->current_epoch = blk->work->eth_epoch;
cg_dwlock(&dag->lock);
2018-02-13 12:07:18 +01:00
applog(LOG_NOTICE, "GPU%d: new DAG created", blk->work->thr->cgpu->device_id);
2016-11-29 18:44:45 +01:00
}
else {
cg_dlock(&dag->lock);
cg_iunlock(&pool->data_lock);
}
2016-08-30 10:16:08 +02:00
2016-11-29 18:44:45 +01:00
memcpy(&le_target, blk->work->device_target + 24, 8);
blk->work->Nonce = (blk->work->Nonce >> 32 << 32) | blk->work->blk.nonce;
2016-11-29 18:44:45 +01:00
num = 0;
kernel = &clState->kernel;
2016-11-29 18:44:45 +01:00
// Not nodes now (64 bytes), but DAG entries (128 bytes)
cl_ulong DAGSize = EthGetDAGSize(blk->work->eth_epoch);
cl_uint ItemsArg = DAGSize / 128;
2016-11-29 18:44:45 +01:00
// DO NOT flip80.
2018-02-13 12:07:18 +01:00
status |= clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, CL_FALSE, 0, 32, blk->work->data, 0, NULL, NULL);
2016-11-29 18:44:45 +01:00
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(dag->dag_buffer);
CL_SET_ARG(ItemsArg);
CL_SET_ARG(blk->work->Nonce);
CL_SET_ARG(le_target);
CL_SET_ARG(Isolate);
2016-11-29 18:44:45 +01:00
if (status != CL_SUCCESS)
cg_runlock(&dag->lock);
return status;
2016-08-30 10:16:08 +02:00
}
2016-12-01 05:53:30 -06:00
static cl_int queue_cryptonight_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
2018-02-17 17:39:47 +01:00
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_int status = 0, tgt32 = *(uint32_t*)(blk->work->target + 28);
2018-02-21 19:45:57 +01:00
int variant = MIN(1, monero_variant(blk->work)); // limit variant to prevent DOS
if (variant != clState->monero_variant) {
applog(LOG_NOTICE, "switch to monero variant %d", variant);
char kernel_name[20] = "search1";
if (variant > 0)
snprintf(kernel_name + 7, sizeof(kernel_name) - 7, "_var%d", variant);
clReleaseKernel(clState->extra_kernels[0]);
clState->extra_kernels[0] = clCreateKernel(clState->program, kernel_name, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d: Creating Kernel \"%s\" from program. (clCreateKernel)", kernel_name, status);
return status;
}
clState->monero_variant = variant;
}
2016-12-01 05:53:30 -06:00
2018-02-17 17:39:47 +01:00
memcpy(clState->cldata, blk->work->data, blk->work->XMRBlobLen);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, CL_FALSE, 0, blk->work->XMRBlobLen, clState->cldata , 0, NULL, NULL);
2018-02-17 17:39:47 +01:00
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(blk->work->XMRBlobLen);
CL_SET_ARG(clState->Scratchpads);
CL_SET_ARG(clState->States);
num = 0;
kernel = clState->extra_kernels;
CL_SET_ARG(clState->Scratchpads);
CL_SET_ARG(clState->States);
if (variant > 0)
CL_SET_ARG(*(cl_uint*)(clState->cldata + 35));
2018-02-17 17:39:47 +01:00
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->Scratchpads);
CL_SET_ARG(clState->States);
CL_SET_ARG(clState->BranchBuffer[0]);
CL_SET_ARG(clState->BranchBuffer[1]);
CL_SET_ARG(clState->BranchBuffer[2]);
CL_SET_ARG(clState->BranchBuffer[3]);
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->States);
CL_SET_ARG(clState->BranchBuffer[0]);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(tgt32);
// last to be set in driver-opencl.c
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->States);
CL_SET_ARG(clState->BranchBuffer[1]);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(tgt32);
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->States);
CL_SET_ARG(clState->BranchBuffer[2]);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(tgt32);
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->States);
CL_SET_ARG(clState->BranchBuffer[3]);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(tgt32);
return(status);
2016-12-01 05:53:30 -06:00
}
2019-06-17 12:15:51 -06:00
static cl_int queue_lbry_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel = &clState->kernel;
unsigned int num = 0;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->target + 24);
flip112(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 112, clState->cldata, 0, NULL, NULL);
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
num = 0;
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
2016-09-19 09:07:22 -05:00
static algorithm_settings_t algos[] = {
2014-06-13 17:50:55 +02:00
// kernels starting from this will have difficulty calculated by using litecoin algorithm
#define A_SCRYPT(a) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_SCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, NULL, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options }
2015-03-10 10:26:58 +01:00
A_SCRYPT("ckolivas"),
A_SCRYPT("alexkarnew"),
A_SCRYPT("alexkarnold"),
A_SCRYPT("bufius"),
A_SCRYPT("psw"),
A_SCRYPT("zuikkis"),
A_SCRYPT("arebyp"),
#undef A_SCRYPT
2014-11-19 12:06:16 +01:00
#define A_NEOSCRYPT(a) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_NEOSCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, neoscrypt_regenhash, NULL, queue_neoscrypt_kernel, gen_hash, append_neoscrypt_compiler_options }
2014-11-19 12:06:16 +01:00
A_NEOSCRYPT("neoscrypt"),
#undef A_NEOSCRYPT
2015-03-10 10:26:58 +01:00
#define A_PLUCK(a) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_PLUCK, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pluck_regenhash, NULL, queue_pluck_kernel, gen_hash, append_neoscrypt_compiler_options }
2015-03-10 10:26:58 +01:00
A_PLUCK("pluck"),
#undef A_PLUCK
#define A_CREDITS(a) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_CRE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, credits_regenhash, NULL, queue_credits_kernel, gen_hash, NULL}
A_CREDITS("credits"),
#undef A_CREDITS
#define A_YESCRYPT(a) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_YESCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, yescrypt_regenhash, NULL, queue_yescrypt_kernel, gen_hash, append_neoscrypt_compiler_options}
A_YESCRYPT("yescrypt"),
#undef A_YESCRYPT
#define A_YESCRYPT_MULTI(a) \
2016-08-30 10:16:08 +02:00
{ a, ALGO_YESCRYPT_MULTI, "", 1, 65536, 65536, 0, 0, 0xFF, 0x00000000FFFFULL, 0x0000ffffUL, 6,-1,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE , yescrypt_regenhash, NULL, queue_yescrypt_multikernel, gen_hash, append_neoscrypt_compiler_options}
A_YESCRYPT_MULTI("yescrypt-multi"),
#undef A_YESCRYPT_MULTI
2014-06-13 17:50:55 +02:00
// kernels starting from this will have difficulty calculated by using quarkcoin algorithm
#define A_QUARK(a, b) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options }
2015-03-10 10:26:58 +01:00
A_QUARK("quarkcoin", quarkcoin_regenhash),
A_QUARK("qubitcoin", qubitcoin_regenhash),
A_QUARK("animecoin", animecoin_regenhash),
A_QUARK("sifcoin", sifcoin_regenhash),
#undef A_QUARK
2014-06-13 17:50:55 +02:00
// kernels starting from this will have difficulty calculated by using bitcoin algorithm
#define A_DARK(a, b) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options }
2015-03-10 10:26:58 +01:00
A_DARK("darkcoin", darkcoin_regenhash),
A_DARK("inkcoin", inkcoin_regenhash),
A_DARK("myriadcoin-groestl", myriadcoin_groestl_regenhash),
#undef A_DARK
2016-02-12 02:01:46 +00:00
{ "twecoin", ALGO_TWE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, NULL, queue_sph_kernel, sha256, NULL },
{ "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, NULL, queue_maxcoin_kernel, sha256, NULL },
2016-02-12 02:01:46 +00:00
{ "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, NULL, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options },
2016-02-12 02:01:46 +00:00
{ "marucoin", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, NULL, queue_sph_kernel, gen_hash, append_x13_compiler_options },
{ "marucoin-mod", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options },
{ "marucoin-modold", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options },
2014-06-15 19:21:10 +04:00
2016-02-12 02:01:46 +00:00
{ "x14", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, NULL, queue_x14_kernel, gen_hash, append_x13_compiler_options },
{ "x14old", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, NULL, queue_x14_old_kernel, gen_hash, append_x13_compiler_options },
2014-07-28 14:43:11 -04:00
2016-02-12 02:01:46 +00:00
{ "bitblock", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, queue_bitblock_kernel, gen_hash, append_x13_compiler_options },
{ "bitblockold", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options },
2014-06-30 15:13:13 -04:00
2016-02-12 02:01:46 +00:00
{ "talkcoin-mod", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, NULL, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options },
2016-02-12 02:01:46 +00:00
{ "fresh", ALGO_FRESH, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, NULL, queue_fresh_kernel, gen_hash, NULL },
2016-02-12 02:01:46 +00:00
{ "lyra2re", ALGO_LYRA2RE, "", 1, 128, 128, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 2 * 8 * 4194304, 0, lyra2re_regenhash, precalc_hash_blake256, queue_lyra2re_kernel, gen_hash, NULL },
{ "lyra2rev2", ALGO_LYRA2REV2, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, lyra2rev2_regenhash, precalc_hash_blake256, queue_lyra2rev2_kernel, gen_hash, append_neoscrypt_compiler_options },
2015-03-10 09:47:46 +01:00
2014-06-13 17:50:55 +02:00
// kernels starting from this will have difficulty calculated by using fuguecoin algorithm
2014-12-03 10:09:55 -05:00
#define A_FUGUE(a, b, c) \
2016-02-12 02:01:46 +00:00
{ a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, queue_sph_kernel, c, NULL }
2014-12-03 10:09:55 -05:00
A_FUGUE("fuguecoin", fuguecoin_regenhash, sha256),
A_FUGUE("groestlcoin", groestlcoin_regenhash, sha256),
A_FUGUE("diamond", groestlcoin_regenhash, gen_hash),
2015-03-10 10:26:58 +01:00
#undef A_FUGUE
2014-12-03 10:09:55 -05:00
2016-02-12 02:01:46 +00:00
{ "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, NULL, queue_whirlcoin_kernel, sha256, NULL },
{ "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, NULL, queue_whirlpoolx_kernel, gen_hash, NULL },
2015-03-09 11:01:20 +01:00
2016-02-12 02:01:46 +00:00
{ "blake256r8", ALGO_BLAKECOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, precalc_hash_blakecoin, queue_blake_kernel, sha256, NULL },
{ "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, 0, blake256_regenhash, precalc_hash_blake256, queue_blake_kernel, gen_hash, NULL },
{ "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, precalc_hash_blakecoin, queue_blake_kernel, gen_hash, NULL },
2016-02-06 12:50:16 +01:00
{ "ethash", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
{ "ethash-genoil", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
{ "ethash-new", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
{ "cryptonight", ALGO_CRYPTONIGHT, "", 1, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, 0, cryptonight_regenhash, NULL, queue_cryptonight_kernel, gen_hash, NULL },
2019-06-17 12:15:51 -06:00
{ "lbry", ALGO_LBRY, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 2, 4 * 8 * 4194304, 0, lbry_regenhash, NULL, queue_lbry_kernel, gen_hash, NULL },
// Terminator (do not remove)
2015-03-10 10:26:58 +01:00
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
};
2014-06-13 17:50:55 +02:00
void copy_algorithm_settings(algorithm_t* dest, const char* algo)
{
algorithm_settings_t* src;
2014-06-13 17:50:55 +02:00
// Find algorithm settings and copy
for (src = algos; src->name; src++)
2014-06-28 00:54:17 -04:00
{
if (strcasecmp(src->name, algo) == 0)
2014-06-28 00:54:17 -04:00
{
2014-06-13 17:50:55 +02:00
strcpy(dest->name, src->name);
2014-12-03 10:09:55 -05:00
dest->kernelfile = src->kernelfile;
2014-06-28 00:54:17 -04:00
dest->type = src->type;
2014-06-13 17:50:55 +02:00
dest->diff_multiplier1 = src->diff_multiplier1;
dest->diff_multiplier2 = src->diff_multiplier2;
dest->share_diff_multiplier = src->share_diff_multiplier;
dest->xintensity_shift = src->xintensity_shift;
dest->intensity_shift = src->intensity_shift;
dest->found_idx = src->found_idx;
dest->diff_numerator = src->diff_numerator;
dest->diff1targ = src->diff1targ;
dest->n_extra_kernels = src->n_extra_kernels;
dest->rw_buffer_size = src->rw_buffer_size;
dest->cq_properties = src->cq_properties;
dest->regenhash = src->regenhash;
2016-02-12 02:01:46 +00:00
dest->precalc_hash = src->precalc_hash;
2014-06-13 17:50:55 +02:00
dest->queue_kernel = src->queue_kernel;
dest->gen_hash = src->gen_hash;
dest->set_compile_options = src->set_compile_options;
break;
}
2014-06-13 17:50:55 +02:00
}
2014-06-13 17:50:55 +02:00
// if not found
if (src->name == NULL)
2014-06-28 00:54:17 -04:00
{
2014-06-13 17:50:55 +02:00
applog(LOG_WARNING, "Algorithm %s not found, using %s.", algo, algos->name);
copy_algorithm_settings(dest, algos->name);
}
}
2016-11-29 18:44:45 +01:00
static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfactor)
{
2015-03-10 10:26:58 +01:00
#define ALGO_ALIAS_NF(alias, name, nf) \
if (strcasecmp(alias, lookup_alias) == 0) { *nfactor = nf; return name; }
#define ALGO_ALIAS(alias, name) \
if (strcasecmp(alias, lookup_alias) == 0) return name;
ALGO_ALIAS_NF("scrypt", "ckolivas", 10);
ALGO_ALIAS_NF("scrypt", "ckolivas", 10);
ALGO_ALIAS_NF("adaptive-n-factor", "ckolivas", 11);
ALGO_ALIAS_NF("adaptive-nfactor", "ckolivas", 11);
ALGO_ALIAS_NF("nscrypt", "ckolivas", 11);
ALGO_ALIAS_NF("adaptive-nscrypt", "ckolivas", 11);
ALGO_ALIAS_NF("adaptive-n-scrypt", "ckolivas", 11);
ALGO_ALIAS("x11mod", "darkcoin-mod");
ALGO_ALIAS("x11", "darkcoin-mod");
ALGO_ALIAS("x13mod", "marucoin-mod");
ALGO_ALIAS("x13", "marucoin-mod");
2014-07-04 09:49:15 -04:00
ALGO_ALIAS("x13old", "marucoin-modold");
ALGO_ALIAS("x13modold", "marucoin-modold");
ALGO_ALIAS("x15mod", "bitblock");
ALGO_ALIAS("x15", "bitblock");
2014-07-04 09:49:15 -04:00
ALGO_ALIAS("x15modold", "bitblockold");
ALGO_ALIAS("x15old", "bitblockold");
ALGO_ALIAS("nist5", "talkcoin-mod");
ALGO_ALIAS("keccak", "maxcoin");
2014-12-03 10:09:55 -05:00
ALGO_ALIAS("whirlpool", "whirlcoin");
2015-03-10 09:47:46 +01:00
ALGO_ALIAS("lyra2", "lyra2re");
ALGO_ALIAS("lyra2v2", "lyra2rev2");
2016-02-06 12:50:16 +01:00
ALGO_ALIAS("blakecoin", "blake256r8");
ALGO_ALIAS("blake", "blake256r14");
2015-03-10 10:26:58 +01:00
#undef ALGO_ALIAS
#undef ALGO_ALIAS_NF
return NULL;
}
2014-06-13 17:50:55 +02:00
void set_algorithm(algorithm_t* algo, const char* newname_alias)
{
2014-12-03 10:09:55 -05:00
const char *newname;
2014-06-25 01:01:03 -04:00
//load previous algorithm nfactor in case nfactor was applied before algorithm... or default to 10
2015-03-10 10:26:58 +01:00
uint8_t old_nfactor = ((algo->nfactor) ? algo->nfactor : 0);
2014-11-19 11:18:25 +01:00
//load previous kernel file name if was applied before algorithm...
const char *kernelfile = algo->kernelfile;
2014-07-28 14:43:11 -04:00
uint8_t nfactor = 10;
2016-11-29 18:44:45 +01:00
if (!(newname = lookup_algorithm_alias(newname_alias, &nfactor))) {
2014-07-04 09:49:15 -04:00
newname = newname_alias;
}
2014-06-13 17:50:55 +02:00
copy_algorithm_settings(algo, newname);
2014-07-04 09:49:15 -04:00
// use old nfactor if it was previously set and is different than the one set by alias
if ((old_nfactor > 0) && (old_nfactor != nfactor)) {
2014-07-04 09:49:15 -04:00
nfactor = old_nfactor;
}
2014-07-04 09:49:15 -04:00
set_algorithm_nfactor(algo, nfactor);
2014-11-19 11:18:25 +01:00
//reapply kernelfile if was set
if (!empty_string(kernelfile)) {
algo->kernelfile = kernelfile;
}
}
2014-06-13 17:50:55 +02:00
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor)
{
algo->nfactor = nfactor;
algo->n = (1 << nfactor);
2014-06-28 00:54:17 -04:00
//adjust algo type accordingly
switch (algo->type)
{
2015-03-10 10:26:58 +01:00
case ALGO_SCRYPT:
//if nfactor isnt 10, switch to NSCRYPT
if (algo->nfactor != 10)
algo->type = ALGO_NSCRYPT;
break;
2014-06-28 00:54:17 -04:00
//nscrypt
2015-03-10 10:26:58 +01:00
case ALGO_NSCRYPT:
//if nfactor is 10, switch to SCRYPT
if (algo->nfactor == 10)
algo->type = ALGO_SCRYPT;
break;
2014-06-28 00:54:17 -04:00
//ignore rest
2015-03-10 10:26:58 +01:00
default:
break;
2014-06-28 00:54:17 -04:00
}
}
2015-03-25 18:54:32 +01:00
bool cmp_algorithm(const algorithm_t* algo1, const algorithm_t* algo2)
2014-06-13 17:50:55 +02:00
{
2016-11-29 18:44:45 +01:00
return (!safe_cmp(algo1->name, algo2->name) && !safe_cmp(algo1->kernelfile, algo2->kernelfile) && (algo1->nfactor == algo2->nfactor));
}