Skip to content

Commit

Permalink
Set up default batch size and threads.
Browse files Browse the repository at this point in the history
Fixes issue #2214.

Pull request #2256.
  • Loading branch information
ihavnoid authored and gcp committed Apr 2, 2019
1 parent d0aacb8 commit 31b795b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/GTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ void GTP::setup_default_parameters() {
cfg_allow_pondering = true;

// we will re-calculate this on Leela.cpp
cfg_num_threads = 0;
cfg_num_threads = 1;
// we will re-calculate this on Leela.cpp
cfg_batch_size = 0;
cfg_batch_size = 1;

cfg_max_memory = UCTSearch::DEFAULT_MAX_MEMORY;
cfg_max_playouts = UCTSearch::UNLIMITED_PLAYOUTS;
Expand Down
15 changes: 8 additions & 7 deletions src/Leela.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void calculate_thread_count_cpu(boost::program_options::variables_map & v
// If we are CPU-based, there is no point using more than the number of CPUs/
auto cfg_max_threads = std::min(SMP::get_num_cpus(), size_t{MAX_CPUS});

if (vm.count("threads")) {
if (vm["threads"].as<unsigned int>() > 0) {
auto num_threads = vm["threads"].as<unsigned int>();
if (num_threads > cfg_max_threads) {
myprintf("Clamping threads to maximum = %d\n", cfg_max_threads);
Expand All @@ -91,15 +91,15 @@ static void calculate_thread_count_gpu(boost::program_options::variables_map & v
gpu_count = 1;
}

if (vm.count("threads")) {
if (vm["threads"].as<unsigned int>() > 0) {
auto num_threads = vm["threads"].as<unsigned int>();
if (num_threads > cfg_max_threads) {
myprintf("Clamping threads to maximum = %d\n", cfg_max_threads);
num_threads = cfg_max_threads;
}
cfg_num_threads = num_threads;

if (vm.count("batchsize")) {
if (vm["batchsize"].as<unsigned int>() > 0) {
cfg_batch_size = vm["batchsize"].as<unsigned int>();
} else {
cfg_batch_size = (cfg_num_threads + (gpu_count * 2) - 1) / (gpu_count * 2);
Expand All @@ -111,7 +111,7 @@ static void calculate_thread_count_gpu(boost::program_options::variables_map & v
}
}
} else {
if (vm.count("batchsize")) {
if (vm["batchsize"].as<unsigned int>() > 0) {
cfg_batch_size = vm["batchsize"].as<unsigned int>();
} else {
cfg_batch_size = 5;
Expand All @@ -136,8 +136,8 @@ static void parse_commandline(int argc, char *argv[]) {
gen_desc.add_options()
("help,h", "Show commandline options.")
("gtp,g", "Enable GTP mode.")
("threads,t", po::value<unsigned int>(),
"Number of threads to use.")
("threads,t", po::value<unsigned int>()->default_value(0),
"Number of threads to use. Select 0 to let leela-zero pick a reasonable default.")
("playouts,p", po::value<int>(),
"Weaken engine by limiting the number of playouts. "
"Requires --noponder.")
Expand Down Expand Up @@ -172,7 +172,7 @@ static void parse_commandline(int argc, char *argv[]) {
"ID of the OpenCL device(s) to use (disables autodetection).")
("full-tuner", "Try harder to find an optimal OpenCL tuning.")
("tune-only", "Tune OpenCL only and then exit.")
("batchsize", po::value<unsigned int>(), "Max batch size. Default is the number of threads divided by (2 * number of OpenCL devices).")
("batchsize", po::value<unsigned int>()->default_value(0), "Max batch size. Select 0 to let leela-zero pick a reasonable default.")
#ifdef USE_HALF
("precision", po::value<std::string>(),
"Floating-point precision (single/half/auto).\n"
Expand Down Expand Up @@ -349,6 +349,7 @@ static void parse_commandline(int argc, char *argv[]) {
} else {
#ifdef USE_OPENCL
calculate_thread_count_gpu(vm);
myprintf("Using OpenCL batch size of %d\n", cfg_batch_size);
#endif
}
myprintf("Using %d thread(s).\n", cfg_num_threads);
Expand Down

0 comments on commit 31b795b

Please sign in to comment.