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:
n file included from /usr/include/c++/12.1.0/memory:76,
from ./Paddle/paddle/fluid/platform/enforce.h:52,
from ./Paddle/paddle/fluid/platform/device/custom/enforce_custom.h:19,
from ./Paddle/paddle/phi/backends/custom/custom_device.cc:15:
In member function 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = unsigned char]',
inlined from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = unsigned char; _Dp = std::default_delete<unsigned char>]' at /usr/include/c++/12.1.0/bits/unique_ptr.h:396:17,
inlined from 'virtual void phi::CustomDevice::MemoryCopyP2P(const phi::Place&, void*, size_t, const void*, size_t, const phi::stream::Stream*)' at ./Paddle/paddle/phi/backends/custom/custom_device.cc:354:7:
/usr/include/c++/12.1.0/bits/unique_ptr.h:95:9: error: 'void operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete]
95 | delete __ptr;
| ^~~~~~~~~~~~
./Paddle/paddle/phi/backends/custom/custom_device.cc: In member function 'virtual void phi::CustomDevice::MemoryCopyP2P(const phi::Place&, void*, size_t, const void*, size_t, const phi::stream::Stream*)':
./Paddle/paddle/phi/backends/custom/custom_device.cc:351:54: note: returned from 'void* operator new [](std::size_t)'
351 | std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
| ^
In member function 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = unsigned char]',
inlined from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = unsigned char; _Dp = std::default_delete<unsigned char>]' at /usr/include/c++/12.1.0/bits/unique_ptr.h:396:17,
inlined from 'virtual void phi::CustomDevice::MemoryCopyP2P(const phi::Place&, void*, size_t, const void*, size_t, const phi::stream::Stream*)' at ./Paddle/paddle/phi/backends/custom/custom_device.cc:354:7:
/usr/include/c++/12.1.0/bits/unique_ptr.h:95:9: error: 'void operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete]
95 | delete __ptr;
| ^~~~~~~~~~~~
./Paddle/paddle/phi/backends/custom/custom_device.cc: In member function 'virtual void phi::CustomDevice::MemoryCopyP2P(const phi::Place&, void*, size_t, const void*, size_t, const phi::stream::Stream*)':
./Paddle/paddle/phi/backends/custom/custom_device.cc:351:54: note: returned from 'void* operator new [](std::size_t)'
351 | std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
| ^
In member function 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = unsigned char]',
inlined from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = unsigned char; _Dp = std::default_delete<unsigned char>]' at /usr/include/c++/12.1.0/bits/unique_ptr.h:396:17,
inlined from 'virtual void phi::CustomDevice::MemorySet(size_t, void*, uint8_t, size_t)' at ./Paddle/paddle/phi/backends/custom/custom_device.cc:446:5:
/usr/include/c++/12.1.0/bits/unique_ptr.h:95:9: error: 'void operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete]
95 | delete __ptr;
| ^~~~~~~~~~~~
./Paddle/paddle/phi/backends/custom/custom_device.cc: In member function 'virtual void phi::CustomDevice::MemorySet(size_t, void*, uint8_t, size_t)':
./Paddle/paddle/phi/backends/custom/custom_device.cc:443:52: note: returned from 'void* operator new [](std::size_t)'
443 | std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
| ^
In member function 'void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = unsigned char]',
inlined from 'std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = unsigned char; _Dp = std::default_delete<unsigned char>]' at /usr/include/c++/12.1.0/bits/unique_ptr.h:396:17,
inlined from 'virtual void phi::CustomDevice::MemorySet(size_t, void*, uint8_t, size_t)' at ./Paddle/paddle/phi/backends/custom/custom_device.cc:446:5:
/usr/include/c++/12.1.0/bits/unique_ptr.h:95:9: error: 'void operator delete(void*, std::size_t)' called on pointer returned from a mismatched allocation function [-Werror=mismatched-new-delete]
95 | delete __ptr;
| ^~~~~~~~~~~~
./Paddle/paddle/phi/backends/custom/custom_device.cc: In member function 'virtual void phi::CustomDevice::MemorySet(size_t, void*, uint8_t, size_t)':
./Paddle/paddle/phi/backends/custom/custom_device.cc:443:52: note: returned from 'void* operator new [](std::size_t)'
443 | std::unique_ptr<uint8_t> tmp(new uint8_t[size]);
| ^
cc1plus: all warnings being treated as errors
make[2]: *** [paddle/phi/backends/custom/CMakeFiles/custom_device.dir/build.make:76: paddle/phi/backends/custom/CMakeFiles/custom_device.dir/custom_device.cc.o] Error 1
其他补充信息 Additional Supplementary Information
check out git master;
cmake
make
4条答案
按热度按时间vh0rcniy1#
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看 官网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!
eoxn13cs2#
Please try compiling with the patch below
fcy6dtqo3#
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 correct fix for this problem is shown below.
reference: https://en.cppreference.com/w/cpp/memory/unique_ptr
template <class T,class Deleter> class unique_ptr<T[], Deleter>;
Manages a dynamically-allocated array of objects (e.g. allocated with new[])template<class T, class Deleter = std::default_delete<T> > class unique_ptr;
Manages a single object (e.g. allocated with new)wydwbb8l4#
Here is the patch to fix this issue: