Skip to content

Commit

Permalink
Merge pull request tsiv#41 from esfomeado/master
Browse files Browse the repository at this point in the history
Multiple Updates
  • Loading branch information
KlausT authored Jul 31, 2017
2 parents 209ccdc + b4d0f50 commit 1b110cb
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 155 deletions.
203 changes: 84 additions & 119 deletions cpu-miner.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crypto/c_blake256.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ void blake256_update(state *S, const uint8_t *data, uint64_t datalen) {
}

if (datalen > 0) {
memcpy((void *) (S->buf + left), (void *) data, (size_t)datalen >> 3);
S->buflen = (left << 3) + (int)datalen;
memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
S->buflen = (left << 3) + datalen;
} else {
S->buflen = 0;
}
Expand Down
3 changes: 1 addition & 2 deletions crypto/c_groestl.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ static void OutputTransformation(groestlHashState *ctx) {

/* initialise context */
static void Init(groestlHashState* ctx) {
int i = 0;
/* allocate memory for state and data buffer */

for(;i<(SIZE512/sizeof(uint32_t));i++)
for(size_t i = 0;i<(SIZE512/sizeof(uint32_t));i++)
{
ctx->chaining[i] = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions crypto/c_keccak.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ void keccakf(uint64_t st[25], int rounds)
// compute a keccak hash (md) of given byte length from "in"
typedef uint64_t state_t[25];

int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
{
state_t st;
uint8_t temp[144];
int i, rsiz, rsizw;
size_t i, rsiz, rsizw;

rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen;
rsizw = rsiz / 8;
Expand Down Expand Up @@ -116,7 +116,7 @@ int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen)
return 0;
}

void keccak1600(const uint8_t *in, int inlen, uint8_t *md)
void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md)
{
keccak(in, inlen, md, sizeof(state_t));
}
4 changes: 2 additions & 2 deletions crypto/c_keccak.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#endif

// compute a keccak hash (md) of given byte length from "in"
int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen);
int keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen);

// update the state
void keccakf(uint64_t st[25], int norounds);

void keccak1600(const uint8_t *in, int inlen, uint8_t *md);
void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md);

