未验证 提交 c35a9880 编写于 作者: Q QingshuChen 提交者: GitHub

fix malloc L3 failed bug for kunlun (#30745)

* fix malloc L3 failed bug for kunlun

* minor
上级 31ed9c9e
...@@ -189,13 +189,25 @@ XPUDeviceContext::XPUDeviceContext(XPUPlace place) : place_(place) { ...@@ -189,13 +189,25 @@ XPUDeviceContext::XPUDeviceContext(XPUPlace place) : place_(place) {
"Baidu Kunlun Card is properly installed.", "Baidu Kunlun Card is properly installed.",
ret)); ret));
context_ = xpu::create_context(); context_ = xpu::create_context();
void* l3ptr = nullptr; const int MAX_XPU_NUM = 16;
int l3_size = 13.5 * 1024 * 1024; const int l3_size = 13.5 * 1024 * 1024;
xpu_malloc(static_cast<void**>(&l3ptr), l3_size, XPU_MEM_L3); static void* l3ptrs[MAX_XPU_NUM] = {nullptr};
if (l3ptr != nullptr) {
context_->_l3_mgr.set(l3ptr, l3_size); auto selected_xpus = GetXPUSelectedDevices();
std::cout << "set l3 size " << l3_size << std::endl; for (unsigned int i = 0; i < selected_xpus.size(); i++) {
if (place.device == selected_xpus[i]) {
if (l3ptrs[place.device] == nullptr) {
xpu_malloc(static_cast<void**>(&l3ptrs[place.device]), l3_size,
XPU_MEM_L3);
}
if (l3ptrs[place.device] != nullptr) {
context_->_l3_mgr.set(l3ptrs[place.device], l3_size);
VLOG(3) << "xpu place " << place.device << " set l3 size " << l3_size;
}
break;
}
} }
ret = xpu_set_device(dev_id); ret = xpu_set_device(dev_id);
PADDLE_ENFORCE_EQ(ret, XPU_SUCCESS, PADDLE_ENFORCE_EQ(ret, XPU_SUCCESS,
platform::errors::External( platform::errors::External(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册