未验证 提交 0cbdcdda 编写于 作者: R ronnywang 提交者: GitHub

call InitDevices only once (#47678)

上级 b4a3cca1
...@@ -164,7 +164,10 @@ void LoadCustomDevice(const std::string &library_dir) { ...@@ -164,7 +164,10 @@ void LoadCustomDevice(const std::string &library_dir) {
} }
#endif #endif
static std::once_flag init_devices_flag;
void InitDevices() { void InitDevices() {
std::call_once(init_devices_flag, []() {
// set name at the entry point of Paddle // set name at the entry point of Paddle
platform::SetCurrentThreadName("MainThread"); platform::SetCurrentThreadName("MainThread");
// CUPTI attribute should be set before any CUDA context is created (see CUPTI // CUPTI attribute should be set before any CUDA context is created (see CUPTI
...@@ -197,8 +200,8 @@ void InitDevices() { ...@@ -197,8 +200,8 @@ void InitDevices() {
// use user specified XPUs in single-node multi-process mode. // use user specified XPUs in single-node multi-process mode.
devices = platform::GetSelectedNPUDevices(); devices = platform::GetSelectedNPUDevices();
} catch (const std::exception &exp) { } catch (const std::exception &exp) {
LOG(WARNING) LOG(WARNING) << "Compiled with PADDLE_WITH_ASCEND_CL, but no NPU found "
<< "Compiled with PADDLE_WITH_ASCEND_CL, but no NPU found in runtime."; "in runtime.";
} }
#endif #endif
#ifdef PADDLE_WITH_IPU #ifdef PADDLE_WITH_IPU
...@@ -219,6 +222,7 @@ void InitDevices() { ...@@ -219,6 +222,7 @@ void InitDevices() {
} }
#endif #endif
InitDevices(devices); InitDevices(devices);
});
} }
void InitDevices(const std::vector<int> devices) { void InitDevices(const std::vector<int> devices) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册