Skip to content

Conversation

@zhwesky2010
Copy link
Contributor

@zhwesky2010 zhwesky2010 commented Feb 26, 2021

PR types

New features

PR changes

OPs

Describe

用户在自定义OP中使用宏 PD_CHECKPD_THROW添加报错信息,支持变长参数模板

1. PD_THROW()

An error occured at /zhouwei25/Paddle/python/paddle/fluid/tests/custom_op/custom_relu_op.cc:82

2. 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:82

3. 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:82

4. 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上:
image

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

#define PD_LIKELY(expr) (expr)
#endif

struct PD_Exception : public std::exception {
Copy link
Contributor

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

Copy link
Contributor Author

@zhwesky2010 zhwesky2010 Feb 26, 2021

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__, \
Copy link
Contributor

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]

Copy link
Contributor Author

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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个提升我觉得可以没有,因为这个是给用户用的,他自己清楚自己写了什么报错,加了多余的信息,他反而会觉得疑惑
框架里面有,主要是为了方便外部用户反馈过来的时候,我们RD能够比较快找到报错语句

Copy link
Contributor Author

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__), "`"); \
Copy link
Contributor

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

Copy link
Contributor Author

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__) + "`"); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

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 `" + \
Copy link
Contributor

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 `" + \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

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__) + "`"); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@zhwesky2010 zhwesky2010 changed the title [Custom OP]add PD_THROW and PD_CHECK for User error message [Custom OP]add PD_THROW and PD_CHECK for User Error message Feb 26, 2021
@chenwhql chenwhql merged commit af9066e into PaddlePaddle:develop Feb 27, 2021
chenwhql pushed a commit to chenwhql/Paddle that referenced this pull request Feb 27, 2021
…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
lanxianghit pushed a commit that referenced this pull request Feb 28, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants