diff --git a/cpu-miner.c b/cpu-miner.c index 25fd80c..01100be 100755 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -45,11 +45,9 @@ #pragma comment(lib, "winmm.lib") #endif -#define PROGRAM_NAME "ccminer-cryptonight" -#define LP_SCANTIME 60 -#define JSON_BUF_LEN 345 +#define PROGRAM_NAME "ccminer-cryptonight" +#define LP_SCANTIME 60 -// from heavy.cu #ifdef __cplusplus extern "C" { @@ -115,23 +113,14 @@ enum workio_commands struct workio_cmd { - enum workio_commands cmd; - struct thr_info *thr; + enum workio_commands cmd; + struct thr_info *thr; union { struct work *work; } u; }; -typedef enum -{ - ALGO_CRYPTONIGHT -} sha256_algos; - -static const char *algo_names[] = { - "cryptonight" -}; - bool stop_mining = false; volatile bool mining_has_stopped[8] = {false}; bool opt_colors = false; @@ -153,11 +142,9 @@ int opt_timeout = 270; static int opt_scantime = 5; static json_t *opt_config; static const bool opt_time = true; -static sha256_algos opt_algo = ALGO_CRYPTONIGHT; static int opt_n_threads = 0; static double opt_difficulty = 1; // CH bool opt_trust_pool = false; -uint16_t opt_vote = 9999; static int num_processors; int device_map[8] = {0, 1, 2, 3, 4, 5, 6, 7}; // CB char *device_name[8]; // CB @@ -221,63 +208,63 @@ struct option static char const usage[] = "\ Usage: " PROGRAM_NAME " [OPTIONS]\n\ Options:\n\ - -d, --devices takes a comma separated list of CUDA devices to use.\n\ - Device IDs start counting from 0! Alternatively takes\n\ - string names of your cards like gtx780ti or gt640#2\n\ - (matching 2nd gt640 in the PC)\n\ - -f, --diff Divide difficulty by this factor (std is 1) \n\ - -l, --launch=CONFIG launch config for the Cryptonight kernel.\n\ - a comma separated list of values in form of\n\ - AxB where A is the number of threads to run in\n\ - each thread block and B is the number of thread\n\ - blocks to launch. If less values than devices in use\n\ - are provided, the last value will be used for\n\ - the remaining devices. If you don't need to vary the\n\ - value between devices, you can just enter a single value\n\ - and it will be used for all devices. (default: 8x40)\n\ - --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ - The kernel will be run in 2^X parts according to bfactor,\n\ - with a small pause between parts, specified by --bsleep.\n\ - This is a per-device setting like the launch config.\n\ - (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ - --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ - Use in combination with --bfactor to mitigate the lag\n\ - when running on your primary GPU.\n\ - This is a per-device setting like the launch config.\n\ - -m, --trust-pool trust the max block reward vote (maxvote) sent by the pool\n\ - -o, --url=URL URL of mining server\n\ - -O, --userpass=U:P username:password pair for mining server\n\ - -u, --user=USERNAME username for mining server\n\ - -p, --pass=PASSWORD password for mining server\n\ - --cert=FILE certificate for mining server using SSL\n\ - -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy\n\ - -k, --keepalive send keepalive requests to avoid a stratum timeout\n\ - -t, --threads=N number of miner threads (default: number of nVidia GPUs)\n\ - -r, --retries=N number of times to retry if a network call fails\n\ - (default: retry indefinitely)\n\ - -R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\ - --timeout=N network timeout, in seconds (default: 270)\n\ - -s, --scantime=N upper bound on time spent scanning current work when\n\ - long polling is unavailable, in seconds (default: 5)\n\ - --no-longpoll disable X-Long-Polling support\n\ - --no-stratum disable X-Stratum support\n\ - -q, --quiet disable per-thread hashmeter output\n\ - -D, --debug enable debug output\n\ - --color enable output with colors\n\ - -P, --protocol-dump verbose dump of protocol-level activities\n" + -d, --devices takes a comma separated list of CUDA devices to use.\n\ + Device IDs start counting from 0! Alternatively takes\n\ + string names of your cards like gtx780ti or gt640#2\n\ + (matching 2nd gt640 in the PC)\n\ + -f, --diff Divide difficulty by this factor (std is 1) \n\ + -l, --launch=CONFIG launch config for the Cryptonight kernel.\n\ + a comma separated list of values in form of\n\ + AxB where A is the number of threads to run in\n\ + each thread block and B is the number of thread\n\ + blocks to launch. If less values than devices in use\n\ + are provided, the last value will be used for\n\ + the remaining devices. If you don't need to vary the\n\ + value between devices, you can just enter a single value\n\ + and it will be used for all devices. (default: 8x40)\n\ + --bfactor=X Enables running the Cryptonight kernel in smaller pieces.\n\ + The kernel will be run in 2^X parts according to bfactor,\n\ + with a small pause between parts, specified by --bsleep.\n\ + This is a per-device setting like the launch config.\n\ + (default: 0 (no splitting) on Linux, 6 (64 parts) on Windows)\n\ + --bsleep=X Insert a delay of X microseconds between kernel launches.\n\ + Use in combination with --bfactor to mitigate the lag\n\ + when running on your primary GPU.\n\ + This is a per-device setting like the launch config.\n\ + -m, --trust-pool trust the max block reward vote (maxvote) sent by the pool\n\ + -o, --url=URL URL of mining server\n\ + -O, --userpass=U:P username:password pair for mining server\n\ + -u, --user=USERNAME username for mining server\n\ + -p, --pass=PASSWORD password for mining server\n\ + --cert=FILE certificate for mining server using SSL\n\ + -x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy\n\ + -k, --keepalive send keepalive requests to avoid a stratum timeout\n\ + -t, --threads=N number of miner threads (default: number of nVidia GPUs)\n\ + -r, --retries=N number of times to retry if a network call fails\n\ + (default: retry indefinitely)\n\ + -R, --retry-pause=N time to pause between retries, in seconds (default: 30)\n\ + --timeout=N network timeout, in seconds (default: 270)\n\ + -s, --scantime=N upper bound on time spent scanning current work when\n\ + long polling is unavailable, in seconds (default: 5)\n\ + --no-longpoll disable X-Long-Polling support\n\ + --no-stratum disable X-Stratum support\n\ + -q, --quiet disable per-thread hashmeter output\n\ + -D, --debug enable debug output\n\ + --color enable output with colors\n\ + -P, --protocol-dump verbose dump of protocol-level activities\n" #ifdef HAVE_SYSLOG_H "\ - -S, --syslog use system log for output messages\n" + -S, --syslog use system log for output messages\n" #endif #ifndef WIN32 "\ - -B, --background run the miner in the background\n" + -B, --background run the miner in the background\n" #endif "\ - --benchmark run in offline benchmark mode\n\ - -c, --config=FILE load a JSON-format configuration file\n\ - -V, --version display version information and exit\n\ - -h, --help display this help text and exit\n\ + --benchmark run in offline benchmark mode\n\ + -c, --config=FILE load a JSON-format configuration file\n\ + -V, --version display version information and exit\n\ + -h, --help display this help text and exit\n\ "; static char const short_options[] = @@ -287,10 +274,9 @@ static char const short_options[] = #ifdef HAVE_SYSLOG_H "S" #endif -"a:c:Dhp:Px:kqr:R:s:t:T:o:u:O:Vd:f:ml:"; +"c:Dhp:Px:kqr:R:s:t:T:o:u:O:Vd:f:ml:"; static struct option const options[] = { - {"algo", 1, NULL, 'a'}, #ifndef WIN32 {"background", 0, NULL, 'B'}, #endif @@ -478,21 +464,21 @@ bool rpc2_job_decode(const json_t *job, struct work *work) if(!tmp) { applog(LOG_ERR, "JSON inval job id"); - goto err_out; + return false; } const char *job_id = json_string_value(tmp); tmp = json_object_get(job, "blob"); if(!tmp) { applog(LOG_ERR, "JSON inval blob"); - goto err_out; + return false; } const char *hexblob = json_string_value(tmp); int blobLen = (int)strlen(hexblob); if(blobLen % 2 != 0 || ((blobLen / 2) < 40 && blobLen != 0) || (blobLen / 2) > 128) { applog(LOG_ERR, "JSON invalid blob length"); - goto err_out; + return false; } if(blobLen != 0) { @@ -502,7 +488,7 @@ bool rpc2_job_decode(const json_t *job, struct work *work) { applog(LOG_ERR, "JSON inval blob"); pthread_mutex_unlock(&rpc2_job_lock); - goto err_out; + return false; } if(rpc2_blob) { @@ -540,7 +526,7 @@ bool rpc2_job_decode(const json_t *job, struct work *work) if(!rpc2_blob) { applog(LOG_ERR, "Requested work before work was received"); - goto err_out; + return false; } memcpy(work->data, rpc2_blob, rpc2_bloblen); memset(work->target, 0xff, sizeof(work->target)); @@ -548,9 +534,6 @@ bool rpc2_job_decode(const json_t *job, struct work *work) strncpy(work->job_id, rpc2_job_id, 128); } return true; - -err_out: - return false; } static bool work_decode(const json_t *val, struct work *work) @@ -567,7 +550,7 @@ bool rpc2_login_decode(const json_t *val) if(!res) { applog(LOG_ERR, "JSON invalid result"); - goto err_out; + return false; } json_t *tmp; @@ -575,13 +558,13 @@ bool rpc2_login_decode(const json_t *val) if(!tmp) { applog(LOG_ERR, "JSON inval id"); - goto err_out; + return false; } id = json_string_value(tmp); if(!id) { applog(LOG_ERR, "JSON id is not a string"); - goto err_out; + return false; } memcpy(&rpc2_id, id, 64); @@ -593,13 +576,13 @@ bool rpc2_login_decode(const json_t *val) if(!tmp) { applog(LOG_ERR, "JSON inval status"); - goto err_out; + return false; } s = json_string_value(tmp); if(!s) { applog(LOG_ERR, "JSON status is not a string"); - goto err_out; + return false; } if(strcmp(s, "OK")) { @@ -608,8 +591,6 @@ bool rpc2_login_decode(const json_t *val) } return true; - -err_out: return false; } static void share_result(int result, const char *reason) @@ -665,7 +646,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work) char hash[32]; cryptonight_hash((void *)hash, (const void *)work->data, 76); char *hashhex = bin2hex((const unsigned char *)hash, 32); - snprintf(s, JSON_BUF_LEN, + snprintf(s, sizeof(s), "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}", rpc2_id, work->job_id, noncestr, hashhex); free(hashhex); @@ -674,7 +655,8 @@ static bool submit_upstream_work(CURL *curl, struct work *work) if(unlikely(!stratum_send_line(&stratum, s))) { applog(LOG_ERR, "submit_upstream_work stratum_send_line failed"); - goto out; + free(str); + return rc; } } else @@ -684,7 +666,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work) char hash[32]; cryptonight_hash((void *)hash, (const void *)work->data, 76); char *hashhex = bin2hex((const unsigned char *)hash, 32); - snprintf(s, JSON_BUF_LEN, + snprintf(s, sizeof(s), "{\"method\": \"submit\", \"params\": {\"id\": \"%s\", \"job_id\": \"%s\", \"nonce\": \"%s\", \"result\": \"%s\"}, \"id\":1}", rpc2_id, work->job_id, noncestr, hashhex); free(noncestr); @@ -695,7 +677,8 @@ static bool submit_upstream_work(CURL *curl, struct work *work) if(unlikely(!val)) { applog(LOG_ERR, "submit_upstream_work json_rpc_call failed"); - goto out; + free(str); + return rc; } res = json_object_get(val, "result"); json_t *status = json_object_get(res, "status"); @@ -707,10 +690,6 @@ static bool submit_upstream_work(CURL *curl, struct work *work) } rc = true; - -out: - free(str); - return rc; } static const char *rpc_req = @@ -761,14 +740,14 @@ static bool rpc2_login(CURL *curl) struct timeval tv_start, tv_end, diff; char s[345]; - snprintf(s, JSON_BUF_LEN, "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"" USER_AGENT "\"}, \"id\": 1}", rpc_user, rpc_pass); + snprintf(s, sizeof(s), "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"" USER_AGENT "\"}, \"id\": 1}", rpc_user, rpc_pass); gettimeofday(&tv_start, NULL); val = json_rpc_call(curl, rpc_url, rpc_userpass, s, false, false, NULL); gettimeofday(&tv_end, NULL); if(!val) - goto end; + return rc; // applog(LOG_DEBUG, "JSON value: %s", json_dumps(val, 0)); @@ -776,13 +755,13 @@ static bool rpc2_login(CURL *curl) json_t *result = json_object_get(val, "result"); - if(!result) goto end; + if(!result) return rc; json_t *job = json_object_get(result, "job"); if(!rpc2_job_decode(job, &g_work)) { - goto end; + return rc; } if(opt_debug && rc) @@ -793,9 +772,6 @@ static bool rpc2_login(CURL *curl) } json_decref(val); - -end: - return rc; } static void workio_cmd_free(struct workio_cmd *wc) @@ -1002,22 +978,22 @@ static bool submit_work(struct thr_info *thr, const struct work *work_in) return false; wc->u.work = (struct work *)malloc(sizeof(*work_in)); - if(!wc->u.work) - goto err_out; + if(!wc->u.work) { + workio_cmd_free(wc); + return false; + } wc->cmd = WC_SUBMIT_WORK; wc->thr = thr; memcpy(wc->u.work, work_in, sizeof(*work_in)); /* send solution to workio thread */ - if(!tq_push(thr_info[work_thr_id].q, wc)) - goto err_out; + if(!tq_push(thr_info[work_thr_id].q, wc)) { + workio_cmd_free(wc); + return false; + } return true; - -err_out: - workio_cmd_free(wc); - return false; } static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work) @@ -1062,9 +1038,6 @@ static void *miner_thread(void *userdata) affine_to_cpu(thr_id, thr_id % num_processors); } - if(device_config[thr_id][0] == 0) - device_config[thr_id][0] = 4 * device_mpcount[thr_id]; - applog(LOG_INFO, "GPU #%d: %s (%d SMX), using %d blocks of %d threads", device_map[thr_id], device_name[thr_id], device_mpcount[thr_id], device_config[thr_id][0], device_config[thr_id][1]); @@ -1517,9 +1490,6 @@ static void parse_arg(int key, char *arg) switch(key) { - case 'a': - applog(LOG_WARNING, "Ignoring algo switch, this program does only cryptonight now."); - break; case 'B': opt_background = true; break; @@ -1966,8 +1936,6 @@ int main(int argc, char *argv[]) for(i = 0; i < 8; i++) { - device_config[i][0] = opt_cn_blocks; - device_config[i][1] = opt_cn_threads; device_bfactor[i] = default_bfactor; device_bsleep[i] = default_bsleep; } @@ -2124,10 +2092,7 @@ int main(int argc, char *argv[]) } } - applog(LOG_INFO, "%d miner threads started, " - "using '%s' algorithm.", - opt_n_threads, - algo_names[opt_algo]); + applog(LOG_INFO, "%d miner threads started", opt_n_threads); #ifdef WIN32 timeBeginPeriod(1); // enable high timer precision (similar to Google Chrome Trick) diff --git a/crypto/c_blake256.c b/crypto/c_blake256.c index 2f1a804..0b484b9 100755 --- a/crypto/c_blake256.c +++ b/crypto/c_blake256.c @@ -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; } diff --git a/crypto/c_groestl.c b/crypto/c_groestl.c index 0f57ea1..fa28e8a 100755 --- a/crypto/c_groestl.c +++ b/crypto/c_groestl.c @@ -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; } diff --git a/crypto/c_keccak.c b/crypto/c_keccak.c index 28e9c6a..d3c5c32 100755 --- a/crypto/c_keccak.c +++ b/crypto/c_keccak.c @@ -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; @@ -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)); } diff --git a/crypto/c_keccak.h b/crypto/c_keccak.h index 566a305..435bd0d 100755 --- a/crypto/c_keccak.h +++ b/crypto/c_keccak.h @@ -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 diff --git a/crypto/oaes_lib.c b/crypto/oaes_lib.c index 9427d82..ac5d987 100755 --- a/crypto/oaes_lib.c +++ b/crypto/oaes_lib.c @@ -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; @@ -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; } @@ -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 ) ^ @@ -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; @@ -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 ) @@ -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 @@ -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 ) { @@ -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; @@ -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 ) { @@ -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 ) { @@ -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 diff --git a/cryptonight/cryptonight.cu b/cryptonight/cryptonight.cu index 9e790a1..1cb9ba4 100755 --- a/cryptonight/cryptonight.cu +++ b/cryptonight/cryptonight.cu @@ -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]; @@ -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; + } + } + } } } diff --git a/miner.h b/miner.h index ec3e41a..ebf3ab8 100755 --- a/miner.h +++ b/miner.h @@ -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)