mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-17 18:40:28 +00:00
Change session option values if they don't work with EPs being registered for the session (#4991)
This commit is contained in:
parent
8a03b6e5c7
commit
4fd4b74149
3 changed files with 31 additions and 24 deletions
|
|
@ -348,15 +348,34 @@ common::Status InferenceSession::RegisterExecutionProvider(std::unique_ptr<IExec
|
|||
|
||||
const std::string& provider_type = p_exec_provider->Type();
|
||||
|
||||
// DML's memory is not byte addressable and hence mem pattern doesn't work.
|
||||
// Some session option values (default or user provided) may not work with some EPs.
|
||||
// Rather than put the onus on the user to know these, make the appropriate change while logging the change.
|
||||
if (provider_type == onnxruntime::kDmlExecutionProvider) {
|
||||
// DML's memory is not byte addressable and hence mem pattern doesn't work.
|
||||
if (session_options_.enable_mem_pattern) {
|
||||
return Status(ONNXRUNTIME, INVALID_ARGUMENT,
|
||||
"Memory pattern must be disabled before registering DMLExecutionProvider");
|
||||
LOGS(*session_logger_, WARNING)
|
||||
<< "Having memory pattern enabled is not supported while using the DML Execution Provider. "
|
||||
<< "So disabling it for this session since it uses the DML Execution Provider.";
|
||||
session_options_.enable_mem_pattern = false;
|
||||
}
|
||||
|
||||
// Parallel execution mode does not support DML EP
|
||||
if (session_options_.execution_mode != ExecutionMode::ORT_SEQUENTIAL) {
|
||||
return Status(ONNXRUNTIME, INVALID_ARGUMENT,
|
||||
"Sequential execution must be enabled before registering DMLExecutionProvider");
|
||||
LOGS(*session_logger_, WARNING)
|
||||
<< "Parallel execution mode does not support the DML Execution Provider. "
|
||||
<< "So making the execution mode sequential for this session since it uses the DML Execution Provider.";
|
||||
|
||||
session_options_.execution_mode = ExecutionMode::ORT_SEQUENTIAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (provider_type == onnxruntime::kCudaExecutionProvider) {
|
||||
// Parallel execution mode does not support the CUDA EP
|
||||
if (session_options_.execution_mode != ExecutionMode::ORT_SEQUENTIAL) {
|
||||
LOGS(*session_logger_, WARNING)
|
||||
<< "Parallel execution mode does not support the CUDA Execution Provider. "
|
||||
<< "So making the execution mode sequential for this session since it uses the CUDA Execution Provider.";
|
||||
session_options_.execution_mode = ExecutionMode::ORT_SEQUENTIAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -994,14 +1013,6 @@ common::Status InferenceSession::Initialize() {
|
|||
session_profiler_,
|
||||
session_options_.use_deterministic_compute);
|
||||
|
||||
if (session_options_.execution_mode == ExecutionMode::ORT_PARALLEL &&
|
||||
execution_providers_.Get(onnxruntime::kCudaExecutionProvider)) {
|
||||
status = common::Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT,
|
||||
"Parallel execution mode doesn't support CUDA Execution Provider currently.");
|
||||
LOGS(*session_logger_, ERROR) << status.ErrorMessage();
|
||||
return status;
|
||||
}
|
||||
|
||||
onnxruntime::Graph& graph = model_->MainGraph();
|
||||
|
||||
// Collect the kernel registries from execution provider instances;
|
||||
|
|
|
|||
|
|
@ -387,16 +387,6 @@ static ORT_STATUS_PTR LoadAndInitializeSession(_In_ const OrtEnv* /*env*/, _In_
|
|||
if (options) {
|
||||
for (auto& factory : options->provider_factories) {
|
||||
auto provider = factory->CreateProvider();
|
||||
if (provider->Type() == kDmlExecutionProvider) {
|
||||
if (options->value.enable_mem_pattern) {
|
||||
// TODO Instead of returning an error, should we set mem pattern to false here and log a warning saying so?
|
||||
// Doing so would be inconsistent with the Python API that doesn't go through this code path.
|
||||
return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Mem pattern should be disabled when using DML execution provider.");
|
||||
}
|
||||
if (options->value.execution_mode != ExecutionMode::ORT_SEQUENTIAL) {
|
||||
return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "Sequential execution should be enabled when using DML execution provider.");
|
||||
}
|
||||
}
|
||||
provider_list.push_back(std::move(provider));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1867,7 +1867,13 @@ TEST(InferenceSessionTests, TestParallelExecutionWithCudaProvider) {
|
|||
|
||||
auto status = session_object.Initialize();
|
||||
|
||||
ASSERT_TRUE(!status.IsOK());
|
||||
ASSERT_TRUE(status.IsOK());
|
||||
|
||||
const auto& so_queried = session_object.GetSessionOptions();
|
||||
|
||||
// execution mode is sequential since we have registered the CUDA EP
|
||||
// (which isn't supported by the parallel execution mode)
|
||||
ASSERT_TRUE(so_queried.execution_mode == ExecutionMode::ORT_SEQUENTIAL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue