-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GCC12: mismatched-new-delete error in custom_device.cc #42908
Comments
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~ Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the API,FAQ,Github Issue and AI community to get the answer.Have a nice day! |
Please try compiling with the patch below diff --git a/paddle/phi/backends/custom/custom_device.cc b/paddle/phi/backends/custom/custom_device.cc
index df757b2..6c74ebb 100644
--- a/paddle/phi/backends/custom/custom_device.cc
+++ b/paddle/phi/backends/custom/custom_device.cc
@@ -348,7 +348,7 @@ class CustomDevice : public DeviceInterface {
}
} else {
if (!pimpl_->memory_copy_p2p) {
- std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
+ std::unique_ptr<uint8_t> tmp(reinterpret_cast<uint8_t*>(new uint8_t[size]));
MemoryCopyD2H(src_dev_id, tmp.get(), src, size);
MemoryCopyH2D(dst_dev_id, dst, tmp.get(), size);
} else {
@@ -440,7 +440,7 @@ class CustomDevice : public DeviceInterface {
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS(
pimpl_->device_memory_set(device, ptr, value, size));
} else {
- std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
+ std::unique_ptr<uint8_t> tmp(reinterpret_cast<uint8_t*>(new uint8_t[size]));
memset(tmp.get(), value, size);
MemoryCopyH2D(dev_id, ptr, tmp.get(), size);
} |
The correct fix for this problem is shown below.diff --git a/paddle/phi/backends/custom/custom_device.cc b/paddle/phi/backends/custom/custom_device.cc
index 928101b09f..d7397353ef 100644
--- a/paddle/phi/backends/custom/custom_device.cc
+++ b/paddle/phi/backends/custom/custom_device.cc
@@ -358,8 +358,7 @@ class CustomDevice : public DeviceInterface {
}
} else {
if (!pimpl_->memory_copy_p2p) {
- std::unique_ptr<uint8_t> tmp(
- reinterpret_cast<uint8_t*>(new uint8_t[size]));
+ std::unique_ptr<uint8_t[]> tmp(new uint8_t[size]);
MemoryCopyD2H(src_dev_id, tmp.get(), src, size);
MemoryCopyH2D(dst_dev_id, dst, tmp.get(), size);
} else {
@@ -451,8 +450,7 @@ class CustomDevice : public DeviceInterface {
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS(
pimpl_->device_memory_set(device, ptr, value, size));
} else {
- std::unique_ptr<uint8_t> tmp(
- reinterpret_cast<uint8_t*>(new uint8_t[size]));
+ std::unique_ptr<uint8_t[]> tmp(new uint8_t[size]);
memset(tmp.get(), value, size);
MemoryCopyH2D(dev_id, ptr, tmp.get(), size);
} reference: https://en.cppreference.com/w/cpp/memory/unique_ptr
|
Here is the patch to fix this issue: From e98f569707ba9fc7669000f593fd51094594c992 Mon Sep 17 00:00:00 2001
From: Si Jinyuan <sijinyuan@foxmail.com>
Date: Fri, 30 Dec 2022 01:42:59 +0900
Subject: [PATCH] Fix GCC12: mismatched-new-delete error in custom_device.cc
according to https://en.cppreference.com/w/cpp/memory/unique_ptr
When using std::unique_ptr to manage array pointers,
should use
template <class T,class Deleter> class unique_ptr<T[], Deleter>;
instead of
template<class T, class Deleter = std::default_delete<T> >
class unique_ptr;
---
paddle/phi/backends/custom/custom_device.cc | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/paddle/phi/backends/custom/custom_device.cc b/paddle/phi/backends/custom/custom_device.cc
index 928101b09f..d7397353ef 100644
--- a/paddle/phi/backends/custom/custom_device.cc
+++ b/paddle/phi/backends/custom/custom_device.cc
@@ -358,8 +358,7 @@ class CustomDevice : public DeviceInterface {
}
} else {
if (!pimpl_->memory_copy_p2p) {
- std::unique_ptr<uint8_t> tmp(
- reinterpret_cast<uint8_t*>(new uint8_t[size]));
+ std::unique_ptr<uint8_t[]> tmp(new uint8_t[size]);
MemoryCopyD2H(src_dev_id, tmp.get(), src, size);
MemoryCopyH2D(dst_dev_id, dst, tmp.get(), size);
} else {
@@ -451,8 +450,7 @@ class CustomDevice : public DeviceInterface {
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS(
pimpl_->device_memory_set(device, ptr, value, size));
} else {
- std::unique_ptr<uint8_t> tmp(
- reinterpret_cast<uint8_t*>(new uint8_t[size]));
+ std::unique_ptr<uint8_t[]> tmp(new uint8_t[size]);
memset(tmp.get(), value, size);
MemoryCopyH2D(dev_id, ptr, tmp.get(), size);
}
--
2.37.1 (Apple Git-137.1)
|
@RexSi Thanks for your fix patch, you can create a PR to fix this issue. |
close due to #47466 merged |
bug描述 Describe the Bug
When compiling PaddlePaddle with GCC 12.1 several mismatched-new-delete errors arise in custom_device.cc of the Phi backend:
其他补充信息 Additional Supplementary Information
check out git master;
The text was updated successfully, but these errors were encountered: