mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-26 19:52:38 +00:00
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:
parent
5678317baf
commit
053ddfe3fd
3 changed files with 28 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Reference in a new issue