Commit b7152ad6 authored by Jayaram Bobba's avatar Jayaram Bobba Committed by Scott Cyphers

Cap the max parallelism that user can request (#2681)

parent 2b674e34
......@@ -20,6 +20,8 @@
#include "ngraph/except.hpp"
#define MAX_PARALLELISM_THRESHOLD 2
static int GetNumCores()
{
const auto omp_num_threads = std::getenv("OMP_NUM_THREADS");
......@@ -38,6 +40,17 @@ static int GetNumCores()
{
count = std::thread::hardware_concurrency() / 2;
}
int max_parallelism_allowed = MAX_PARALLELISM_THRESHOLD * std::thread::hardware_concurrency();
if (count > max_parallelism_allowed)
{
throw ngraph::ngraph_error(
"OMP_NUM_THREADS and/or NGRAPH_INTRA_OP_PARALLELISM is too high: "
"(" +
std::to_string(count) + "). Please specify a value in range [1-" +
std::to_string(max_parallelism_allowed) + "]");
}
return count < 1 ? 1 : count;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment