-
Couldn't load subscription status.
- Fork 5.9k
[Custom OP]add PD_THROW and PD_CHECK for User Error message #31253
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
[Custom OP]add PD_THROW and PD_CHECK for User Error message #31253
Conversation
|
Thanks for your contribution! |
| #define PD_LIKELY(expr) (expr) | ||
| #endif | ||
|
|
||
| struct PD_Exception : public std::exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think split Exception、CHECK、THROW to a new header file exception.h is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, split to exception.h
| if (PD_UNLIKELY(!(COND))) { \ | ||
| HANDLE_THE_ERROR \ | ||
| auto __message__ = ::paddle::ErrorMessage(__VA_ARGS__).to_string(); \ | ||
| throw ::paddle::PD_Exception(__message__, __FILE__, __LINE__, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个file和line的格式能再整理一下吗,现在回导致第一行信息太长,是不是换行之后缩进一下,用括号包起来,比如
ExternalError: error message.
[file:line]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| HANDLE_THE_ERROR \ | ||
| auto __message__ = ::paddle::ErrorMessage(__VA_ARGS__).to_string(); \ | ||
| throw ::paddle::PD_Exception(__message__, __FILE__, __LINE__, \ | ||
| "Expected " #COND \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个提升我觉得可以没有,因为这个是给用户用的,他自己清楚自己写了什么报错,加了多余的信息,他反而会觉得疑惑
框架里面有,主要是为了方便外部用户反馈过来的时候,我们RD能够比较快找到报错语句
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认的报错信息,用户如果写了就以用户为准
| " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ | ||
| PD_THROW("function " #NAME " not implemented for data type `", \ | ||
| ::paddle::ToString(__dtype__), "`"); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar problem:is not implemented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ | ||
| PD_THROW("function " #NAME " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| PD_PRIVATE_CASE_TYPE(NAME, ::paddle::DataType::COMPLEX128, \ | ||
| ::paddle::complex128, __VA_ARGS__) \ | ||
| default: \ | ||
| PD_THROW("function " #NAME " not implemented for data type `" + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
| throw std::runtime_error("function " #NAME \ | ||
| " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ | ||
| PD_THROW("function " #NAME " not implemented for data type `" + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ | ||
| PD_THROW("function " #NAME " not implemented for data type `" + \ | ||
| ::paddle::ToString(__dtype__) + "`"); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
3ce88f4 to
ec9a651
Compare
ec9a651 to
3212435
Compare
0724d69 to
f3abcde
Compare
…ddle#31253) * [Custom OP]add PD_THROW and PD_CHECK for User error message * PD_THROW and PD_CHECK, fix comment * fix Windows error message * fix Windows error message * fix CI
* modify custom op dependent from paddle_framework to paddle_custom_op (#31195) * [Custom Op] Remove unsupport dtypes (#31232) * remove remove_unsupport_dtype * remove remove_unsupport_dtype * remove test dtype * add more include * change dtype.h's enum as enum class to avoid conflict with inference lib * make enum as enum class * remove additional test * merge develop * polish code * [Custom OP] Support stream set on Custom Op (#31257) * [Custom OP] change the user header file format, test=develop (#31274) * [Custom OP]add PD_THROW and PD_CHECK for User Error message (#31253) * [Custom OP]add PD_THROW and PD_CHECK for User error message * PD_THROW and PD_CHECK, fix comment * fix Windows error message * fix Windows error message * fix CI * [Custom OP]add MSVC compile check on Windows (#31265) * fix test_check_abi Co-authored-by: Zhou Wei <52485244+zhouwei25@users.noreply.github.com> Co-authored-by: Jiabin Yang <marsyang199376@gmail.com> Co-authored-by: 石晓伟 <39303645+Shixiaowei02@users.noreply.github.com> Co-authored-by: zhouwei25 <zhouwei25@baidu.com>
PR types
New features
PR changes
OPs
Describe
用户在自定义OP中使用宏
PD_CHECK、PD_THROW添加报错信息,支持变长参数模板1. PD_THROW()
An error occured at /zhouwei25/Paddle/python/paddle/fluid/tests/custom_op/custom_relu_op.cc:822. PD_THROW("PD_THROW returns ", false, ". DataType of ", 1, " is INT")
PD_THROW returns false. DataType of 1 is INT at /zhouwei25/Paddle/python/paddle/fluid/tests/custom_op/custom_relu_op.cc:823. PD_CHECK(a > b)
Expected a > b, but it's not satisfied at /zhouwei25/Paddle/python/paddle/fluid/tests/custom_op/custom_relu_op.cc:824. PD_CHECK(c < d, "PD_CHECK returns false ", because c > d")
"PD_CHECK returns false, because c > d at /zhouwei25/Paddle/python/paddle/fluid/tests/custom_op/custom_relu_op.cc:82例如,在Windows10上:
