未验证 提交 73196e5a 编写于 作者: D duanyanhui 提交者: GitHub

[Custom Device] Add singleton to custom device (#46963)

* add singleton to custom device

* Update custom_device.cc

Init device_init_flag_ in default
上级 166ff39a
......@@ -53,11 +53,14 @@ class CustomDevice : public DeviceInterface {
~CustomDevice() override { Finalize(); }
size_t GetDeviceCount() override {
size_t count;
if (pimpl_->get_device_count(&count) != C_SUCCESS) {
count = 0;
if (!device_init_flag_) {
if (pimpl_->get_device_count(&device_count_) != C_SUCCESS) {
device_count_ = 0;
} else {
device_init_flag_ = true;
}
}
return count;
return device_count_;
}
std::vector<size_t> GetDeviceList() override {
......@@ -882,6 +885,8 @@ class CustomDevice : public DeviceInterface {
std::unique_ptr<C_DeviceInterface> pimpl_;
void* dso_handle_;
std::unordered_map<size_t, C_Device_st> devices_pool;
bool device_init_flag_ = false;
size_t device_count_;
};
bool ValidCustomCustomRuntimeParams(const CustomRuntimeParams* params) {
......
......@@ -140,6 +140,7 @@ class TestCustomCPUPlugin(unittest.TestCase):
import paddle
paddle.set_device('custom_cpu')
paddle.device.get_available_device()
x_tensor = paddle.to_tensor(x, stop_gradient=False)
y_tensor = paddle.to_tensor(y)
z1_tensor = paddle.matmul(x_tensor, y_tensor)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册