Skip to content

Commit 9c56e8c

Browse files
committed
[NPU] register finalize on exit
1 parent cbe5c9f commit 9c56e8c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

paddle/fluid/platform/npu_info.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ void NPUMemcpySync(void *dst, const void *src, size_t count,
190190
enum aclrtMemcpyKind kind, size_t dst_max_count) {
191191
// NOTE(zhiqiu): The default max_count is count
192192
dst_max_count = dst_max_count ? dst_max_count : count;
193+
VLOG(4) << dst << " " << dst_max_count << " " << src << " " << count << " "
194+
<< kind << " " << stream;
193195
PADDLE_ENFORCE_NPU_SUCCESS(aclrtMemcpy(dst, dst_max_count, src, count, kind));
194196
}
195197

paddle/fluid/pybind/pybind.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,9 +2178,7 @@ All parameter, weight, gradient are variables in Paddle.
21782178

21792179
#ifdef PADDLE_WITH_ASCEND_CL
21802180
m.def("get_npu_device_count", platform::GetNPUDeviceCount);
2181-
m.def("_npu_finalize", []() {
2182-
platform::AclInstance::Instance().Finalize();
2183-
}); // private interface
2181+
m.def("npu_finalize", []() { platform::AclInstance::Instance().Finalize(); });
21842182

21852183
py::class_<platform::NPUProfConfigWrapper>(m, "NPUProfConfigWrapper");
21862184

python/paddle/fluid/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import print_function
1616
import os
1717
import sys
18+
import atexit
1819

1920
# The legacy core need to be removed before "import core",
2021
# in case of users installing paddlepadde without -U option
@@ -255,3 +256,8 @@ def __bootstrap__():
255256
monkey_patch_variable()
256257
__bootstrap__()
257258
monkey_patch_varbase()
259+
260+
# NOTE(zhiqiu): register npu_finalize on the exit of Python,
261+
# do some clean up manually.
262+
if paddle.is_compiled_with_npu():
263+
atexit.register(core.npu_finalize)

0 commit comments

Comments
 (0)