未验证 提交 d1ac85e5 编写于 作者: C Chen Weihang 提交者: GitHub

fix device context init error (#43910)

上级 c7694b82
......@@ -906,6 +906,8 @@ class DeviceContextPool {
return *pool;
}
static bool IsInitialized() { return pool != nullptr; }
static void SetPool(DeviceContextPool* dev_pool) { pool = dev_pool; }
/*! \brief Return handle of single device context. */
......
......@@ -333,7 +333,7 @@ cc_library(
cc_library(
context_pool
SRCS context_pool.cc
DEPS phi_context phi_enforce place)
DEPS phi_context phi_enforce place init)
cc_library(
kernel_dispatch
......
......@@ -17,6 +17,8 @@ limitations under the License. */
#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/enforce.h"
#include "paddle/fluid/platform/init.h"
namespace paddle {
namespace experimental {
......@@ -28,6 +30,9 @@ DeviceContextPool& DeviceContextPool::Instance() {
const phi::DeviceContext* DeviceContextPool::Get(const Place& place) {
auto it = context_map_.find(place);
if (it == context_map_.end()) {
if (!paddle::platform::DeviceContextPool::IsInitialized()) {
paddle::framework::InitDevices();
}
// only when we need the specific DeviceContext, get and cache it
auto* dev_ctx = paddle::platform::DeviceContextPool::Instance().Get(place);
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册