Disable per-session thread pool for web (#18480)

### Description
ORT web prefers to use a global thread pool for all inference sessions.
See how OrtCreateSession is implemented in
https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/wasm/api.cc#L183
.

Application code can only the global thread poo. However, internal
testing code still often use per-session threadpool. This pr is to fix
the inconsistency.

### Motivation and Context
Replace PR #18476
This commit is contained in:
Changming Sun 2024-01-10 18:45:49 -08:00 committed by GitHub
parent 5678317baf
commit 053ddfe3fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

@ -65,6 +65,11 @@ struct FreeDimensionOverride {
* Configuration information for a session.
*/
struct SessionOptions {
#if defined(__wasm__) && defined(__EMSCRIPTEN_PTHREADS__)
static constexpr bool DEFAULT_USE_PER_SESSION_THREADS = false;
#else
static constexpr bool DEFAULT_USE_PER_SESSION_THREADS = true;
#endif
ExecutionMode execution_mode = ExecutionMode::ORT_SEQUENTIAL;
// set the execution order of the graph
@ -129,7 +134,8 @@ struct SessionOptions {
// By default the session uses its own set of threadpools, unless this is set to false.
// Use this in conjunction with the CreateEnvWithGlobalThreadPools API.
bool use_per_session_threads = true;
bool use_per_session_threads = DEFAULT_USE_PER_SESSION_THREADS;
bool thread_pool_allow_spinning = true;
// Deterministic compute is likely not as performant. This option is default to false.

View file

@ -578,6 +578,9 @@ TEST(InferenceSessionTests, ModelMetadata) {
}
#endif
TEST(InferenceSessionTests, CheckRunLogger) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
SessionOptions so;
so.session_logid = "CheckRunLogger";
@ -837,6 +840,9 @@ TEST(InferenceSessionTests, PreAllocateOutputVector) {
}
TEST(InferenceSessionTests, ConfigureVerbosityLevel) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
SessionOptions so;
so.session_logid = "ConfigureVerbosityLevel";
@ -2661,6 +2667,9 @@ class InferenceSessionTestSharingAllocator : public InferenceSessionWrapper {
// Ensure sessions use the same allocator. It uses ORT created allocator.
TEST(InferenceSessionTests, AllocatorSharing_EnsureSessionsUseSameOrtCreatedAllocator) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
auto logging_manager = std::make_unique<logging::LoggingManager>(
std::unique_ptr<ISink>(new CLogSink()), logging::Severity::kVERBOSE, false,
LoggingManager::InstanceType::Temporal);
@ -2706,6 +2715,9 @@ TEST(InferenceSessionTests, AllocatorSharing_EnsureSessionsUseSameOrtCreatedAllo
// Ensure sessions don't use the same allocator. It uses ORT created allocator.
TEST(InferenceSessionTests, AllocatorSharing_EnsureSessionsDontUseSameOrtCreatedAllocator) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
auto logging_manager = std::make_unique<logging::LoggingManager>(
std::unique_ptr<ISink>(new CLogSink()), logging::Severity::kVERBOSE, false,
LoggingManager::InstanceType::Temporal);
@ -2758,6 +2770,9 @@ class InferenceSessionTestSharingInitializer : public InferenceSessionWrapper {
};
TEST(InferenceSessionTests, InitializerSharing_EnsureSessionsUseUserAddedInitializer) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
auto logging_manager = std::make_unique<logging::LoggingManager>(
std::unique_ptr<ISink>(new CLogSink()), logging::Severity::kVERBOSE, false,
LoggingManager::InstanceType::Temporal);
@ -2942,6 +2957,9 @@ TEST(InferenceSessionTests, GlobalThreadPoolWithDenormalAsZero) {
// test inter thread pool with setting denormal as zero
TEST(InferenceSessionTests, InterThreadPoolWithDenormalAsZero) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
// test if denormal-as-zero mode is supported
if (!SetDenormalAsZero(false)) {
return;

View file

@ -588,6 +588,9 @@ TEST_F(ActivationOpTest, Softplus) {
}
TEST_F(ActivationOpNoInfTest, Softsign) {
if constexpr (!SessionOptions::DEFAULT_USE_PER_SESSION_THREADS) {
GTEST_SKIP() << "Skipping the test";
}
// TODO: Unskip when fixed #41968513
if (DefaultDmlExecutionProvider().get() != nullptr) {
GTEST_SKIP() << "Skipping because of the following error: The difference between expected[i] and output[i] is 1, which exceeds threshold";