Skip to content

Commit

Permalink
Autofind a better value for blocks and threads
Browse files Browse the repository at this point in the history
Thanks to the xmr-stak-nvidia developers
  • Loading branch information
esfomeado committed Jul 31, 2017
1 parent 863b5fb commit b4d0f50
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
5 changes: 0 additions & 5 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,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]);

Expand Down Expand Up @@ -1939,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;
}
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

0 comments on commit b4d0f50

Please sign in to comment.