Move DNNL workaround to EP (#4738)

This commit is contained in:
Tiago Koji Castro Shibata 2020-08-10 13:06:22 -07:00 committed by GitHub
parent 487665c21f
commit 082a741636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View file

@ -509,22 +509,6 @@ struct ProviderLibrary {
if (!handle_)
return;
#if defined(_WIN32) && !defined(_OPENMP)
{
// We crash when unloading DNNL on Windows when OpenMP also unloads (As there are threads
// still running code inside the openmp runtime DLL if OMP_WAIT_POLICY is set to ACTIVE).
// To avoid this, we pin the OpenMP DLL so that it unloads as late as possible.
HMODULE handle{};
#ifdef _DEBUG
constexpr const char* dll_name = "vcomp140d.dll";
#else
constexpr const char* dll_name = "vcomp140.dll";
#endif
::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN, dll_name, &handle);
assert(handle); // It should exist
}
#endif
Provider* (*PGetProvider)();
Env::Default().GetSymbolFromLibrary(handle_, "GetProvider", (void**)&PGetProvider);

View file

@ -4,6 +4,7 @@
#include "core/providers/shared_library/provider_api.h"
#include "core/providers/dnnl/dnnl_provider_factory.h"
#include <atomic>
#include <cassert>
#include "dnnl_execution_provider.h"
using namespace onnxruntime;
@ -32,6 +33,21 @@ std::unique_ptr<Provider_IExecutionProvider> DnnlProviderFactory::CreateProvider
struct Dnnl_Provider : Provider {
std::shared_ptr<Provider_IExecutionProviderFactory> CreateExecutionProviderFactory(int use_arena) override {
#if defined(_WIN32) && !defined(_OPENMP)
{
// We crash when unloading DNNL on Windows when OpenMP also unloads (As there are threads
// still running code inside the openmp runtime DLL if OMP_WAIT_POLICY is set to ACTIVE).
// To avoid this, we pin the OpenMP DLL so that it unloads as late as possible.
HMODULE handle{};
#ifdef _DEBUG
constexpr const char* dll_name = "vcomp140d.dll";
#else
constexpr const char* dll_name = "vcomp140.dll";
#endif
::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_PIN, dll_name, &handle);
assert(handle); // It should exist
}
#endif
return std::make_shared<DnnlProviderFactory>(use_arena != 0);
}