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

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

上级 88f1a98e
......@@ -30,10 +30,17 @@
namespace phi {
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,
const stream::Stream::Priority& priority,
......
......@@ -127,7 +127,8 @@ class Device final {
private:
size_t dev_id_;
DeviceInterface* impl_;
std::once_flag initialized_;
std::once_flag initialized_once_flag_;
bool initialized_{false};
};
class DeviceManager {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册