未验证 提交 23c036d6 编写于 作者: R ronnywang 提交者: GitHub

clean up DeviceManager in advance manually (#40504)

上级 f5bf46e6
......@@ -114,6 +114,7 @@ limitations under the License. */
#include "paddle/fluid/pybind/metrics_py.h"
#include "paddle/fluid/pybind/ps_gpu_wrapper_py.h"
#include "paddle/fluid/pybind/pybind_boost_headers.h"
#include "paddle/phi/backends/device_manager.h"
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#include "paddle/fluid/pybind/nccl_wrapper_py.h"
......@@ -742,6 +743,11 @@ PYBIND11_MODULE(core_noavx, m) {
// stored in this static instance to avoid illegal memory access.
m.def("clear_kernel_factory",
[]() { phi::KernelFactory::Instance().kernels().clear(); });
m.def("clear_device_manager", []() {
#ifdef PADDLE_WITH_CUSTOM_DEVICE
phi::DeviceManager::Clear();
#endif
});
// NOTE(zjl): ctest would load environment variables at the beginning even
// though we have not `import paddle.fluid as fluid`. So we add this API
......
......@@ -393,6 +393,11 @@ DeviceManager& DeviceManager::Instance() {
return platform_manager;
}
void DeviceManager::Clear() {
Instance().device_map_.clear();
Instance().device_impl_map_.clear();
}
std::vector<std::string> ListAllLibraries(const std::string& library_dir) {
std::vector<std::string> libraries;
std::regex express(".*\\.so");
......
......@@ -158,6 +158,8 @@ class DeviceManager {
static std::vector<size_t> GetDeviceList(const std::string& device_type);
static void Clear();
private:
DISABLE_COPY_AND_ASSIGN(DeviceManager);
DeviceManager() {}
......
......@@ -228,3 +228,5 @@ if core.is_compiled_with_npu():
atexit.register(core.clear_executor_cache)
# NOTE(Aganlengzi): clean up KernelFactory in advance manually.
atexit.register(core.clear_kernel_factory)
# NOTE(wangran16): clean up DeviceManger in advance manually.
atexit.register(core.clear_device_manager)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册