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

[CustomDevice] Improve device initialize & release (#57099)

上级 88f1a98e
...@@ -30,10 +30,17 @@ ...@@ -30,10 +30,17 @@
namespace phi { namespace phi {
void Device::CheckInitialized() { void Device::CheckInitialized() {
std::call_once(initialized_, [&]() { this->impl_->InitDevice(dev_id_); }); std::call_once(initialized_once_flag_, [&]() {
this->impl_->InitDevice(dev_id_);
this->initialized_ = true;
});
} }
Device::~Device() { impl_->DeInitDevice(dev_id_); } Device::~Device() {
if (initialized_) {
impl_->DeInitDevice(dev_id_);
}
}
void Device::CreateStream(stream::Stream* stream, void Device::CreateStream(stream::Stream* stream,
const stream::Stream::Priority& priority, const stream::Stream::Priority& priority,
......
...@@ -127,7 +127,8 @@ class Device final { ...@@ -127,7 +127,8 @@ class Device final {
private: private:
size_t dev_id_; size_t dev_id_;
DeviceInterface* impl_; DeviceInterface* impl_;
std::once_flag initialized_; std::once_flag initialized_once_flag_;
bool initialized_{false};
}; };
class DeviceManager { class DeviceManager {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册