Skip to content

Commit 7c7d5a1

Browse files
authored
Disable thread pool creation when enabled OpenMP (#2485)
1 parent e29fb5c commit 7c7d5a1

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

onnxruntime/core/framework/session_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct SessionOptions {
5555
TransformerLevel graph_optimization_level = TransformerLevel::Level1;
5656

5757
// controls the size of the thread pool used to parallelize the execution of tasks within individual nodes (ops)
58+
// if OpenMP is enabled, this configuration will be ignored
5859
int intra_op_num_threads = 0;
5960

6061
// controls the size of the thread pool used to parallelize the execution of nodes (ops)

onnxruntime/core/session/inference_session.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ InferenceSession::InferenceSession(const SessionOptions& session_options,
102102
: session_options_(session_options),
103103
graph_transformation_mgr_(session_options.max_num_graph_transformation_steps),
104104
logging_manager_(logging_manager),
105+
#ifndef USE_OPENMP
105106
thread_pool_(concurrency::CreateThreadPool("intra_op_thread_pool",
106107
session_options.intra_op_num_threads)),
108+
#else
109+
thread_pool_(nullptr),
110+
#endif
107111
inter_op_thread_pool_(session_options.execution_mode == ExecutionMode::ORT_PARALLEL
108112
? concurrency::CreateThreadPool("inter_op_thread_pool",
109113
session_options.inter_op_num_threads)

onnxruntime/test/perftest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Options:
3232
3333
-v: Show verbose information.
3434
35-
-x: [intra_op_num_threads]: Sets the number of threads used to parallelize the execution within nodes. A value of 0 means the test will auto-select a default. Must >=0.
35+
-x: [intra_op_num_threads]: Sets the number of threads used to parallelize the execution within nodes. A value of 0 means the test will auto-select a default. Must >=0. If OpenMP is enabled, this configuration will be ignored.
3636

3737
-y: [inter_op_num_threads]: Sets the number of threads used to parallelize the execution of the graph (across nodes), A value of 0 means the test will auto-select a default. Must >=0.
3838

onnxruntime/test/perftest/command_args_parser.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace perftest {
4141
"\t-p [profile_file]: Specifies the profile name to enable profiling and dump the profile data to the file.\n"
4242
"\t-s: Show statistics result, like P75, P90.\n"
4343
"\t-v: Show verbose information.\n"
44-
"\t-x [intra_op_num_threads]: Sets the number of threads used to parallelize the execution within nodes, A value of 0 means ORT will pick a default. Must >=0.\n"
44+
"\t-x [intra_op_num_threads]: Sets the number of threads used to parallelize the execution within nodes, A value of 0 means ORT will pick a default. Must >=0. If OpenMP is enabled, this configuration will be ignored.\n"
4545
"\t-y [inter_op_num_threads]: Sets the number of threads used to parallelize the execution of the graph (across nodes), A value of 0 means ORT will pick a default. Must >=0.\n"
4646
"\t-P: Use parallel executor instead of sequential executor.\n"
4747
"\t-o [optimization level]: Default is 1. Valid values are 0 (disable), 1 (basic), 2 (extended), 99 (all).\n"
@@ -123,10 +123,15 @@ namespace perftest {
123123
test_config.run_config.f_verbose = true;
124124
break;
125125
case 'x':
126+
#ifdef USE_OPENMP
127+
fprintf(stderr, "cannot use argument '-x' when OpenMP is enabled.\n");
128+
return false;
129+
#else
126130
test_config.run_config.intra_op_num_threads = static_cast<int>(OrtStrtol<PATH_CHAR_TYPE>(optarg, nullptr));
127131
if (test_config.run_config.intra_op_num_threads < 0) {
128132
return false;
129133
}
134+
#endif
130135
break;
131136
case 'y':
132137
test_config.run_config.inter_op_num_threads = static_cast<int>(OrtStrtol<PATH_CHAR_TYPE>(optarg, nullptr));

onnxruntime/test/perftest/ort_test_session.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device
8282
} else if (provider_name == onnxruntime::kAclExecutionProvider) {
8383
#ifdef USE_ACL
8484
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_ACL(session_options,
85-
performance_test_config.run_config.enable_cpu_mem_arena ? 1 : 0));
85+
performance_test_config.run_config.enable_cpu_mem_arena ? 1 : 0));
8686
#else
8787
ORT_THROW("Acl is not supported in this build\n");
8888
#endif
@@ -100,8 +100,11 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device
100100
else
101101
session_options.DisableMemPattern();
102102
session_options.SetExecutionMode(performance_test_config.run_config.execution_mode);
103+
104+
#ifndef USE_OPENMP
103105
fprintf(stdout, "Setting intra_op_num_threads to %d\n", performance_test_config.run_config.intra_op_num_threads);
104106
session_options.SetIntraOpNumThreads(performance_test_config.run_config.intra_op_num_threads);
107+
#endif
105108

106109
if (performance_test_config.run_config.execution_mode == ExecutionMode::ORT_PARALLEL) {
107110
fprintf(stdout, "Setting inter_op_num_threads to %d\n", performance_test_config.run_config.inter_op_num_threads);

0 commit comments

Comments
 (0)