#endif
56 changes: 31 additions & 25 deletions crypto/oaes_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static OAES_RET oaes_sub_byte( uint8_t * byte )
{
size_t _x, _y;

if( unlikely(NULL == byte) )
if(NULL == byte)
return OAES_RET_ARG1;

_y = ((_x = *byte) >> 4) & 0x0f;
Expand Down Expand Up @@ -297,23 +297,28 @@ static OAES_RET oaes_word_rot_left( uint8_t word[OAES_COL_LEN] )

static OAES_RET oaes_shift_rows( uint8_t block[OAES_BLOCK_SIZE] )
{
uint8_t _temp[] = { block[0x03], block[0x02], block[0x01], block[0x06], block[0x0b] };
uint8_t _temp[OAES_BLOCK_SIZE];

if( unlikely(NULL == block) )
if(NULL == block)
return OAES_RET_ARG1;

block[0x0b] = block[0x07];
block[0x01] = block[0x05];
block[0x02] = block[0x0a];
block[0x03] = block[0x0f];
block[0x05] = block[0x09];
block[0x06] = block[0x0e];
block[0x07] = _temp[0];
block[0x09] = block[0x0d];
block[0x0a] = _temp[1];
block[0x0d] = _temp[2];
block[0x0e] = _temp[3];
block[0x0f] = _temp[4];
_temp[0x00] = block[0x00];
_temp[0x01] = block[0x05];
_temp[0x02] = block[0x0a];
_temp[0x03] = block[0x0f];
_temp[0x04] = block[0x04];
_temp[0x05] = block[0x09];
_temp[0x06] = block[0x0e];
_temp[0x07] = block[0x03];
_temp[0x08] = block[0x08];
_temp[0x09] = block[0x0d];
_temp[0x0a] = block[0x02];
_temp[0x0b] = block[0x07];
_temp[0x0c] = block[0x0c];
_temp[0x0d] = block[0x01];
_temp[0x0e] = block[0x06];
_temp[0x0f] = block[0x0b];
memcpy(block, _temp, OAES_BLOCK_SIZE);

return OAES_RET_SUCCESS;
}
Expand Down Expand Up @@ -383,7 +388,7 @@ static OAES_RET oaes_mix_cols( uint8_t word[OAES_COL_LEN] )
{
uint8_t _temp[OAES_COL_LEN];

if( unlikely(NULL == word) )
if(NULL == word)
return OAES_RET_ARG1;

_temp[0] = oaes_gf_mul(word[0], 0x02) ^ oaes_gf_mul( word[1], 0x03 ) ^
Expand Down Expand Up @@ -524,7 +529,6 @@ static OAES_RET oaes_key_expand( OAES_CTX * ctx )
{
size_t _i, _j;
oaes_ctx * _ctx = (oaes_ctx *) ctx;
uint8_t _temp[OAES_COL_LEN];

if( NULL == _ctx )
return OAES_RET_ARG1;
Expand All @@ -548,9 +552,9 @@ static OAES_RET oaes_key_expand( OAES_CTX * ctx )
// apply ExpandKey algorithm for remainder
for( _i = _ctx->key->key_base; _i < _ctx->key->num_keys * OAES_RKEY_LEN; _i++ )
{
uint8_t _temp[OAES_COL_LEN];

memcpy( _temp,
_ctx->key->exp_data + ( _i - 1 ) * OAES_RKEY_LEN, OAES_COL_LEN );
memcpy( _temp,_ctx->key->exp_data + ( _i - 1 ) * OAES_RKEY_LEN, OAES_COL_LEN );

// transform key column
if( 0 == _i % _ctx->key->key_base )
Expand Down Expand Up @@ -600,8 +604,10 @@ static OAES_RET oaes_key_gen( OAES_CTX * ctx, size_t key_size )
_key->data_len = key_size;
_key->data = (uint8_t *) calloc( key_size, sizeof( uint8_t ));

if( NULL == _key->data )
if (NULL == _key->data) {
free(_key);
return OAES_RET_MEM;
}

for( _i = 0; _i < key_size; _i++ )
#ifdef OAES_HAVE_ISAAC
Expand All @@ -611,7 +617,7 @@ static OAES_RET oaes_key_gen( OAES_CTX * ctx, size_t key_size )
#endif // OAES_HAVE_ISAAC

_ctx->key = _key;
_rc = _rc ? _rc : oaes_key_expand( ctx );
_rc = _rc || oaes_key_expand( ctx );

if( _rc != OAES_RET_SUCCESS )
{
Expand Down Expand Up @@ -665,7 +671,7 @@ OAES_RET oaes_key_export( OAES_CTX * ctx,
// header
memcpy( data, oaes_header, OAES_BLOCK_SIZE );
data[5] = 0x01;
data[7] = (uint8_t)(_ctx->key->data_len);
data[7] = _ctx->key->data_len;
memcpy( data + OAES_BLOCK_SIZE, _ctx->key->data, _ctx->key->data_len );

return OAES_RET_SUCCESS;
Expand Down Expand Up @@ -779,7 +785,7 @@ OAES_RET oaes_key_import( OAES_CTX * ctx,
}

memcpy( _ctx->key->data, data + OAES_BLOCK_SIZE, _key_length );
_rc = _rc ? _rc : oaes_key_expand( ctx );
_rc = _rc || oaes_key_expand( ctx );

if( _rc != OAES_RET_SUCCESS )
{
Expand Down Expand Up @@ -831,7 +837,7 @@ OAES_RET oaes_key_import_data( OAES_CTX * ctx,
}

memcpy( _ctx->key->data, data, data_len );
_rc = _rc ? _rc : oaes_key_expand( ctx );
_rc = _rc || oaes_key_expand( ctx );

if( _rc != OAES_RET_SUCCESS )
{
Expand All @@ -845,7 +851,7 @@ OAES_RET oaes_key_import_data( OAES_CTX * ctx,
OAES_CTX * oaes_alloc(void)
{
oaes_ctx * _ctx = (oaes_ctx *) calloc(sizeof(oaes_ctx), 1);
if(!_ctx)
if(NULL == _ctx)
return NULL;

#ifdef OAES_HAVE_ISAAC
Expand Down
33 changes: 32 additions & 1 deletion cryptonight/cryptonight.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern "C"
}
#include "cryptonight.h"


extern char *device_name[8];
extern int device_arch[8][2];
extern int device_mpcount[8];
Expand Down Expand Up @@ -77,6 +76,38 @@ extern "C" void cuda_deviceinfo()
device_mpcount[i] = props.multiProcessorCount;
device_arch[i][0] = props.major;
device_arch[i][1] = props.minor;

device_config[i][0] = props.multiProcessorCount * (props.major < 3 ? 2 : 3);
device_config[i][1] = 64;

/* sm_20 devices can only run 512 threads per cuda block
* `cryptonight_core_gpu_phase1` and `cryptonight_core_gpu_phase3` starts
* `8 * ctx->device_threads` threads per block
*/
if(props.major < 6) {

//Try to stay under 950 threads ( 1900MiB memory per for hashes )
while(device_config[i][0] * device_config[i][1] >= 950 && device_config[i][1] > 2)
{
device_config[i][1] /= 2;
}

//Stay within 85% of the available RAM
while(device_config[i][1] > 2)
{
size_t freeMemory = 0;
size_t totalMemoery = 0;

cudaMemGetInfo(&freeMemory, &totalMemoery);
freeMemory = (freeMemory * size_t(85)) / 100;

if(freeMemory > size_t(device_config[i][0]) * size_t(device_config[i][1]) * size_t(2u * 1024u * 1024u)) {
break;
} else {
device_config[i][1] /= 2;
}
}
}
}
}

Expand Down
1 change: 0 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ extern int longpoll_thr_id;
extern int stratum_thr_id;
extern struct work_restart *work_restart;
extern bool opt_trust_pool;
extern uint16_t opt_vote;

#define JSON_RPC_LONGPOLL (1 << 0)
#define JSON_RPC_QUIET_404 (1 << 1)
Expand Down

0 comments on commit 1b110cb

Please sign in to comment.