mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-31 17:04:23 +00:00
core: use global algorithm structure instead of opt_nfactor.
Also squashed: config: add log messages to set_algo() and set_nfactor(). algorithm: use set_algorithm_nfactor() when setting default nfactor in set_algorithm(). Otherwise algorithm->n defaults to 0. P.S. Did I already mention how this could have been C++?..
This commit is contained in:
parent
a0c52bf67c
commit
c6a27709f8
@ -17,12 +17,17 @@ void set_algorithm(algorithm_t* algo, const char* newname) {
|
|||||||
algo->name[sizeof(algo->name) - 1] = '\0';
|
algo->name[sizeof(algo->name) - 1] = '\0';
|
||||||
|
|
||||||
if (strcmp(algo->name, "adaptive-nfactor") == 0) {
|
if (strcmp(algo->name, "adaptive-nfactor") == 0) {
|
||||||
algo->nfactor = 11;
|
set_algorithm_nfactor(algo, 11);
|
||||||
} else {
|
} else {
|
||||||
algo->nfactor = 10;
|
set_algorithm_nfactor(algo, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor) {
|
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor) {
|
||||||
algo->nfactor = nfactor;
|
algo->nfactor = nfactor;
|
||||||
|
algo->n = (1 << nfactor);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,9 @@
|
|||||||
* a specific coin.
|
* a specific coin.
|
||||||
*/
|
*/
|
||||||
typedef struct _algorithm_t {
|
typedef struct _algorithm_t {
|
||||||
char name[20]; /* Human-readable identifier */
|
char name[20]; /* Human-readable identifier */
|
||||||
uint8_t nfactor; /* N factor (CPU/Memory tradeoff parameter) */
|
uint32_t n; /* N (CPU/Memory tradeoff parameter) */
|
||||||
|
uint8_t nfactor; /* Factor of N above (n = 2^nfactor) */
|
||||||
} algorithm_t;
|
} algorithm_t;
|
||||||
|
|
||||||
/* Set default parameters based on name. */
|
/* Set default parameters based on name. */
|
||||||
|
6
miner.h
6
miner.h
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "algorithm.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -1019,8 +1021,8 @@ extern int opt_queue;
|
|||||||
extern int opt_scantime;
|
extern int opt_scantime;
|
||||||
extern int opt_expiry;
|
extern int opt_expiry;
|
||||||
|
|
||||||
extern char* opt_algorithm;
|
extern char *opt_algorithm;
|
||||||
extern int opt_nfactor;
|
extern algorithm_t *algorithm;
|
||||||
|
|
||||||
extern cglock_t control_lock;
|
extern cglock_t control_lock;
|
||||||
extern pthread_mutex_t hash_lock;
|
extern pthread_mutex_t hash_lock;
|
||||||
|
18
ocl.c
18
ocl.c
@ -33,6 +33,12 @@
|
|||||||
#include "findnonce.h"
|
#include "findnonce.h"
|
||||||
#include "ocl.h"
|
#include "ocl.h"
|
||||||
|
|
||||||
|
/* FIXME: only here for global config vars, replace with configuration.h
|
||||||
|
* or similar as soon as config is in a struct instead of littered all
|
||||||
|
* over the global namespace.
|
||||||
|
*/
|
||||||
|
#include "miner.h"
|
||||||
|
|
||||||
int opt_platform_id = -1;
|
int opt_platform_id = -1;
|
||||||
|
|
||||||
char *file_contents(const char *filename, int *length)
|
char *file_contents(const char *filename, int *length)
|
||||||
@ -226,9 +232,6 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|||||||
cl_uint numDevices;
|
cl_uint numDevices;
|
||||||
cl_int status;
|
cl_int status;
|
||||||
|
|
||||||
/* Scrypt CPU/Memory cost parameter */
|
|
||||||
cl_uint N = (1 << opt_nfactor);
|
|
||||||
|
|
||||||
status = clGetPlatformIDs(0, NULL, &numPlatforms);
|
status = clGetPlatformIDs(0, NULL, &numPlatforms);
|
||||||
if (status != CL_SUCCESS) {
|
if (status != CL_SUCCESS) {
|
||||||
applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
|
applog(LOG_ERR, "Error %d: Getting Platforms. (clGetPlatformsIDs)", status);
|
||||||
@ -485,7 +488,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|||||||
if (!cgpu->opt_tc) {
|
if (!cgpu->opt_tc) {
|
||||||
unsigned int sixtyfours;
|
unsigned int sixtyfours;
|
||||||
|
|
||||||
sixtyfours = cgpu->max_alloc / 131072 / 64 / (N/1024) - 1;
|
sixtyfours = cgpu->max_alloc / 131072 / 64 / (algorithm->n/1024) - 1;
|
||||||
cgpu->thread_concurrency = sixtyfours * 64;
|
cgpu->thread_concurrency = sixtyfours * 64;
|
||||||
if (cgpu->shaders && cgpu->thread_concurrency > cgpu->shaders) {
|
if (cgpu->shaders && cgpu->thread_concurrency > cgpu->shaders) {
|
||||||
cgpu->thread_concurrency -= cgpu->thread_concurrency % cgpu->shaders;
|
cgpu->thread_concurrency -= cgpu->thread_concurrency % cgpu->shaders;
|
||||||
@ -525,7 +528,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize)
|
|||||||
if (clState->goffset)
|
if (clState->goffset)
|
||||||
strcat(binaryfilename, "g");
|
strcat(binaryfilename, "g");
|
||||||
|
|
||||||
sprintf(numbuf, "lg%utc%unf%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency,opt_nfactor);
|
sprintf(numbuf, "lg%utc%unf%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, algorithm->nfactor);
|
||||||
strcat(binaryfilename, numbuf);
|
strcat(binaryfilename, numbuf);
|
||||||
|
|
||||||
sprintf(numbuf, "w%d", (int)clState->wsize);
|
sprintf(numbuf, "w%d", (int)clState->wsize);
|
||||||
@ -592,7 +595,7 @@ build:
|
|||||||
char *CompilerOptions = (char *)calloc(1, 256);
|
char *CompilerOptions = (char *)calloc(1, 256);
|
||||||
|
|
||||||
sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d -D NFACTOR=%d",
|
sprintf(CompilerOptions, "-D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%d -D WORKSIZE=%d -D NFACTOR=%d",
|
||||||
cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, (int)clState->wsize, (unsigned int) opt_nfactor);
|
cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, (int)clState->wsize, (unsigned int)algorithm->nfactor);
|
||||||
|
|
||||||
applog(LOG_DEBUG, "Setting worksize to %d", (int)(clState->wsize));
|
applog(LOG_DEBUG, "Setting worksize to %d", (int)(clState->wsize));
|
||||||
if (clState->vwidth > 1)
|
if (clState->vwidth > 1)
|
||||||
@ -781,7 +784,8 @@ built:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ipt = (N / cgpu->lookup_gap + (N % cgpu->lookup_gap > 0));
|
size_t ipt = (algorithm->n / cgpu->lookup_gap +
|
||||||
|
(algorithm->n % cgpu->lookup_gap > 0));
|
||||||
size_t bufsize = 128 * ipt * cgpu->thread_concurrency;
|
size_t bufsize = 128 * ipt * cgpu->thread_concurrency;
|
||||||
|
|
||||||
/* Use the max alloc value which has been rounded to a power of
|
/* Use the max alloc value which has been rounded to a power of
|
||||||
|
24
scrypt.c
24
scrypt.c
@ -353,10 +353,12 @@ salsa20_8(uint32_t B[16], const uint32_t Bx[16])
|
|||||||
B[15] += x15;
|
B[15] += x15;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
|
/* cpu and memory intensive function to transform a 80 byte buffer into
|
||||||
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
|
* a 32 byte output.
|
||||||
|
* scratchpad size needs to be at least (bytes):
|
||||||
|
* 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N)
|
||||||
*/
|
*/
|
||||||
static void scrypt_n_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_t *ostate, const cl_uint n)
|
static void scrypt_n_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_t *ostate)
|
||||||
{
|
{
|
||||||
uint32_t * V;
|
uint32_t * V;
|
||||||
uint32_t X[32];
|
uint32_t X[32];
|
||||||
@ -370,7 +372,7 @@ static void scrypt_n_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_
|
|||||||
|
|
||||||
PBKDF2_SHA256_80_128(input, X);
|
PBKDF2_SHA256_80_128(input, X);
|
||||||
|
|
||||||
for (i = 0; i < n; i += 2) {
|
for (i = 0; i < algorithm->n; i += 2) {
|
||||||
memcpy(&V[i * 32], X, 128);
|
memcpy(&V[i * 32], X, 128);
|
||||||
|
|
||||||
salsa20_8(&X[0], &X[16]);
|
salsa20_8(&X[0], &X[16]);
|
||||||
@ -381,8 +383,8 @@ static void scrypt_n_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_
|
|||||||
salsa20_8(&X[0], &X[16]);
|
salsa20_8(&X[0], &X[16]);
|
||||||
salsa20_8(&X[16], &X[0]);
|
salsa20_8(&X[16], &X[0]);
|
||||||
}
|
}
|
||||||
for (i = 0; i < n; i += 2) {
|
for (i = 0; i < algorithm->n; i += 2) {
|
||||||
j = X[16] & (n-1);
|
j = X[16] & (algorithm->n-1);
|
||||||
p2 = (uint64_t *)(&V[j * 32]);
|
p2 = (uint64_t *)(&V[j * 32]);
|
||||||
for(k = 0; k < 16; k++)
|
for(k = 0; k < 16; k++)
|
||||||
p1[k] ^= p2[k];
|
p1[k] ^= p2[k];
|
||||||
@ -390,7 +392,7 @@ static void scrypt_n_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_
|
|||||||
salsa20_8(&X[0], &X[16]);
|
salsa20_8(&X[0], &X[16]);
|
||||||
salsa20_8(&X[16], &X[0]);
|
salsa20_8(&X[16], &X[0]);
|
||||||
|
|
||||||
j = X[16] & (n-1);
|
j = X[16] & (algorithm->n-1);
|
||||||
p2 = (uint64_t *)(&V[j * 32]);
|
p2 = (uint64_t *)(&V[j * 32]);
|
||||||
for(k = 0; k < 16; k++)
|
for(k = 0; k < 16; k++)
|
||||||
p1[k] ^= p2[k];
|
p1[k] ^= p2[k];
|
||||||
@ -412,8 +414,8 @@ void scrypt_regenhash(struct work *work)
|
|||||||
be32enc_vect(data, (const uint32_t *)work->data, 19);
|
be32enc_vect(data, (const uint32_t *)work->data, 19);
|
||||||
data[19] = htobe32(*nonce);
|
data[19] = htobe32(*nonce);
|
||||||
|
|
||||||
scratchbuf = (char *)alloca((1 << opt_nfactor) * 128 + 512);
|
scratchbuf = (char *)alloca(algorithm->n * 128 + 512);
|
||||||
scrypt_n_1_1_256_sp(data, scratchbuf, ohash, (1 << opt_nfactor));
|
scrypt_n_1_1_256_sp(data, scratchbuf, ohash);
|
||||||
flip32(ohash, ohash);
|
flip32(ohash, ohash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +433,7 @@ int scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t non
|
|||||||
be32enc_vect(data, (const uint32_t *)pdata, 19);
|
be32enc_vect(data, (const uint32_t *)pdata, 19);
|
||||||
data[19] = htobe32(nonce);
|
data[19] = htobe32(nonce);
|
||||||
scratchbuf = (char *)alloca(SCRATCHBUF_SIZE);
|
scratchbuf = (char *)alloca(SCRATCHBUF_SIZE);
|
||||||
scrypt_n_1_1_256_sp(data, scratchbuf, ohash, (1 << opt_nfactor));
|
scrypt_n_1_1_256_sp(data, scratchbuf, ohash, algorithm->n);
|
||||||
tmp_hash7 = be32toh(ohash[7]);
|
tmp_hash7 = be32toh(ohash[7]);
|
||||||
|
|
||||||
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
|
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
|
||||||
@ -470,7 +472,7 @@ bool scanhash_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *p
|
|||||||
|
|
||||||
*nonce = ++n;
|
*nonce = ++n;
|
||||||
data[19] = htobe32(n);
|
data[19] = htobe32(n);
|
||||||
scrypt_n_1_1_256_sp(data, scratchbuf, ostate, (1 << opt_nfactor));
|
scrypt_n_1_1_256_sp(data, scratchbuf, ostate, algorithm->n);
|
||||||
tmp_hash7 = be32toh(ostate[7]);
|
tmp_hash7 = be32toh(ostate[7]);
|
||||||
|
|
||||||
if (unlikely(tmp_hash7 <= Htarg)) {
|
if (unlikely(tmp_hash7 <= Htarg)) {
|
||||||
|
@ -97,7 +97,6 @@ int opt_expiry = 28;
|
|||||||
|
|
||||||
char *opt_algorithm;
|
char *opt_algorithm;
|
||||||
algorithm_t *algorithm;
|
algorithm_t *algorithm;
|
||||||
int opt_nfactor = 10;
|
|
||||||
|
|
||||||
static const bool opt_time = true;
|
static const bool opt_time = true;
|
||||||
unsigned long long global_hashrate;
|
unsigned long long global_hashrate;
|
||||||
@ -1014,6 +1013,7 @@ static void load_temp_cutoffs()
|
|||||||
static char *set_algo(const char *arg)
|
static char *set_algo(const char *arg)
|
||||||
{
|
{
|
||||||
set_algorithm(algorithm, arg);
|
set_algorithm(algorithm, arg);
|
||||||
|
applog(LOG_INFO, "Set algorithm to %s", algorithm->name);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1021,6 +1021,9 @@ static char *set_algo(const char *arg)
|
|||||||
static char *set_nfactor(const char *arg)
|
static char *set_nfactor(const char *arg)
|
||||||
{
|
{
|
||||||
set_algorithm_nfactor(algorithm, (uint8_t)atoi(arg));
|
set_algorithm_nfactor(algorithm, (uint8_t)atoi(arg));
|
||||||
|
applog(LOG_INFO, "Set algorithm N-factor to %d (N to %d)",
|
||||||
|
algorithm->nfactor, algorithm->n);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user