Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞不过沧海
Paddle
提交
eea75a1d
P
Paddle
项目概览
飞不过沧海
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eea75a1d
编写于
1月 14, 2019
作者:
P
peizhilin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issue when type is invalid
test=develop
上级
9adb158e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
55 addition
and
164 deletion
+55
-164
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+48
-43
paddle/fluid/framework/operator.h
paddle/fluid/framework/operator.h
+0
-4
paddle/fluid/platform/CMakeLists.txt
paddle/fluid/platform/CMakeLists.txt
+2
-4
paddle/fluid/platform/debug_support.cc
paddle/fluid/platform/debug_support.cc
+0
-44
paddle/fluid/platform/debug_support.h
paddle/fluid/platform/debug_support.h
+0
-57
paddle/fluid/platform/enforce.h
paddle/fluid/platform/enforce.h
+0
-2
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+5
-10
未找到文件。
paddle/fluid/framework/operator.cc
浏览文件 @
eea75a1d
...
...
@@ -16,6 +16,11 @@ limitations under the License. */
#include <glog/logging.h>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "paddle/fluid/framework/data_transform.h"
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/lod_tensor.h"
...
...
@@ -32,12 +37,6 @@ DEFINE_bool(check_nan_inf, false,
"Checking whether operator produce NAN/INF or not. It will be "
"extremely slow so please use this flag wisely."
);
DEFINE_bool
(
enable_debug
,
false
,
"The enable_debug indicate whether to give more detail information when, "
"use the paddlepaddle. However it may deduce the performance since it has"
"to record the information during runtime."
);
namespace
paddle
{
namespace
framework
{
...
...
@@ -163,50 +162,56 @@ RuntimeContext::RuntimeContext(const VariableNameMap& innames,
}
}
void
OperatorBase
::
PreHook
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
)
{
auto
attrName
=
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
();
if
(
HasAttr
(
attrName
))
{
auto
&
callstack
=
Attr
<
std
::
vector
<
std
::
string
>>
(
attrName
);
platform
::
PythonDebugSupport
::
GetInstance
()
->
SetInformation
(
callstack
);
}
}
void
OperatorBase
::
Run
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
)
{
if
(
FLAGS_enable_debug
)
{
VLOG
(
4
)
<<
"Call the prehook ... "
;
PreHook
(
scope
,
place
);
}
VLOG
(
4
)
<<
place
<<
" "
<<
DebugStringEx
(
&
scope
);
if
(
platform
::
is_gpu_place
(
place
))
{
try
{
VLOG
(
4
)
<<
place
<<
" "
<<
DebugStringEx
(
&
scope
);
if
(
platform
::
is_gpu_place
(
place
))
{
#ifndef PADDLE_WITH_CUDA
PADDLE_THROW
(
"Cannot run operator on place %s"
,
place
);
PADDLE_THROW
(
"Cannot run operator on place %s"
,
place
);
#else
auto
dev_id
=
boost
::
get
<
platform
::
CUDAPlace
>
(
place
).
device
;
platform
::
SetDeviceId
(
dev_id
);
auto
dev_id
=
boost
::
get
<
platform
::
CUDAPlace
>
(
place
).
device
;
platform
::
SetDeviceId
(
dev_id
);
#endif
}
}
// The profile has a process-wide mutex, results in serious performance issue
// in concurrency scenerio. Here use an `if` to fix this issue.
// Please not remove the `if`, ask @Superjomn if there are any concern.
if
(
platform
::
IsProfileEnabled
())
{
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
RecordEvent
record_event
(
Type
(),
pool
.
Get
(
place
));
RunImpl
(
scope
,
place
);
}
else
{
RunImpl
(
scope
,
place
);
}
VLOG
(
3
)
<<
place
<<
" "
<<
DebugStringEx
(
&
scope
);
// The profile has a process-wide mutex, results in serious performance
// issue
// in concurrency scenerio. Here use an `if` to fix this issue.
// Please not remove the `if`, ask @Superjomn if there are any concern.
if
(
platform
::
IsProfileEnabled
())
{
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
RecordEvent
record_event
(
Type
(),
pool
.
Get
(
place
));
RunImpl
(
scope
,
place
);
}
else
{
RunImpl
(
scope
,
place
);
}
if
(
FLAGS_enable_debug
)
{
VLOG
(
4
)
<<
"Call the posthook ... "
;
PostHook
(
scope
,
place
);
}
}
VLOG
(
3
)
<<
place
<<
" "
<<
DebugStringEx
(
&
scope
);
}
catch
(
platform
::
EnforceNotMet
exception
)
{
if
(
Attrs
().
count
(
"sub_block"
)
!=
0
)
{
throw
exception
;
}
void
OperatorBase
::
PostHook
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
)
{
// do nothing here
auto
&
callstack
=
Attr
<
std
::
vector
<
std
::
string
>>
(
OpProtoAndCheckerMaker
::
OpCreationCallstackAttrName
());
if
(
callstack
.
empty
())
{
throw
exception
;
}
std
::
ostringstream
sout
;
sout
<<
"Invoke operator "
<<
Type
()
<<
" error.
\n
"
;
sout
<<
"Python Callstacks:
\n
"
;
for
(
auto
&
line
:
callstack
)
{
sout
<<
line
;
}
sout
<<
"C++ Callstacks:
\n
"
;
sout
<<
exception
.
err_str_
;
exception
.
err_str_
=
sout
.
str
();
throw
exception
;
}
catch
(...)
{
std
::
rethrow_exception
(
std
::
current_exception
());
}
}
bool
OperatorBase
::
HasInputs
(
const
std
::
string
&
name
)
const
{
...
...
paddle/fluid/framework/operator.h
浏览文件 @
eea75a1d
...
...
@@ -160,10 +160,6 @@ class OperatorBase {
const
platform
::
Place
&
place
,
const
RuntimeContext
&
ctx
)
const
{}
// Add the hooks
virtual
void
PreHook
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
);
virtual
void
PostHook
(
const
Scope
&
scope
,
const
platform
::
Place
&
place
);
protected:
std
::
string
type_
;
// NOTE: in case of OpGrad, inputs_ contains:
...
...
paddle/fluid/platform/CMakeLists.txt
浏览文件 @
eea75a1d
...
...
@@ -20,12 +20,10 @@ add_custom_command(TARGET profiler_py_proto POST_BUILD
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
endif
(
NOT WIN32
)
cc_library
(
debug_support SRCS debug_support.cc
)
if
(
WITH_GPU
)
nv_library
(
enforce SRCS enforce.cc
DEPS debug_support
)
nv_library
(
enforce SRCS enforce.cc
)
else
()
cc_library
(
enforce SRCS enforce.cc
DEPS debug_support
)
cc_library
(
enforce SRCS enforce.cc
)
endif
()
cc_test
(
enforce_test SRCS enforce_test.cc DEPS stringpiece enforce
)
...
...
paddle/fluid/platform/debug_support.cc
已删除
100644 → 0
浏览文件 @
9adb158e
/* Copyright (c) 2016 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 <sstream>
#include "paddle/fluid/platform/debug_support.h"
namespace
paddle
{
namespace
platform
{
template
<
>
std
::
string
PythonDebugSupport
::
Format
()
const
{
std
::
ostringstream
sout
;
sout
<<
"
\n
Python Callstacks:
\n
"
;
if
(
!
info
.
empty
())
{
for
(
auto
&
line
:
info
)
{
sout
<<
line
;
}
}
else
{
#ifdef _WIN32
sout
<<
"please set FLAGS_enable_debug=True to get more details regard to "
"this failure.
\n
"
;
#else // _WIN32
sout
<<
"please export FLAGS_enable_debug=True to get more details regard "
"to "
"this failure.
\n
"
;
#endif // _WIN32
}
return
sout
.
str
();
}
}
// namespace platform
}
// namespace paddle
paddle/fluid/platform/debug_support.h
已删除
100644 → 0
浏览文件 @
9adb158e
/* Copyright (c) 2016 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. */
#pragma once
#include <exception>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
namespace
paddle
{
namespace
platform
{
template
<
typename
T
>
class
DebugSupport
{
public:
// Returns the singleton of DebugSupport.
static
DebugSupport
*
GetInstance
()
{
static
thread_local
std
::
unique_ptr
<
DebugSupport
>
debugSupport_
(
nullptr
);
static
thread_local
std
::
once_flag
init_flag_
;
std
::
call_once
(
init_flag_
,
[
&
]()
{
debugSupport_
.
reset
(
new
DebugSupport
<
T
>
());
});
return
debugSupport_
.
get
();
}
T
GetInformation
()
const
{
return
info
;
}
void
SetInformation
(
const
T
&
v
)
{
info
=
v
;
}
std
::
string
Format
()
const
;
private:
T
info
;
};
using
PythonDebugSupport
=
DebugSupport
<
std
::
vector
<
std
::
string
>>
;
template
<
>
std
::
string
PythonDebugSupport
::
Format
()
const
;
}
// namespace platform
}
// namespace paddle
paddle/fluid/platform/enforce.h
浏览文件 @
eea75a1d
...
...
@@ -33,7 +33,6 @@ limitations under the License. */
#include <string>
#include "glog/logging.h"
#include "paddle/fluid/platform/debug_support.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/fluid/platform/port.h"
#include "paddle/fluid/string/printf.h"
...
...
@@ -69,7 +68,6 @@ struct EnforceNotMet : public std::exception {
std
::
rethrow_exception
(
e
);
}
catch
(
std
::
exception
&
e
)
{
Init
(
e
.
what
(),
f
,
l
);
err_str_
+=
platform
::
PythonDebugSupport
::
GetInstance
()
->
Format
();
}
}
...
...
python/paddle/fluid/framework.py
浏览文件 @
eea75a1d
...
...
@@ -621,21 +621,16 @@ class Operator(object):
if
role_var_name
in
op_attrs
and
len
(
op_attrs
[
role_var_name
])
==
0
:
del
op_attrs
[
role_var_name
]
if
'FLAGS_enable_debug'
in
os
.
environ
and
os
.
environ
[
'FLAGS_enable_debug'
]:
callstack_var_name
=
op_maker
.
kOpCreationCallstackAttrName
()
op_attrs
[
callstack_var_name
]
=
list
(
reversed
(
traceback
.
format_stack
()))[
1
:]
op_attrs
[
callstack_var_name
].
insert
(
0
,
'Invoke operator '
+
(
''
if
type
is
None
else
type
)
+
' error.
\n
'
)
if
len
(
self
.
desc
.
type
())
!=
0
:
return
if
type
is
None
:
raise
ValueError
(
"`type` to initilized an Operator can not be None."
)
else
:
callstack_var_name
=
op_maker
.
kOpCreationCallstackAttrName
()
op_attrs
[
callstack_var_name
]
=
list
(
reversed
(
traceback
.
format_stack
()))[
1
:]
self
.
desc
.
set_type
(
type
)
proto
=
OpProtoHolder
.
instance
().
get_op_proto
(
type
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录