Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ac813bba
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ac813bba
编写于
10月 24, 2019
作者:
Z
Zeng Jinle
提交者:
GitHub
10月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more error debug message to Operator::Run (#20793)
* add more err msg, test=develop * add more unittests, test=develop
上级
efbdad05
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
103 addition
and
5 deletion
+103
-5
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+1
-0
paddle/fluid/framework/op_call_stack.cc
paddle/fluid/framework/op_call_stack.cc
+10
-5
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+7
-0
paddle/fluid/framework/operator_exception_test.cc
paddle/fluid/framework/operator_exception_test.cc
+85
-0
未找到文件。
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
ac813bba
...
@@ -127,6 +127,7 @@ cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope gl
...
@@ -127,6 +127,7 @@ cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope gl
shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type op_call_stack
)
shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type op_call_stack
)
cc_test
(
operator_test SRCS operator_test.cc DEPS operator op_registry device_context
)
cc_test
(
operator_test SRCS operator_test.cc DEPS operator op_registry device_context
)
cc_test
(
operator_exception_test SRCS operator_exception_test.cc DEPS operator op_registry device_context
)
cc_library
(
version SRCS version.cc
)
cc_library
(
version SRCS version.cc
)
cc_test
(
version_test SRCS version_test.cc DEPS version
)
cc_test
(
version_test SRCS version_test.cc DEPS version
)
...
...
paddle/fluid/framework/op_call_stack.cc
浏览文件 @
ac813bba
...
@@ -26,17 +26,22 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
...
@@ -26,17 +26,22 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
if
(
attrs
.
count
(
"sub_block"
)
!=
0
)
{
if
(
attrs
.
count
(
"sub_block"
)
!=
0
)
{
return
;
return
;
}
}
auto
&
callstack
=
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
attrs
.
at
(
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
()));
const
std
::
vector
<
std
::
string
>
*
callstack
=
nullptr
;
auto
iter
=
attrs
.
find
(
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
());
if
(
iter
!=
attrs
.
end
())
{
callstack
=
&
boost
::
get
<
std
::
vector
<
std
::
string
>>
(
iter
->
second
);
if
(
callstack
->
empty
())
callstack
=
nullptr
;
}
std
::
ostringstream
sout
;
std
::
ostringstream
sout
;
std
::
ostringstream
sout_py_trace
;
std
::
ostringstream
sout_py_trace
;
// Step 1. Construct python call stack string
// Step 1. Construct python call stack string
if
(
!
callstack
.
empty
()
)
{
if
(
callstack
)
{
sout_py_trace
<<
"
\n
------------------------------------------
\n
"
;
sout_py_trace
<<
"
\n
------------------------------------------
\n
"
;
sout_py_trace
<<
"Python Call Stacks (More useful to users):"
;
sout_py_trace
<<
"Python Call Stacks (More useful to users):"
;
sout_py_trace
<<
"
\n
------------------------------------------
\n
"
;
sout_py_trace
<<
"
\n
------------------------------------------
\n
"
;
for
(
auto
&
line
:
callstack
)
{
for
(
auto
&
line
:
*
callstack
)
{
sout_py_trace
<<
line
;
sout_py_trace
<<
line
;
}
}
}
}
...
@@ -55,7 +60,7 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
...
@@ -55,7 +60,7 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
sout
<<
"C++ Call Stacks (More useful to developers):"
;
sout
<<
"C++ Call Stacks (More useful to developers):"
;
sout
<<
"
\n
--------------------------------------------
\n
"
;
sout
<<
"
\n
--------------------------------------------
\n
"
;
sout
<<
exception
->
err_str_
;
sout
<<
exception
->
err_str_
;
if
(
!
callstack
.
empty
()
)
{
if
(
callstack
)
{
sout
<<
" [operator < "
<<
type
<<
" > error]"
;
sout
<<
" [operator < "
<<
type
<<
" > error]"
;
}
}
exception
->
err_str_
=
sout
.
str
();
exception
->
err_str_
=
sout
.
str
();
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
ac813bba
...
@@ -183,7 +183,14 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
...
@@ -183,7 +183,14 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
}
catch
(
platform
::
EnforceNotMet
&
exception
)
{
}
catch
(
platform
::
EnforceNotMet
&
exception
)
{
framework
::
InsertCallStackInfo
(
Type
(),
Attrs
(),
&
exception
);
framework
::
InsertCallStackInfo
(
Type
(),
Attrs
(),
&
exception
);
throw
std
::
move
(
exception
);
throw
std
::
move
(
exception
);
}
catch
(
platform
::
EOFException
&
)
{
std
::
rethrow_exception
(
std
::
current_exception
());
}
catch
(
std
::
exception
&
ex
)
{
LOG
(
WARNING
)
<<
Type
()
<<
" raises an exception "
<<
platform
::
demangle
(
typeid
(
ex
).
name
())
<<
", "
<<
ex
.
what
();
std
::
rethrow_exception
(
std
::
current_exception
());
}
catch
(...)
{
}
catch
(...)
{
LOG
(
WARNING
)
<<
Type
()
<<
" raises an unknown exception"
;
std
::
rethrow_exception
(
std
::
current_exception
());
std
::
rethrow_exception
(
std
::
current_exception
());
}
}
}
}
...
...
paddle/fluid/framework/operator_exception_test.cc
0 → 100644
浏览文件 @
ac813bba
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/framework/operator.h"
#include <exception>
#include <stdexcept>
#include <string>
#include <utility>
#include "gtest/gtest.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/platform/place.h"
namespace
paddle
{
namespace
framework
{
class
ExceptionThrownOperator
:
public
OperatorBase
{
public:
using
OperatorBase
::
OperatorBase
;
template
<
typename
T
>
void
SetException
(
T
&&
obj
)
{
exception_
=
std
::
make_exception_ptr
(
std
::
forward
<
T
>
(
obj
));
}
protected:
void
RunImpl
(
const
Scope
&
,
const
platform
::
Place
&
)
const
override
{
if
(
exception_
)
{
std
::
rethrow_exception
(
exception_
);
}
}
private:
std
::
exception_ptr
exception_
{
nullptr
};
};
class
StubException
:
public
std
::
exception
{
public:
const
char
*
what
()
const
noexcept
override
{
return
""
;
}
};
template
<
typename
T
>
bool
ExceptionTestMain
(
T
&&
obj
,
bool
set_exception
)
{
ExceptionThrownOperator
op
(
""
,
{},
{},
{});
if
(
set_exception
)
{
op
.
SetException
(
std
::
forward
<
T
>
(
obj
));
}
Scope
scope
;
try
{
op
.
Run
(
scope
,
platform
::
CPUPlace
());
return
false
;
}
catch
(
T
&
)
{
return
true
;
}
}
TEST
(
test_operator_exception
,
test_operator_exception
)
{
platform
::
EnforceNotMet
enforce_not_met
(
""
,
__FILE__
,
__LINE__
);
ASSERT_TRUE
(
ExceptionTestMain
(
enforce_not_met
,
true
));
ASSERT_FALSE
(
ExceptionTestMain
(
enforce_not_met
,
false
));
platform
::
EOFException
eof
(
""
,
__FILE__
,
__LINE__
);
ASSERT_TRUE
(
ExceptionTestMain
(
eof
,
true
));
ASSERT_FALSE
(
ExceptionTestMain
(
eof
,
false
));
StubException
stub
;
ASSERT_TRUE
(
ExceptionTestMain
(
stub
,
true
));
ASSERT_FALSE
(
ExceptionTestMain
(
stub
,
false
));
ASSERT_TRUE
(
ExceptionTestMain
(
1
,
true
));
ASSERT_FALSE
(
ExceptionTestMain
(
1
,
false
));
}
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录